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.Length;
5   import org.djunits.value.vdouble.scalar.Speed;
6   import org.opentrafficsim.base.parameters.ParameterException;
7   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
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.RelativeLane;
14  import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
15  import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGtu;
16  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
17  
18  /**
19   * Class that splits the desired acceleration of a controller in a fixed linear free term, and a term for following determined
20   * by the sub-class.
21   * <p>
22   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
24   * </p>
25   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
27   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
28   */
29  public abstract class AbstractLinearFreeControl extends AbstractActuatedControl
30  {
31  
32      /** Desired speed error gain parameter. */
33      public static final ParameterTypeDouble KF =
34              new ParameterTypeDouble("kf", "Desired speed error gain", 0.075, NumericConstraint.POSITIVE);
35  
36      /**
37       * Constructor using default sensors with no delay.
38       * @param delayedActuation DelayedActuation; delayed actuation
39       */
40      public AbstractLinearFreeControl(final DelayedActuation delayedActuation)
41      {
42          super(delayedActuation);
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      public final Acceleration getDesiredAcceleration(final LaneBasedGtu gtu,
48              final PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders, final Parameters settings) throws ParameterException
49      {
50          SpeedLimitInfo speedInfo;
51          try
52          {
53              speedInfo = gtu.getTacticalPlanner().getPerception().getPerceptionCategory(InfrastructurePerception.class)
54                      .getSpeedLimitProspect(RelativeLane.CURRENT).getSpeedLimitInfo(Length.ZERO);
55          }
56          catch (OperationalPlanException exception)
57          {
58              throw new RuntimeException("Infrastructure perception is not available.", exception);
59          }
60          Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(gtu.getParameters(), speedInfo);
61          Acceleration a = Acceleration.instantiateSI(settings.getParameter(KF) * (v0.si - gtu.getSpeed().si));
62          if (leaders.isEmpty())
63          {
64              return a;
65          }
66          return Acceleration.min(a, getFollowingAcceleration(gtu, leaders, settings));
67      }
68  
69      /**
70       * Returns the following acceleration of the longitudinal control. This method is only invoked if there is at least 1
71       * leader.
72       * @param gtu LaneBasedGtu; gtu
73       * @param leaders PerceptionCollectable&lt;HeadwayGtu, LaneBasedGtu&gt;; leaders
74       * @param settings Parameters; system settings
75       * @return Acceleration; following acceleration of the longitudinal control
76       * @throws ParameterException if parameter is not present
77       */
78      public abstract Acceleration getFollowingAcceleration(LaneBasedGtu gtu,
79              PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders, Parameters settings) throws ParameterException;
80  
81  }