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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  21.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  22.  * </p>
  23.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  24.  * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
  25.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  26.  */
  27. public class DefaultCaccSensors implements HeadwayGtuType
  28. {

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

  78.     @Override
  79.     public HeadwayGtu createUpstreamGtu(final LaneBasedGtu perceivingGtu, final LaneBasedGtu perceivedGtu,
  80.             final Length distance) throws GtuException, ParameterException
  81.     {
  82.         throw new UnsupportedOperationException("Default CACC sensors can only determine leaders.");
  83.     }

  84.     @Override
  85.     public HeadwayGtu createParallelGtu(final LaneBasedGtu perceivingGtu, final LaneBasedGtu perceivedGtu,
  86.             final Length overlapFront, final Length overlap, final Length overlapRear) throws GtuException
  87.     {
  88.         throw new UnsupportedOperationException("Default CACC sensors can only determine leaders.");
  89.     }

  90. }