1 package org.opentrafficsim.road.gtu.lane;
2
3 import org.djunits.value.vdouble.scalar.Acceleration;
4 import org.djunits.value.vdouble.scalar.Mass;
5 import org.djunits.value.vdouble.scalar.Speed;
6
7 /**
8 * Interface for vehicle models.
9 * <p>
10 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
12 * </p>
13 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
14 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
15 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
16 */
17 public interface VehicleModel
18 {
19
20 /** No bounds. */
21 VehicleModel NONE = new VehicleModel()
22 {
23 @Override
24 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
25 {
26 return acceleration;
27 }
28
29 @Override
30 public String toString()
31 {
32 return "VehicleModel [None]";
33 }
34 };
35
36 /** Acceleration bounded by GTU min and max acceleration. */
37 VehicleModel MINMAX = new VehicleModel()
38 {
39 @Override
40 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
41 {
42 return acceleration.si > gtu.getMaximumDeceleration().si
43 ? (acceleration.si < gtu.getMaximumAcceleration().si ? acceleration : gtu.getMaximumAcceleration())
44 : gtu.getMaximumDeceleration();
45 }
46
47 @Override
48 public String toString()
49 {
50 return "VehicleModel [MinMax]";
51 }
52 };
53
54 /**
55 * Returns a bounded acceleration.
56 * @param acceleration intended acceleration
57 * @param gtu gtu
58 * @return possible acceleration
59 */
60 Acceleration boundAcceleration(Acceleration acceleration, LaneBasedGtu gtu);
61
62 /**
63 * GTU mass.
64 * @return GTU mass
65 */
66 default Mass getMass()
67 {
68 return null;
69 }
70
71 /**
72 * Moment of inertia about z-axis and center point of gravity.
73 * @return moment of inertia about z-axis
74 */
75 default double getMomentOfInertiaAboutZ()
76 {
77 return 0;
78 }
79
80 /**
81 * Returns whether the braking lights are on. The default implementation returns {@code true} if the deceleration is larger
82 * than a speed-dependent threshold given by:<br>
83 * <br>
84 * c0 * g(v) + c1 + c3*v^2<br>
85 * <br>
86 * 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
87 * 25 km/h or 1 otherwise, representing that the engine is disengaged at low speeds.
88 * @param speed speed
89 * @param acceleration acceleration
90 * @return whether the braking lights are on
91 */
92 default boolean isBrakingLightsOn(final Speed speed, final Acceleration acceleration)
93 {
94 return acceleration.si < (speed.si < 6.944 ? 0.0 : -0.2) - 0.15 - 0.00025 * speed.si * speed.si;
95 }
96
97 /**
98 * Defines (fixed) mass and moment of inertia about z-axis. Acceleration is limited using {@code VehicleModel.MINMAX}.
99 * <p>
100 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
101 * <br>
102 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
103 * </p>
104 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
105 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
106 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
107 */
108 class MassBased implements VehicleModel
109 {
110 /** Mass. */
111 private final Mass mass;
112
113 /** Moment of inertia about z-axis. */
114 private final double momentOfInertiaAboutZ;
115
116 /**
117 * @param mass mass
118 * @param momentOfInertiaAboutZ moment of inertia about z-axis
119 */
120 public MassBased(final Mass mass, final double momentOfInertiaAboutZ)
121 {
122 this.mass = mass;
123 this.momentOfInertiaAboutZ = momentOfInertiaAboutZ;
124 }
125
126 @Override
127 public Acceleration boundAcceleration(final Acceleration acceleration, final LaneBasedGtu gtu)
128 {
129 return MINMAX.boundAcceleration(acceleration, gtu);
130 }
131
132 @Override
133 public Mass getMass()
134 {
135 return this.mass;
136 }
137
138 @Override
139 public double getMomentOfInertiaAboutZ()
140 {
141 return this.momentOfInertiaAboutZ;
142 }
143 }
144
145 }