AbstractActuatedControl.java

  1. package org.opentrafficsim.road.gtu.lane.control;

  2. import org.djunits.value.vdouble.scalar.Acceleration;
  3. import org.djunits.value.vdouble.scalar.Duration;
  4. import org.djunits.value.vdouble.scalar.Length;
  5. import org.opentrafficsim.base.parameters.ParameterException;
  6. import org.opentrafficsim.base.parameters.ParameterTypeDuration;
  7. import org.opentrafficsim.base.parameters.ParameterTypeLength;
  8. import org.opentrafficsim.base.parameters.Parameters;
  9. import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
  10. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  11. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  12. import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
  13. import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.LongitudinalControllerPerception;
  14. import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;

  15. /**
  16.  * Simple linear CACC controller.
  17.  * <p>
  18.  * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  19.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  20.  * <p>
  21.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Mar 12, 2019 <br>
  22.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  23.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  24.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  25.  */
  26. public abstract class AbstractActuatedControl implements LongitudinalControl
  27. {

  28.     /** Time headway setting for ACC mode. */
  29.     public static final ParameterTypeDuration TDACC = new ParameterTypeDuration("td ACC",
  30.             "User defined time headway in ACC mode", Duration.instantiateSI(1.2), NumericConstraint.POSITIVE);

  31.     /** Time headway setting for CACC mode. */
  32.     public static final ParameterTypeDuration TDCACC = new ParameterTypeDuration("td CACC",
  33.             "User defined time headway in CACC mode", Duration.instantiateSI(0.5), NumericConstraint.POSITIVE);

  34.     /** (C)ACC stopping distance. */
  35.     public static final ParameterTypeLength X0 =
  36.             new ParameterTypeLength("x0 (C)ACC", "Stopping distance (C)ACC", Length.instantiateSI(3.0), NumericConstraint.POSITIVE);

  37.     /** Delayed actuation. */
  38.     private final DelayedActuation delayedActuation;

  39.     /**
  40.      * Constructor using default sensors with no delay.
  41.      * @param delayedActuation DelayedActuation; delayed actuation
  42.      */
  43.     public AbstractActuatedControl(final DelayedActuation delayedActuation)
  44.     {
  45.         this.delayedActuation = delayedActuation;
  46.     }

  47.     /**
  48.      * Delays the actuation of acceleration.
  49.      * @param desiredAcceleration Acceleration; desired acceleration
  50.      * @param gtu LaneBasedGTU; gtu
  51.      * @return Acceleration; delayed acceleration
  52.      */
  53.     public Acceleration delayActuation(final Acceleration desiredAcceleration, final LaneBasedGTU gtu)
  54.     {
  55.         return this.delayedActuation.delayActuation(desiredAcceleration, gtu);
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public Acceleration getAcceleration(final LaneBasedGTU gtu, final Parameters settings)
  60.     {
  61.         try
  62.         {
  63.             PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders = gtu.getTacticalPlanner().getPerception()
  64.                     .getPerceptionCategory(LongitudinalControllerPerception.class).getLeaders();
  65.             return delayActuation(getDesiredAcceleration(gtu, leaders, settings), gtu);
  66.         }
  67.         catch (OperationalPlanException exception)
  68.         {
  69.             throw new RuntimeException("Missing perception category LongitudinalControllerPerception", exception);
  70.         }
  71.         catch (ParameterException exception)
  72.         {
  73.             throw new RuntimeException("Missing parameter", exception);
  74.         }
  75.     }

  76.     /**
  77.      * Returns the desired acceleration from the longitudinal control.
  78.      * @param gtu LaneBasedGTU; gtu
  79.      * @param leaders PerceptionCollectable&lt;HeadwayGTU, LaneBasedGTU&gt;; leaders
  80.      * @param settings Parameters; system settings
  81.      * @return Acceleration; desired acceleration
  82.      * @throws ParameterException if parameter is not present
  83.      */
  84.     public abstract Acceleration getDesiredAcceleration(LaneBasedGTU gtu,
  85.             PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders, Parameters settings) throws ParameterException;

  86. }