AccelerationChecker.java

  1. package org.opentrafficsim.road.gtu.lane;

  2. import org.djunits.value.vdouble.scalar.Acceleration;
  3. import org.djunits.value.vdouble.scalar.Duration;
  4. import org.djunits.value.vdouble.scalar.Speed;
  5. import org.opentrafficsim.core.network.OTSNetwork;

  6. /**
  7.  * Checks acceleration bounds.
  8.  * <p>
  9.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  10.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  11.  * <p>
  12.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 6, 2019 <br>
  13.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  14.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  15.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  16.  */
  17. public class AccelerationChecker extends AbstractLaneBasedMoveChecker
  18. {

  19.     /** Minimum allowable acceleration. */
  20.     private final Acceleration min;

  21.     /** Maximum allowable acceleration. */
  22.     private final Acceleration max;

  23.     /** Speed above which acceleration should be checked. */
  24.     private final Speed minSpeed;

  25.     /**
  26.      * Constructor.
  27.      * @param network OTSNetwork; network
  28.      */
  29.     public AccelerationChecker(final OTSNetwork network)
  30.     {
  31.         this(network, Acceleration.instantiateSI(-10.0), Acceleration.instantiateSI(5), Speed.instantiateSI(2.5));
  32.     }

  33.     /**
  34.      * Constructor.
  35.      * @param network OTSNetwork; network
  36.      * @param min Acceleration; minimum allowable acceleration
  37.      * @param max Acceleration; maximum allowable acceleration
  38.      * @param minSpeed Speed; speed above which acceleration should be checked
  39.      */
  40.     public AccelerationChecker(final OTSNetwork network, final Acceleration min, final Acceleration max, final Speed minSpeed)
  41.     {
  42.         super(network);
  43.         this.min = min;
  44.         this.max = max;
  45.         this.minSpeed = minSpeed;
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public void checkMove(final LaneBasedGTU gtu) throws Exception
  50.     {
  51.         Acceleration a = gtu.getOperationalPlan().getAcceleration(Duration.ZERO);
  52.         if (gtu.getOperationalPlan().getSpeed(Duration.ZERO).si > this.minSpeed.si
  53.                 && (a.si < this.min.si || a.si > this.max.si))
  54.         {
  55.             gtu.getSimulator().getLogger().always().error("GTU: {} acceleration out of bounds ({}, {})", this.min, this.max);
  56.         }
  57.     }

  58. }