View Javadoc
1   package org.opentrafficsim.road.gtu.lane.control;
2   
3   import java.util.Optional;
4   
5   import org.djunits.value.vdouble.scalar.Acceleration;
6   import org.djunits.value.vdouble.scalar.Duration;
7   import org.djunits.value.vdouble.scalar.Length;
8   import org.opentrafficsim.base.OtsRuntimeException;
9   import org.opentrafficsim.base.parameters.ParameterException;
10  import org.opentrafficsim.base.parameters.ParameterTypeDuration;
11  import org.opentrafficsim.base.parameters.ParameterTypeLength;
12  import org.opentrafficsim.base.parameters.Parameters;
13  import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
14  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
15  import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
16  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
17  import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.LongitudinalControllerPerception;
18  import org.opentrafficsim.road.gtu.lane.perception.object.PerceivedGtu;
19  
20  /**
21   * Simple linear CACC controller.
22   * <p>
23   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25   * </p>
26   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
28   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
29   */
30  public abstract class AbstractActuatedControl implements LongitudinalControl
31  {
32  
33      /** Time headway setting for ACC mode. */
34      public static final ParameterTypeDuration TDACC = new ParameterTypeDuration("td ACC",
35              "User defined time headway in ACC mode", Duration.ofSI(1.2), NumericConstraint.POSITIVE);
36  
37      /** Time headway setting for CACC mode. */
38      public static final ParameterTypeDuration TDCACC = new ParameterTypeDuration("td CACC",
39              "User defined time headway in CACC mode", Duration.ofSI(0.5), NumericConstraint.POSITIVE);
40  
41      /** (C)ACC stopping distance. */
42      public static final ParameterTypeLength X0 =
43              new ParameterTypeLength("x0 (C)ACC", "Stopping distance (C)ACC", Length.ofSI(3.0), NumericConstraint.POSITIVE);
44  
45      /** Delayed actuation. */
46      private final DelayedActuation delayedActuation;
47  
48      /**
49       * Constructor using default sensors with no delay.
50       * @param delayedActuation delayed actuation
51       */
52      public AbstractActuatedControl(final DelayedActuation delayedActuation)
53      {
54          this.delayedActuation = delayedActuation;
55      }
56  
57      /**
58       * Delays the actuation of acceleration.
59       * @param desiredAcceleration desired acceleration
60       * @param gtu gtu
61       * @return delayed acceleration
62       */
63      public Acceleration delayActuation(final Acceleration desiredAcceleration, final LaneBasedGtu gtu)
64      {
65          return this.delayedActuation.delayActuation(desiredAcceleration, gtu);
66      }
67  
68      @Override
69      public Optional<Acceleration> getAcceleration(final LaneBasedGtu gtu, final Parameters settings)
70      {
71          try
72          {
73              PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders = gtu.getTacticalPlanner().getPerception()
74                      .getPerceptionCategory(LongitudinalControllerPerception.class).getLeaders();
75              return Optional.ofNullable(delayActuation(getDesiredAcceleration(gtu, leaders, settings), gtu));
76          }
77          catch (OperationalPlanException exception)
78          {
79              throw new OtsRuntimeException("Missing perception category LongitudinalControllerPerception", exception);
80          }
81          catch (ParameterException exception)
82          {
83              throw new OtsRuntimeException("Missing parameter", exception);
84          }
85      }
86  
87      /**
88       * Returns the desired acceleration from the longitudinal control.
89       * @param gtu gtu
90       * @param leaders leaders
91       * @param settings system settings
92       * @return desired acceleration
93       * @throws ParameterException if parameter is not present
94       */
95      public abstract Acceleration getDesiredAcceleration(LaneBasedGtu gtu,
96              PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, Parameters settings) throws ParameterException;
97  
98  }