1 package org.opentrafficsim.road.gtu.lane;
2
3 import org.djunits.value.vdouble.scalar.Acceleration;
4 import org.djunits.value.vdouble.scalar.Duration;
5 import org.djunits.value.vdouble.scalar.Speed;
6 import org.opentrafficsim.core.network.OTSNetwork;
7
8 /**
9 * Checks acceleration bounds.
10 * <p>
11 * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
13 * <p>
14 * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 6, 2019 <br>
15 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
18 */
19 public class AccelerationChecker extends AbstractLaneBasedMoveChecker
20 {
21
22 /** Minimum allowable acceleration. */
23 private final Acceleration min;
24
25 /** Maximum allowable acceleration. */
26 private final Acceleration max;
27
28 /** Speed above which acceleration should be checked. */
29 private final Speed minSpeed;
30
31 /**
32 * Constructor.
33 * @param network OTSNetwork; network
34 */
35 public AccelerationChecker(final OTSNetwork network)
36 {
37 this(network, Acceleration.instantiateSI(-10.0), Acceleration.instantiateSI(5), Speed.instantiateSI(2.5));
38 }
39
40 /**
41 * Constructor.
42 * @param network OTSNetwork; network
43 * @param min Acceleration; minimum allowable acceleration
44 * @param max Acceleration; maximum allowable acceleration
45 * @param minSpeed Speed; speed above which acceleration should be checked
46 */
47 public AccelerationChecker(final OTSNetwork network, final Acceleration min, final Acceleration max, final Speed minSpeed)
48 {
49 super(network);
50 this.min = min;
51 this.max = max;
52 this.minSpeed = minSpeed;
53 }
54
55 /** {@inheritDoc} */
56 @Override
57 public void checkMove(final LaneBasedGTU gtu) throws Exception
58 {
59 Acceleration a = gtu.getOperationalPlan().getAcceleration(Duration.ZERO);
60 if (gtu.getOperationalPlan().getSpeed(Duration.ZERO).si > this.minSpeed.si
61 && (a.si < this.min.si || a.si > this.max.si))
62 {
63 gtu.getSimulator().getLogger().always().error("GTU: {} acceleration out of bounds ({}, {})", this.min, this.max);
64 }
65 }
66
67 }