VehicleModel.java

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

  2. import org.djunits.value.vdouble.scalar.Acceleration;
  3. import org.djunits.value.vdouble.scalar.Mass;
  4. import org.djunits.value.vdouble.scalar.Speed;

  5. /**
  6.  * Interface for vehicle models.
  7.  * <p>
  8.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  9.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  10.  * </p>
  11.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  12.  * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
  13.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  14.  */
  15. public interface VehicleModel
  16. {

  17.     /** No bounds. */
  18.     VehicleModel NONE = new VehicleModel()
  19.     {
  20.         @Override
  21.         public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
  22.         {
  23.             return acceleration;
  24.         }

  25.         @Override
  26.         public String toString()
  27.         {
  28.             return "VehicleModel [None]";
  29.         }
  30.     };

  31.     /** Acceleration bounded by GTU min and max acceleration. */
  32.     VehicleModel MINMAX = new VehicleModel()
  33.     {
  34.         @Override
  35.         public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
  36.         {
  37.             return acceleration.si > gtu.getMaximumDeceleration().si
  38.                     ? (acceleration.si < gtu.getMaximumAcceleration().si ? acceleration : gtu.getMaximumAcceleration())
  39.                     : gtu.getMaximumDeceleration();
  40.         }

  41.         @Override
  42.         public String toString()
  43.         {
  44.             return "VehicleModel [MinMax]";
  45.         }
  46.     };

  47.     /**
  48.      * Returns a bounded acceleration.
  49.      * @param acceleration intended acceleration
  50.      * @param gtu gtu
  51.      * @return possible acceleration
  52.      */
  53.     Acceleration boundAcceleration(Acceleration acceleration, LaneBasedGtu gtu);

  54.     /**
  55.      * GTU mass.
  56.      * @return GTU mass
  57.      */
  58.     default Mass getMass()
  59.     {
  60.         return null;
  61.     }

  62.     /**
  63.      * Moment of inertia about z-axis and center point of gravity.
  64.      * @return moment of inertia about z-axis
  65.      */
  66.     default double getMomentOfInertiaAboutZ()
  67.     {
  68.         return 0;
  69.     }

  70.     /**
  71.      * Returns whether the braking lights are on. The default implementation returns {@code true} if the deceleration is larger
  72.      * than a speed-dependent threshold given by:<br>
  73.      * <br>
  74.      * c0 * g(v) + c1 + c3*v^2<br>
  75.      * <br>
  76.      * where c0 = 0.2, c1 = 0.15 and c3 = 0.00025 (with c2 = 0 implicit) are empirically derived averages, and g(v) is 0 below
  77.      * 25 km/h or 1 otherwise, representing that the engine is disengaged at low speeds.
  78.      * @param speed speed
  79.      * @param acceleration acceleration
  80.      * @return whether the braking lights are on
  81.      */
  82.     default boolean isBrakingLightsOn(final Speed speed, final Acceleration acceleration)
  83.     {
  84.         return acceleration.si < (speed.si < 6.944 ? 0.0 : -0.2) - 0.15 - 0.00025 * speed.si * speed.si;
  85.     }

  86.     /**
  87.      * Defines (fixed) mass and moment of inertia about z-axis. Acceleration is limited using {@code VehicleModel.MINMAX}.
  88.      * <p>
  89.      * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
  90.      * <br>
  91.      * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  92.      * </p>
  93.      * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  94.      * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
  95.      * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  96.      */
  97.     class MassBased implements VehicleModel
  98.     {
  99.         /** Mass. */
  100.         private final Mass mass;

  101.         /** Moment of inertia about z-axis. */
  102.         private final double momentOfInertiaAboutZ;

  103.         /**
  104.          * @param mass mass
  105.          * @param momentOfInertiaAboutZ moment of inertia about z-axis
  106.          */
  107.         public MassBased(final Mass mass, final double momentOfInertiaAboutZ)
  108.         {
  109.             this.mass = mass;
  110.             this.momentOfInertiaAboutZ = momentOfInertiaAboutZ;
  111.         }

  112.         @Override
  113.         public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
  114.         {
  115.             return MINMAX.boundAcceleration(acceleration, gtu);
  116.         }

  117.         @Override
  118.         public Mass getMass()
  119.         {
  120.             return this.mass;
  121.         }

  122.         @Override
  123.         public double getMomentOfInertiaAboutZ()
  124.         {
  125.             return this.momentOfInertiaAboutZ;
  126.         }
  127.     }

  128. }