View Javadoc
1   package org.opentrafficsim.road.gtu.lane.control;
2   
3   import org.djunits.value.vdouble.scalar.Acceleration;
4   import org.djunits.value.vdouble.scalar.Duration;
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.opentrafficsim.base.parameters.ParameterException;
7   import org.opentrafficsim.base.parameters.ParameterTypeDuration;
8   import org.opentrafficsim.base.parameters.ParameterTypeLength;
9   import org.opentrafficsim.base.parameters.Parameters;
10  import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
11  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
12  import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
13  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
14  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.LongitudinalControllerPerception;
15  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
16  
17  /**
18   * Simple linear CACC controller.
19   * <p>
20   * Copyright (c) 2013-2020 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 12, 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 abstract class AbstractActuatedControl implements LongitudinalControl
29  {
30  
31      /** Time headway setting for ACC mode. */
32      public static final ParameterTypeDuration TDACC = new ParameterTypeDuration("td ACC",
33              "User defined time headway in ACC mode", Duration.instantiateSI(1.2), NumericConstraint.POSITIVE);
34  
35      /** Time headway setting for CACC mode. */
36      public static final ParameterTypeDuration TDCACC = new ParameterTypeDuration("td CACC",
37              "User defined time headway in CACC mode", Duration.instantiateSI(0.5), NumericConstraint.POSITIVE);
38  
39      /** (C)ACC stopping distance. */
40      public static final ParameterTypeLength X0 =
41              new ParameterTypeLength("x0 (C)ACC", "Stopping distance (C)ACC", Length.instantiateSI(3.0), NumericConstraint.POSITIVE);
42  
43      /** Delayed actuation. */
44      private final DelayedActuation delayedActuation;
45  
46      /**
47       * Constructor using default sensors with no delay.
48       * @param delayedActuation DelayedActuation; delayed actuation
49       */
50      public AbstractActuatedControl(final DelayedActuation delayedActuation)
51      {
52          this.delayedActuation = delayedActuation;
53      }
54  
55      /**
56       * Delays the actuation of acceleration.
57       * @param desiredAcceleration Acceleration; desired acceleration
58       * @param gtu LaneBasedGTU; gtu
59       * @return Acceleration; delayed acceleration
60       */
61      public Acceleration delayActuation(final Acceleration desiredAcceleration, final LaneBasedGTU gtu)
62      {
63          return this.delayedActuation.delayActuation(desiredAcceleration, gtu);
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public Acceleration getAcceleration(final LaneBasedGTU gtu, final Parameters settings)
69      {
70          try
71          {
72              PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders = gtu.getTacticalPlanner().getPerception()
73                      .getPerceptionCategory(LongitudinalControllerPerception.class).getLeaders();
74              return delayActuation(getDesiredAcceleration(gtu, leaders, settings), gtu);
75          }
76          catch (OperationalPlanException exception)
77          {
78              throw new RuntimeException("Missing perception category LongitudinalControllerPerception", exception);
79          }
80          catch (ParameterException exception)
81          {
82              throw new RuntimeException("Missing parameter", exception);
83          }
84      }
85  
86      /**
87       * Returns the desired acceleration from the longitudinal control.
88       * @param gtu LaneBasedGTU; gtu
89       * @param leaders PerceptionCollectable&lt;HeadwayGTU, LaneBasedGTU&gt;; leaders
90       * @param settings Parameters; system settings
91       * @return Acceleration; desired acceleration
92       * @throws ParameterException if parameter is not present
93       */
94      public abstract Acceleration getDesiredAcceleration(LaneBasedGTU gtu,
95              PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders, Parameters settings) throws ParameterException;
96  
97  }