DefaultCaccSensors.java

  1. package org.opentrafficsim.road.gtu.lane.perception.categories.neighbors;

  2. import java.util.ArrayList;
  3. import java.util.List;

  4. import org.djunits.value.vdouble.scalar.Acceleration;
  5. import org.djunits.value.vdouble.scalar.Length;
  6. import org.djunits.value.vdouble.scalar.Speed;
  7. import org.djunits.value.vdouble.scalar.Time;
  8. import org.opentrafficsim.base.parameters.ParameterException;
  9. import org.opentrafficsim.core.gtu.GTUException;
  10. import org.opentrafficsim.core.gtu.GTUType;
  11. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  12. import org.opentrafficsim.road.gtu.lane.control.ControlTacticalPlanner;
  13. import org.opentrafficsim.road.gtu.lane.perception.headway.GTUStatus;
  14. import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
  15. import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTUSimple;

  16. /**
  17.  * Default CACC sensors. This returns all information except desired speed for the first leader and CACC leaders. Remaining
  18.  * leaders are provided null information.
  19.  * <p>
  20.  * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  21.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  22.  * <p>
  23.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Mar 13, 2019 <br>
  24.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  25.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  26.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  27.  */
  28. public class DefaultCaccSensors implements HeadwayGtuType
  29. {

  30.     /** {@inheritDoc} */
  31.     @Override
  32.     public HeadwayGTU createDownstreamGtu(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
  33.             final Length distance) throws GTUException, ParameterException
  34.     {
  35.         Time t;
  36.         try
  37.         {
  38.             t = perceivingGtu.getSimulator().getSimulatorAbsTime()
  39.                     .minus(((ControlTacticalPlanner) perceivingGtu.getTacticalPlanner()).getSettings()
  40.                             .getParameter(LongitudinalControllerPerception.DELAY));
  41.         }
  42.         catch (ClassCastException exception)
  43.         {
  44.             if (!(perceivingGtu.getTacticalPlanner() instanceof ControlTacticalPlanner))
  45.             {
  46.                 throw new GTUException("DefaultCaccSensors relies on the tactical planner being a ControlTacticalPlanner",
  47.                         exception);
  48.             }
  49.             throw new GTUException(exception);
  50.         }
  51.         String id = perceivedGtu.getId();
  52.         GTUType gtuType = perceivedGtu.getGTUType();
  53.         Length length = perceivedGtu.getLength();
  54.         Length width = perceivedGtu.getWidth();
  55.         Speed v = perceivedGtu.getSpeed(t);
  56.         Acceleration a = perceivedGtu.getAcceleration(t);
  57.         Speed desiredSpeed = null;
  58.         List<GTUStatus> status = new ArrayList<>();
  59.         if (perceivedGtu.isBrakingLightsOn(t))
  60.         {
  61.             status.add(GTUStatus.BRAKING_LIGHTS);
  62.         }
  63.         switch (perceivedGtu.getTurnIndicatorStatus(t))
  64.         {
  65.             case HAZARD:
  66.                 status.add(GTUStatus.EMERGENCY_LIGHTS);
  67.                 break;
  68.             case LEFT:
  69.                 status.add(GTUStatus.LEFT_TURNINDICATOR);
  70.                 break;
  71.             case RIGHT:
  72.                 status.add(GTUStatus.RIGHT_TURNINDICATOR);
  73.                 break;
  74.             default:
  75.                 break;
  76.         }
  77.         return new HeadwayGTUSimple(id, gtuType, distance, length, width, v, a, desiredSpeed,
  78.                 status.toArray(new GTUStatus[status.size()]));
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public HeadwayGTU createUpstreamGtu(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
  83.             final Length distance) throws GTUException, ParameterException
  84.     {
  85.         throw new UnsupportedOperationException("Default CACC sensors can only determine leaders.");
  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public HeadwayGTU createParallelGtu(final LaneBasedGTU perceivingGtu, final LaneBasedGTU perceivedGtu,
  90.             final Length overlapFront, final Length overlap, final Length overlapRear) throws GTUException
  91.     {
  92.         throw new UnsupportedOperationException("Default CACC sensors can only determine leaders.");
  93.     }

  94. }