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://github.com/peter-knoppers">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 delayed actuation
39       */
40      public AbstractLinearFreeControl(final DelayedActuation delayedActuation)
41      {
42          super(delayedActuation);
43      }
44  
45      @Override
46      public final Acceleration getDesiredAcceleration(final LaneBasedGtu gtu,
47              final PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders, final Parameters settings) throws ParameterException
48      {
49          SpeedLimitInfo speedInfo;
50          try
51          {
52              speedInfo = gtu.getTacticalPlanner().getPerception().getPerceptionCategory(InfrastructurePerception.class)
53                      .getSpeedLimitProspect(RelativeLane.CURRENT).getSpeedLimitInfo(Length.ZERO);
54          }
55          catch (OperationalPlanException exception)
56          {
57              throw new RuntimeException("Infrastructure perception is not available.", exception);
58          }
59          Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(gtu.getParameters(), speedInfo);
60          Acceleration a = Acceleration.instantiateSI(settings.getParameter(KF) * (v0.si - gtu.getSpeed().si));
61          if (leaders.isEmpty())
62          {
63              return a;
64          }
65          return Acceleration.min(a, getFollowingAcceleration(gtu, leaders, settings));
66      }
67  
68      /**
69       * Returns the following acceleration of the longitudinal control. This method is only invoked if there is at least 1
70       * leader.
71       * @param gtu gtu
72       * @param leaders leaders
73       * @param settings system settings
74       * @return following acceleration of the longitudinal control
75       * @throws ParameterException if parameter is not present
76       */
77      public abstract Acceleration getFollowingAcceleration(LaneBasedGtu gtu,
78              PerceptionCollectable<HeadwayGtu, LaneBasedGtu> leaders, Parameters settings) throws ParameterException;
79  
80  }