View Javadoc
1   package org.opentrafficsim.road.gtu.control;
2   
3   import org.djunits.value.vdouble.scalar.Acceleration;
4   import org.djunits.value.vdouble.scalar.Speed;
5   import org.opentrafficsim.base.parameters.ParameterException;
6   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
7   import org.opentrafficsim.base.parameters.Parameters;
8   import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
9   import org.opentrafficsim.road.gtu.LaneBasedGtu;
10  import org.opentrafficsim.road.gtu.perception.PerceptionCollectable;
11  import org.opentrafficsim.road.gtu.perception.object.PerceivedGtu;
12  import org.opentrafficsim.road.network.speed.SpeedLimits;
13  
14  /**
15   * Class that splits the desired acceleration of a controller in a fixed linear free term, and a term for following determined
16   * by the sub-class.
17   * <p>
18   * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * </p>
21   * @author Alexander Verbraeck
22   * @author Peter Knoppers
23   * @author Wouter Schakel
24   */
25  public abstract class AbstractLinearFreeControl extends AbstractActuatedControl
26  {
27  
28      /** Desired speed error gain parameter. */
29      public static final ParameterTypeDouble KF =
30              new ParameterTypeDouble("kf", "Desired speed error gain", 0.075, NumericConstraint.POSITIVE);
31  
32      /**
33       * Constructor using default sensors with no delay.
34       * @param delayedActuation delayed actuation
35       */
36      public AbstractLinearFreeControl(final DelayedActuation delayedActuation)
37      {
38          super(delayedActuation);
39      }
40  
41      @Override
42      public final Acceleration getDesiredAcceleration(final LaneBasedGtu gtu,
43              final PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, final Parameters settings)
44              throws ParameterException
45      {
46          SpeedLimits speedLimits = gtu.getLane().getSpeedLimits(gtu.getType());
47          Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(gtu.getParameters(), speedLimits,
48                  gtu.getMaximumSpeed());
49          Acceleration a = Acceleration.ofSI(settings.getParameter(KF) * (v0.si - gtu.getSpeed().si));
50          if (leaders.isEmpty())
51          {
52              return a;
53          }
54          return Acceleration.min(a, getFollowingAcceleration(gtu, leaders, settings));
55      }
56  
57      /**
58       * Returns the following acceleration of the longitudinal control. This method is only invoked if there is at least 1
59       * leader.
60       * @param gtu gtu
61       * @param leaders leaders
62       * @param settings system settings
63       * @return following acceleration of the longitudinal control
64       * @throws ParameterException if parameter is not present
65       */
66      public abstract Acceleration getFollowingAcceleration(LaneBasedGtu gtu,
67              PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, Parameters settings) throws ParameterException;
68  
69  }