AbstractLinearFreeControl.java
package org.opentrafficsim.road.gtu.control;
import org.djunits.value.vdouble.scalar.Acceleration;
import org.djunits.value.vdouble.scalar.Speed;
import org.opentrafficsim.base.parameters.ParameterException;
import org.opentrafficsim.base.parameters.ParameterTypeDouble;
import org.opentrafficsim.base.parameters.Parameters;
import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
import org.opentrafficsim.road.gtu.LaneBasedGtu;
import org.opentrafficsim.road.gtu.perception.PerceptionCollectable;
import org.opentrafficsim.road.gtu.perception.object.PerceivedGtu;
import org.opentrafficsim.road.network.speed.SpeedLimits;
/**
* Class that splits the desired acceleration of a controller in a fixed linear free term, and a term for following determined
* by the sub-class.
* <p>
* Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
* BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
* </p>
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
public abstract class AbstractLinearFreeControl extends AbstractActuatedControl
{
/** Desired speed error gain parameter. */
public static final ParameterTypeDouble KF =
new ParameterTypeDouble("kf", "Desired speed error gain", 0.075, NumericConstraint.POSITIVE);
/**
* Constructor using default sensors with no delay.
* @param delayedActuation delayed actuation
*/
public AbstractLinearFreeControl(final DelayedActuation delayedActuation)
{
super(delayedActuation);
}
@Override
public final Acceleration getDesiredAcceleration(final LaneBasedGtu gtu,
final PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, final Parameters settings)
throws ParameterException
{
SpeedLimits speedLimits = gtu.getLane().getSpeedLimits(gtu.getType());
Speed v0 = gtu.getTacticalPlanner().getCarFollowingModel().desiredSpeed(gtu.getParameters(), speedLimits,
gtu.getMaximumSpeed());
Acceleration a = Acceleration.ofSI(settings.getParameter(KF) * (v0.si - gtu.getSpeed().si));
if (leaders.isEmpty())
{
return a;
}
return Acceleration.min(a, getFollowingAcceleration(gtu, leaders, settings));
}
/**
* Returns the following acceleration of the longitudinal control. This method is only invoked if there is at least 1
* leader.
* @param gtu gtu
* @param leaders leaders
* @param settings system settings
* @return following acceleration of the longitudinal control
* @throws ParameterException if parameter is not present
*/
public abstract Acceleration getFollowingAcceleration(LaneBasedGtu gtu,
PerceptionCollectable<PerceivedGtu, LaneBasedGtu> leaders, Parameters settings) throws ParameterException;
}