AbstractLinearFreeControl.java

  1. package org.opentrafficsim.road.gtu.lane.control;

  2. import org.djunits.value.vdouble.scalar.Acceleration;
  3. import org.djunits.value.vdouble.scalar.Length;
  4. import org.djunits.value.vdouble.scalar.Speed;
  5. import org.opentrafficsim.base.parameters.ParameterException;
  6. import org.opentrafficsim.base.parameters.ParameterTypeDouble;
  7. import org.opentrafficsim.base.parameters.Parameters;
  8. import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
  9. import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
  10. import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
  11. import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
  12. import org.opentrafficsim.road.gtu.lane.perception.RelativeLane;
  13. import org.opentrafficsim.road.gtu.lane.perception.categories.InfrastructurePerception;
  14. import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGTU;
  15. import org.opentrafficsim.road.network.speed.SpeedLimitInfo;

  16. /**
  17.  * Class that splits the desired acceleration of a controller in a fixed linear free term, and a term for following determined
  18.  * by the sub-class.
  19.  * <p>
  20.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  21.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  22.  * <p>
  23.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Mar 14, 2019 <br>
  24.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  25.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  26.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  27.  */
  28. public abstract class AbstractLinearFreeControl extends AbstractActuatedControl
  29. {

  30.     /** Desired speed error gain parameter. */
  31.     public static final ParameterTypeDouble KF =
  32.             new ParameterTypeDouble("kf", "Desired speed error gain", 0.075, NumericConstraint.POSITIVE);

  33.     /**
  34.      * Constructor using default sensors with no delay.
  35.      * @param delayedActuation DelayedActuation; delayed actuation
  36.      */
  37.     public AbstractLinearFreeControl(final DelayedActuation delayedActuation)
  38.     {
  39.         super(delayedActuation);
  40.     }

  41.     /** {@inheritDoc} */
  42.     @Override
  43.     public final Acceleration getDesiredAcceleration(final LaneBasedGTU gtu,
  44.             final PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders, final Parameters settings) throws ParameterException
  45.     {
  46.         SpeedLimitInfo speedInfo;
  47.         try
  48.         {
  49.             speedInfo = gtu.getTacticalPlanner().getPerception().getPerceptionCategory(InfrastructurePerception.class)
  50.                     .getSpeedLimitProspect(RelativeLane.CURRENT).getSpeedLimitInfo(Length.ZERO);
  51.         }
  52.         catch (OperationalPlanException exception)
  53.         {
  54.             throw new RuntimeException("Infrastructure perception is not available.", exception);
  55.         }
  56.         Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(gtu.getParameters(), speedInfo);
  57.         Acceleration a = Acceleration.instantiateSI(settings.getParameter(KF) * (v0.si - gtu.getSpeed().si));
  58.         if (leaders.isEmpty())
  59.         {
  60.             return a;
  61.         }
  62.         return Acceleration.min(a, getFollowingAcceleration(gtu, leaders, settings));
  63.     }

  64.     /**
  65.      * Returns the following acceleration of the longitudinal control. This method is only invoked if there is at least 1
  66.      * leader.
  67.      * @param gtu LaneBasedGTU; gtu
  68.      * @param leaders PerceptionCollectable&lt;HeadwayGTU, LaneBasedGTU&gt;; leaders
  69.      * @param settings Parameters; system settings
  70.      * @return Acceleration; following acceleration of the longitudinal control
  71.      * @throws ParameterException if parameter is not present
  72.      */
  73.     public abstract Acceleration getFollowingAcceleration(LaneBasedGTU gtu,
  74.             PerceptionCollectable<HeadwayGTU, LaneBasedGTU> leaders, Parameters settings) throws ParameterException;

  75. }