1 package org.opentrafficsim.road.gtu.lane;
2
3 import java.util.Map;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djunits.value.vdouble.scalar.Time;
7 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
8 import org.opentrafficsim.core.gtu.GTU;
9 import org.opentrafficsim.core.gtu.GTUDirectionality;
10 import org.opentrafficsim.core.gtu.GTUException;
11 import org.opentrafficsim.core.gtu.RelativePosition;
12 import org.opentrafficsim.core.network.LateralDirectionality;
13 import org.opentrafficsim.road.gtu.lane.tactical.LaneBasedTacticalPlanner;
14 import org.opentrafficsim.road.gtu.strategical.LaneBasedStrategicalPlanner;
15 import org.opentrafficsim.road.network.lane.DirectedLanePosition;
16 import org.opentrafficsim.road.network.lane.Lane;
17
18 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent;
19 import nl.tudelft.simulation.event.EventType;
20 import nl.tudelft.simulation.language.d3.DirectedPoint;
21
22 /**
23 * This interface defines a lane based GTU.
24 * <p>
25 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
26 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
27 * <p>
28 * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
29 * initial version Oct 22, 2014 <br>
30 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
31 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
32 */
33 public interface LaneBasedGTU extends GTU
34 {
35 /** {@inheritDoc} */
36 @Override
37 LaneBasedStrategicalPlanner getStrategicalPlanner();
38
39 /** {@inheritDoc} */
40 @Override
41 LaneBasedTacticalPlanner getTacticalPlanner();
42
43 /**
44 * Return the location without a RemoteException.
45 * {@inheritDoc}
46 */
47 @Override
48 DirectedPoint getLocation();
49
50 /**
51 * insert GTU at a certain position. This can happen at setup (first initialization), and after a lane change of the GTU.
52 * The relative position that will be registered is the referencePosition (dx, dy, dz) = (0, 0, 0). Front and rear positions
53 * are relative towards this position.
54 * @param lane the lane to add to the list of lanes on which the GTU is registered.
55 * @param gtuDirection the direction of the GTU on the lane (which can be bidirectional). If the GTU has a positive speed,
56 * it is moving in this direction.
57 * @param position the position on the lane.
58 * @throws GTUException when positioning the GTU on the lane causes a problem
59 */
60 void enterLane(Lane lane, Length position, GTUDirectionality gtuDirection) throws GTUException;
61
62 /**
63 * Unregister the GTU from a lane.
64 * @param lane the lane to remove from the list of lanes on which the GTU is registered.
65 * @throws GTUException when leaveLane should not be called
66 */
67 void leaveLane(Lane lane) throws GTUException;
68
69 /**
70 * Change lanes instantaneously.
71 * @param laneChangeDirection the direction to change to
72 * @throws GTUException in case lane change fails
73 */
74 void changeLaneInstantaneously(LateralDirectionality laneChangeDirection) throws GTUException;
75
76 /**
77 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
78 * vehicle is registered. <br>
79 * <b>Note:</b> If a GTU is registered in multiple parallel lanes, the lateralLaneChangeModel is used to determine the
80 * center line of the vehicle at this point in time. Otherwise, the average of the center positions of the lines will be
81 * taken.
82 * @param relativePosition the position on the vehicle relative to the reference point.
83 * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU.
84 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
85 */
86 Map<Lane, Length> positions(RelativePosition relativePosition) throws GTUException;
87
88 /**
89 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
90 * vehicle is registered.
91 * @param relativePosition the position on the vehicle relative to the reference point.
92 * @param when the future time for which to calculate the positions.
93 * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of
94 * the GTU.
95 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
96 */
97 Map<Lane, Length> positions(RelativePosition relativePosition, Time when) throws GTUException;
98
99 /**
100 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane at the current
101 * simulation time. <br>
102 * @param lane the position on this lane will be returned.
103 * @param relativePosition the position on the vehicle relative to the reference point.
104 * @return DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane.
105 * @throws GTUException when the vehicle is not on the given lane.
106 */
107 Length position(Lane lane, RelativePosition relativePosition) throws GTUException;
108
109 /**
110 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane.
111 * @param lane the position on this lane will be returned.
112 * @param relativePosition the position on the vehicle relative to the reference point.
113 * @param when the future time for which to calculate the positions.
114 * @return DoubleScalarAbs<LengthUnit>; the position, relative to the center line of the Lane.
115 * @throws GTUException when the vehicle is not on the given lane.
116 */
117 Length position(Lane lane, RelativePosition relativePosition, Time when) throws GTUException;
118
119 /**
120 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
121 * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are
122 * next to each other and we compare an 'inner' and 'outer' curve.<br>
123 * @param relativePosition the position on the vehicle relative to the reference point.
124 * @return the lanes and the position on the lanes where the GTU is currently registered, for the given position of the GTU.
125 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
126 */
127 Map<Lane, Double> fractionalPositions(RelativePosition relativePosition) throws GTUException;
128
129 /**
130 * Return the longitudinal positions of a point relative to this GTU, relative to the center line of the Lanes in which the
131 * vehicle is registered, as fractions of the length of the lane. This is important when we want to see if two vehicles are
132 * next to each other and we compare an 'inner' and 'outer' curve.
133 * @param relativePosition the position on the vehicle relative to the reference point.
134 * @param when the future time for which to calculate the positions.
135 * @return the lanes and the position on the lanes where the GTU will be registered at the time, for the given position of
136 * the GTU.
137 * @throws GTUException when the vehicle is not on one of the lanes on which it is registered.
138 */
139 Map<Lane, Double> fractionalPositions(RelativePosition relativePosition, Time when) throws GTUException;
140
141 /**
142 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction
143 * of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an
144 * 'inner' and 'outer' curve.
145 * @param lane the position on this lane will be returned.
146 * @param relativePosition the position on the vehicle relative to the reference point.
147 * @param when the future time for which to calculate the positions.
148 * @return the fractional relative position on the lane at the given time.
149 * @throws GTUException when the vehicle is not on the given lane.
150 */
151 double fractionalPosition(Lane lane, RelativePosition relativePosition, Time when) throws GTUException;
152
153 /**
154 * Return the longitudinal position of a point relative to this GTU, relative to the center line of the Lane, as a fraction
155 * of the length of the lane. This is important when we want to see if two vehicles are next to each other and we compare an
156 * 'inner' and 'outer' curve.<br>
157 * @param lane the position on this lane will be returned.
158 * @param relativePosition the position on the vehicle relative to the reference point.
159 * @return the fractional relative position on the lane at the given time.
160 * @throws GTUException when the vehicle is not on the given lane.
161 */
162 double fractionalPosition(Lane lane, RelativePosition relativePosition) throws GTUException;
163
164 /**
165 * Return the longitudinal position that this GTU would have if it were to change to another Lane with a / the current
166 * CrossSectionLink.
167 * @param projectionLane Lane; the lane onto which the position of this GTU must be projected
168 * @param relativePosition RelativePosition; the point on this GTU that must be projected
169 * @param when Time; the time for which to project the position of this GTU
170 * @return Length; the position of this GTU in the projectionLane
171 * @throws GTUException when projectionLane it not in any of the CrossSectionLink that the GTU is on
172 */
173 Length projectedPosition(Lane projectionLane, RelativePosition relativePosition, Time when) throws GTUException;
174
175 /**
176 * Return the current Lane, position and directionality of the GTU.
177 * @return DirectedLanePosition; the current Lane, position and directionality of the GTU
178 * @throws GTUException in case the reference position of the GTU cannot be found on the lanes in its current path
179 */
180 DirectedLanePosition getReferencePosition() throws GTUException;
181
182 /**
183 * Return the directionality of a lane on which the GTU is registered for its current operational plan.
184 * @param lane Lane; the lane for which we want to know the direction
185 * @return GTUDirectionality; the direction on the given lane
186 * @throws GTUException in case the GTU is not registered on the Lane
187 */
188 GTUDirectionality getDirection(Lane lane) throws GTUException;
189
190 /**
191 * Add an event to the list of lane triggers scheduled for this GTU.
192 * @param lane Lane; the lane on which the event occurs
193 * @param event SimeEvent<OTSSimTimeDouble> the event
194 */
195 void addTrigger(Lane lane, SimEvent<OTSSimTimeDouble> event);
196
197 /**
198 * The lane-based event type for pub/sub indicating the initialization of a new GTU. <br>
199 * Payload: [String gtuId, DirectedPoint initialPosition, Length length, Length width, Color gtuBaseColor, Lane
200 * referenceLane, Length positionOnReferenceLane, GTUDirectionality direction]
201 */
202 EventType LANEBASED_INIT_EVENT = new EventType("LANEBASEDGTU.INIT");
203
204 /**
205 * The lane-based event type for pub/sub indicating a move. <br>
206 * Payload: [String gtuId, DirectedPoint position, Speed speed, Acceleration acceleration, TurnIndicatorStatus
207 * turnIndicatorStatus, Length odometer, Lane referenceLane, Length positionOnReferenceLane, GTUDirectionality direction]
208 */
209 EventType LANEBASED_MOVE_EVENT = new EventType("LANEBASEDGTU.MOVE");
210
211 /**
212 * The lane-based event type for pub/sub indicating destruction of the GTU. <br>
213 * Payload: [String gtuId, DirectedPoint lastPosition, Length odometer, Lane referenceLane, Length positionOnReferenceLane,
214 * GTUDirectionality direction]
215 */
216 EventType LANEBASED_DESTROY_EVENT = new EventType("LANEBASEDGTU.DESTROY");
217
218 /**
219 * The event type for pub/sub indicating that the GTU entered a new link (with the FRONT position if driving forward; REAR
220 * if driving backward). <br>
221 * Payload: [String gtuId, Link link]
222 */
223 EventType LINK_ENTER_EVENT = new EventType("LINK.ENTER");
224
225 /**
226 * The event type for pub/sub indicating that the GTU exited a link (with the REAR position if driving forward; FRONT if
227 * driving backward). <br>
228 * Payload: [String gtuId, Link link]
229 */
230 EventType LINK_EXIT_EVENT = new EventType("LINK.EXIT");
231
232 /**
233 * The event type for pub/sub indicating that the GTU entered a new lane (with the FRONT position if driving forward; REAR
234 * if driving backward). <br>
235 * Payload: [String gtuId, Lane lane]
236 */
237 EventType LANE_ENTER_EVENT = new EventType("LANE.ENTER");
238
239 /**
240 * The event type for pub/sub indicating that the GTU exited a lane (with the REAR position if driving forward; FRONT if
241 * driving backward). <br>
242 * Payload: [String gtuId, Lane lane]
243 */
244 EventType LANE_EXIT_EVENT = new EventType("LANE.EXIT");
245
246 }