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.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  /**
17   * Simple linear CACC controller.
18   * <p>
19   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
21   * <p>
22   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Mar 12, 2019 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
25   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
26   */
27  public abstract class AbstractActuatedControl implements LongitudinalControl
28  {
29  
30      /** Time headway setting for ACC mode. */
31      public static final ParameterTypeDuration TDACC = new ParameterTypeDuration("td ACC",
32              "User defined time headway in ACC mode", Duration.createSI(1.2), NumericConstraint.POSITIVE);
33  
34      /** Time headway setting for CACC mode. */
35      public static final ParameterTypeDuration TDCACC = new ParameterTypeDuration("td CACC",
36              "User defined time headway in CACC mode", Duration.createSI(0.5), NumericConstraint.POSITIVE);
37  
38      /** (C)ACC stopping distance. */
39      public static final ParameterTypeLength X0 =
40              new ParameterTypeLength("x0 (C)ACC", "Stopping distance (C)ACC", Length.createSI(3.0), NumericConstraint.POSITIVE);
41  
42      /** Delayed actuation. */
43      private final DelayedActuation delayedActuation;
44  
45      /**
46       * Constructor using default sensors with no delay.
47       * @param delayedActuation DelayedActuation; delayed actuation
48       */
49      public AbstractActuatedControl(final DelayedActuation delayedActuation)
50      {
51          this.delayedActuation = delayedActuation;
52      }
53  
54      /**
55       * Delays the actuation of acceleration.
56       * @param desiredAcceleration Acceleration; desired acceleration
57       * @param gtu LaneBasedGTU; gtu
58       * @return Acceleration; delayed acceleration
59       */
60      public Acceleration delayActuation(final Acceleration desiredAcceleration, final LaneBasedGTU gtu)
61      {
62          return this.delayedActuation.delayActuation(desiredAcceleration, gtu);
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public Acceleration getAcceleration(final LaneBasedGTU gtu)
68      {
69          try
70          {
71              PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders = gtu.getTacticalPlanner().getPerception()
72                      .getPerceptionCategory(LongitudinalControllerPerception.class).getLeaders();
73              return this.delayedActuation.delayActuation(getDesiredAcceleration(gtu, leaders), gtu);
74          }
75          catch (OperationalPlanException exception)
76          {
77              throw new RuntimeException("Missing perception category LongitudinalControllerPerception", exception);
78          }
79          catch (ParameterException exception)
80          {
81              throw new RuntimeException("Missing parameter", exception);
82          }
83      }
84  
85      /**
86       * Returns the desired acceleration from the longitudinal control.
87       * @param gtu LaneBasedGTU; gtu
88       * @param leaders PerceptionCollectable&lt;HeadwayGTU, LaneBasedGTU&gt;; leaders
89       * @return Acceleration; desired acceleration
90       * @throws ParameterException if parameter is not present
91       */
92      public abstract Acceleration getDesiredAcceleration(LaneBasedGTU gtu,
93              PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders) throws ParameterException;
94  
95  }