org.opentrafficsim.road.gtu.lane.control.AbstractActuatedControl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ots-road Show documentation
Show all versions of ots-road Show documentation
OpenTrafficSim road classes
The newest version!
package org.opentrafficsim.road.gtu.lane.control;
import org.djunits.value.vdouble.scalar.Acceleration;
import org.djunits.value.vdouble.scalar.Duration;
import org.djunits.value.vdouble.scalar.Length;
import org.opentrafficsim.base.parameters.ParameterException;
import org.opentrafficsim.base.parameters.ParameterTypeDuration;
import org.opentrafficsim.base.parameters.ParameterTypeLength;
import org.opentrafficsim.base.parameters.Parameters;
import org.opentrafficsim.base.parameters.constraint.NumericConstraint;
import org.opentrafficsim.core.gtu.plan.operational.OperationalPlanException;
import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
import org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable;
import org.opentrafficsim.road.gtu.lane.perception.categories.neighbors.LongitudinalControllerPerception;
import org.opentrafficsim.road.gtu.lane.perception.headway.HeadwayGtu;
/**
* Simple linear CACC controller.
*
* Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
public abstract class AbstractActuatedControl implements LongitudinalControl
{
/** Time headway setting for ACC mode. */
public static final ParameterTypeDuration TDACC = new ParameterTypeDuration("td ACC",
"User defined time headway in ACC mode", Duration.instantiateSI(1.2), NumericConstraint.POSITIVE);
/** Time headway setting for CACC mode. */
public static final ParameterTypeDuration TDCACC = new ParameterTypeDuration("td CACC",
"User defined time headway in CACC mode", Duration.instantiateSI(0.5), NumericConstraint.POSITIVE);
/** (C)ACC stopping distance. */
public static final ParameterTypeLength X0 = new ParameterTypeLength("x0 (C)ACC", "Stopping distance (C)ACC",
Length.instantiateSI(3.0), NumericConstraint.POSITIVE);
/** Delayed actuation. */
private final DelayedActuation delayedActuation;
/**
* Constructor using default sensors with no delay.
* @param delayedActuation DelayedActuation; delayed actuation
*/
public AbstractActuatedControl(final DelayedActuation delayedActuation)
{
this.delayedActuation = delayedActuation;
}
/**
* Delays the actuation of acceleration.
* @param desiredAcceleration Acceleration; desired acceleration
* @param gtu LaneBasedGtu; gtu
* @return Acceleration; delayed acceleration
*/
public Acceleration delayActuation(final Acceleration desiredAcceleration, final LaneBasedGtu gtu)
{
return this.delayedActuation.delayActuation(desiredAcceleration, gtu);
}
/** {@inheritDoc} */
@Override
public Acceleration getAcceleration(final LaneBasedGtu gtu, final Parameters settings)
{
try
{
PerceptionCollectable leaders = gtu.getTacticalPlanner().getPerception()
.getPerceptionCategory(LongitudinalControllerPerception.class).getLeaders();
return delayActuation(getDesiredAcceleration(gtu, leaders, settings), gtu);
}
catch (OperationalPlanException exception)
{
throw new RuntimeException("Missing perception category LongitudinalControllerPerception", exception);
}
catch (ParameterException exception)
{
throw new RuntimeException("Missing parameter", exception);
}
}
/**
* Returns the desired acceleration from the longitudinal control.
* @param gtu LaneBasedGtu; gtu
* @param leaders PerceptionCollectable<HeadwayGtu, LaneBasedGtu>; leaders
* @param settings Parameters; system settings
* @return Acceleration; desired acceleration
* @throws ParameterException if parameter is not present
*/
public abstract Acceleration getDesiredAcceleration(LaneBasedGtu gtu,
PerceptionCollectable leaders, Parameters settings) throws ParameterException;
}