View Javadoc
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.Network;
7   
8   /**
9    * Checks acceleration bounds.
10   * <p>
11   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13   * </p>
14   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
16   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
17   */
18  public class AccelerationChecker extends AbstractLaneBasedMoveChecker
19  {
20  
21      /** Minimum allowable acceleration. */
22      private final Acceleration min;
23  
24      /** Maximum allowable acceleration. */
25      private final Acceleration max;
26  
27      /** Speed above which acceleration should be checked. */
28      private final Speed minSpeed;
29  
30      /**
31       * Constructor.
32       * @param network Network; network
33       */
34      public AccelerationChecker(final Network network)
35      {
36          this(network, Acceleration.instantiateSI(-10.0), Acceleration.instantiateSI(5), Speed.instantiateSI(2.5));
37      }
38  
39      /**
40       * Constructor.
41       * @param network Network; network
42       * @param min Acceleration; minimum allowable acceleration
43       * @param max Acceleration; maximum allowable acceleration
44       * @param minSpeed Speed; speed above which acceleration should be checked
45       */
46      public AccelerationChecker(final Network network, final Acceleration min, final Acceleration max, final Speed minSpeed)
47      {
48          super(network);
49          this.min = min;
50          this.max = max;
51          this.minSpeed = minSpeed;
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public void checkMove(final LaneBasedGtu gtu) throws Exception
57      {
58          Acceleration a = gtu.getOperationalPlan().getAcceleration(Duration.ZERO);
59          if (gtu.getOperationalPlan().getSpeed(Duration.ZERO).si > this.minSpeed.si
60                  && (a.si < this.min.si || a.si > this.max.si))
61          {
62              gtu.getSimulator().getLogger().always().error("GTU: {} acceleration out of bounds ({}, {})", this.min, this.max);
63          }
64      }
65  
66  }