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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  21.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  22.  * </p>
  23.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  24.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  25.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  26.  */
  27. public abstract class AbstractLinearFreeControl extends AbstractActuatedControl
  28. {

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

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

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

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

  74. }