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-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
24   * <p>
25   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Mar 14, 2019 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
28   * @author <a href="http://www.transport.citg.tudelft.nl">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 DelayedActuation; delayed actuation
40       */
41      public AbstractLinearFreeControl(final DelayedActuation delayedActuation)
42      {
43          super(delayedActuation);
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public final Acceleration getDesiredAcceleration(final LaneBasedGTU gtu,
49              final PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders, final Parameters settings) 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 RuntimeException("Infrastructure perception is not available.", exception);
60          }
61          Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(gtu.getParameters(), speedInfo);
62          Acceleration a = Acceleration.instantiateSI(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 LaneBasedGTU; gtu
74       * @param leaders PerceptionCollectable&lt;HeadwayGTU, LaneBasedGTU&gt;; leaders
75       * @param settings Parameters; system settings
76       * @return Acceleration; following acceleration of the longitudinal control
77       * @throws ParameterException if parameter is not present
78       */
79      public abstract Acceleration getFollowingAcceleration(LaneBasedGTU gtu,
80              PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders, Parameters settings) throws ParameterException;
81  
82  }