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.base.logger.Logger;
7   import org.opentrafficsim.core.network.Network;
8   
9   /**
10   * Checks acceleration bounds.
11   * <p>
12   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * </p>
15   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
17   * @author <a href="https://github.com/wjschakel">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 network
34       */
35      public AccelerationChecker(final Network network)
36      {
37          this(network, Acceleration.ofSI(-10.0), Acceleration.ofSI(5), Speed.ofSI(2.5));
38      }
39  
40      /**
41       * Constructor.
42       * @param network network
43       * @param min minimum allowable acceleration
44       * @param max maximum allowable acceleration
45       * @param minSpeed speed above which acceleration should be checked
46       */
47      public AccelerationChecker(final Network 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      @Override
56      public void checkMove(final LaneBasedGtu gtu) throws Exception
57      {
58          Acceleration a = gtu.getOperationalPlan().getAcceleration(Duration.ZERO);
59          if (gtu.getOperationalPlan().getSpeedFromStart(Duration.ZERO).si > this.minSpeed.si
60                  && (a.si < this.min.si || a.si > this.max.si))
61          {
62              Logger.ots().error("GTU: {} acceleration out of bounds ({}, {})", this.min, this.max);
63          }
64      }
65  
66  }