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-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @version $Revision$, $LastChangedDate$, by $Author$, initial version Mar 12, 2019
* @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; }