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-2019 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) throws ParameterException
50      {
51          Parameters params = gtu.getParameters();
52          SpeedLimitInfo speedInfo;
53          try
54          {
55              speedInfo = gtu.getTacticalPlanner().getPerception().getPerceptionCategory(InfrastructurePerception.class)
56                      .getSpeedLimitProspect(RelativeLane.CURRENT).getSpeedLimitInfo(Length.ZERO);
57          }
58          catch (OperationalPlanException exception)
59          {
60              throw new RuntimeException("Infrastructure perception is not available.", exception);
61          }
62          Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(params, speedInfo);
63          Acceleration a = Acceleration.createSI(params.getParameter(KF) * (v0.si - gtu.getSpeed().si));
64          if (leaders.isEmpty())
65          {
66              return a;
67          }
68          return Acceleration.min(a, getFollowingAcceleration(gtu, leaders));
69      }
70  
71      /**
72       * Returns the following acceleration of the longitudinal control. This method is only invoked if there is at least 1
73       * leader.
74       * @param gtu LaneBasedGTU; gtu
75       * @param leaders PerceptionCollectable&lt;HeadwayGTU, LaneBasedGTU&gt;; leaders
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) throws ParameterException;
81  
82  }