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.OtsRuntimeException;
7   import org.opentrafficsim.base.parameters.ParameterException;
8   import org.opentrafficsim.base.parameters.ParameterTypeDouble;
9   import org.opentrafficsim.base.parameters.Parameters;
10  import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
11  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
12  import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
13  import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
14  import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
15  import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
16  import org.opentrafficsim.road.gtu.lane.perception.object.PerceivedGtu;
17  import org.opentrafficsim.road.network.speed.SpeedLimitInfo;
18  
19  /**
20   * Class that splits the desired acceleration of a controller in a fixed linear free term, and a term for following determined
21   * by the sub-class.
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 AbstractLinearFreeControl extends AbstractActuatedControl
31  {
32  
33      /** Desired speed error gain parameter. */
34      public static final ParameterTypeDouble KF =
35              new ParameterTypeDouble("kf", "Desired speed error gain", 0.075, NumericConstraint.POSITIVE);
36  
37      /**
38       * Constructor using default sensors with no delay.
39       * @param delayedActuation delayed actuation
40       */
41      public AbstractLinearFreeControl(final DelayedActuation delayedActuation)
42      {
43          super(delayedActuation);
44      }
45  
46      @Override
47      public final Acceleration getDesiredAcceleration(final LaneBasedGtu gtu,
48              final PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, final Parameters settings)
49              throws ParameterException
50      {
51          SpeedLimitInfo speedInfo;
52          try
53          {
54              speedInfo = gtu.getTacticalPlanner().getPerception().getPerceptionCategory(InfrastructurePerception.class)
55                      .getSpeedLimitProspect(RelativeLane.CURRENT).getSpeedLimitInfo(Length.ZERO);
56          }
57          catch (OperationalPlanException exception)
58          {
59              throw new OtsRuntimeException("Infrastructure perception is not available.", exception);
60          }
61          Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(gtu.getParameters(), speedInfo);
62          Acceleration a = Acceleration.ofSI(settings.getParameter(KF) * (v0.si - gtu.getSpeed().si));
63          if (leaders.isEmpty())
64          {
65              return a;
66          }
67          return Acceleration.min(a, getFollowingAcceleration(gtu, leaders, settings));
68      }
69  
70      /**
71       * Returns the following acceleration of the longitudinal control. This method is only invoked if there is at least 1
72       * leader.
73       * @param gtu gtu
74       * @param leaders leaders
75       * @param settings system settings
76       * @return following acceleration of the longitudinal control
77       * @throws ParameterException if parameter is not present
78       */
79      public abstract Acceleration getFollowingAcceleration(LaneBasedGtu gtu,
80              PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, Parameters settings) throws ParameterException;
81  
82  }