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