View Javadoc
1   package org.opentrafficsim.core.gtu;
2   
3   import java.io.Serializable;
4   import java.util.Set;
5   
6   import org.djunits.value.vdouble.scalar.Acceleration;
7   import org.djunits.value.vdouble.scalar.Direction;
8   import org.djunits.value.vdouble.scalar.Length;
9   import org.djunits.value.vdouble.scalar.Speed;
10  import org.djunits.value.vdouble.scalar.Time;
11  import org.djunits.value.vdouble.vector.PositionVector;
12  import org.djutils.event.EventProducerInterface;
13  import org.djutils.event.TimedEventType;
14  import org.djutils.immutablecollections.ImmutableMap;
15  import org.djutils.immutablecollections.ImmutableSet;
16  import org.djutils.metadata.MetaData;
17  import org.djutils.metadata.ObjectDescriptor;
18  import org.opentrafficsim.base.Identifiable;
19  import org.opentrafficsim.base.parameters.Parameters;
20  import org.opentrafficsim.core.animation.Drawable;
21  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
22  import org.opentrafficsim.core.geometry.DirectedPoint;
23  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
24  import org.opentrafficsim.core.gtu.plan.strategical.StrategicalPlanner;
25  import org.opentrafficsim.core.gtu.plan.tactical.TacticalPlanner;
26  import org.opentrafficsim.core.perception.PerceivableContext;
27  
28  import nl.tudelft.simulation.dsol.animation.Locatable;
29  
30  /**
31   * Generalized Travel Unit. <br>
32   * A GTU is an object (person, car, ship) that can travel over the infrastructure. It has a (directed) location, dimensions, and
33   * some properties that all GTUs share. The GTU is not bound to any infrastructure and can travel freely in the world. <br>
34   * For its movement, a GTU uses an OperationalPlan, which indicates a shape in the world with a speed profile that the GTU will
35   * use to move. The OperationalPlan can be updated or replaced, for which a tactical planner is responsible. A tactical plan can
36   * for instance be for a car to change two lanes to the left during the next 200 m to be able to make a left turn in 200 m. The
37   * operational plans are then the implementation of segments of the movement (time, location, speed, acceleration) that the car
38   * will make to drive on the road and (safely) make the lane changes. On the highest level, a StrategicPlan puts boundary
39   * conditions on the tactical plans. The strategic plan contains for instance the destination we want to reach and possibly some
40   * constraints on solutions that the tactical plans have to comply with.
41   * <p>
42   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
43   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
44   * <p>
45   * @version $Revision$, $LastChangedDate$, by $Author$,
46   *          initial version May 15, 2014 <br>
47   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
48   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
49   */
50  public interface GTU extends Locatable, Serializable, EventProducerInterface, Identifiable, Drawable
51  {
52      /** @return the id of the GTU */
53      @Override
54      String getId();
55  
56      /** {@inheritDoc} */
57      @Override
58      DirectedPoint getLocation();
59  
60      /** @return the context to which the GTU belongs */
61      PerceivableContext getPerceivableContext();
62  
63      /** @return the maximum length of the GTU (parallel with driving direction). */
64      Length getLength();
65  
66      /** @return the maximum width of the GTU (perpendicular to driving direction). */
67      Length getWidth();
68  
69      /** @return the maximum speed of the GTU, in the direction of movement. */
70      Speed getMaximumSpeed();
71  
72      /** @return the maximum acceleration of the GTU, in the linear direction. */
73      Acceleration getMaximumAcceleration();
74  
75      /** @return the maximum deceleration of the GTU, in the linear direction, stored as a negative number. */
76      Acceleration getMaximumDeceleration();
77  
78      /** @return the type of GTU, e.g. TruckType, CarType, BusType. */
79      GTUType getGTUType();
80  
81      /** @return the simulator of the GTU. */
82      OTSSimulatorInterface getSimulator();
83  
84      /** @return the reference position of the GTU, by definition (0, 0, 0). */
85      RelativePosition getReference();
86  
87      /** @return the front position of the GTU, relative to its reference point. */
88      RelativePosition getFront();
89  
90      /** @return the rear position of the GTU, relative to its reference point. */
91      RelativePosition getRear();
92  
93      /** @return the center position of the GTU, relative to its reference point. */
94      RelativePosition getCenter();
95  
96      /** @return the contour points of the GTU. */
97      ImmutableSet<RelativePosition> getContourPoints();
98  
99      /** @return the positions for this GTU, but not the contour points. */
100     ImmutableMap<RelativePosition.TYPE, RelativePosition> getRelativePositions();
101 
102     /** @return the current speed of the GTU, along the direction of movement. */
103     Speed getSpeed();
104 
105     /**
106      * @param time Time; time at which to obtain the speed
107      * @return the current speed of the GTU, along the direction of movement.
108      */
109     Speed getSpeed(Time time);
110 
111     /** @return the current acceleration of the GTU, along the direction of movement. */
112     Acceleration getAcceleration();
113 
114     /**
115      * @param time Time; time at which to obtain the acceleration
116      * @return the current acceleration of the GTU, along the direction of movement.
117      */
118     Acceleration getAcceleration(Time time);
119 
120     /**
121      * @return Length; the current odometer value.
122      */
123     Length getOdometer();
124 
125     /**
126      * @param time Time; time to obtain the odometer at
127      * @return Length; the odometer value at given time.
128      */
129     Length getOdometer(Time time);
130 
131     /** @return Parameters. */
132     Parameters getParameters();
133 
134     /** @param parameters Parameters; parameters */
135     void setParameters(Parameters parameters);
136 
137     /**
138      * @return StrategicalPlanner; the planner responsible for the overall 'mission' of the GTU, usually indicating where it
139      *         needs to go. It operates by instantiating tactical planners to do the work.
140      */
141     StrategicalPlanner getStrategicalPlanner();
142 
143     /**
144      * @param time Time; time to obtain the strategical planner at
145      * @return StrategicalPlanner; the planner responsible for the overall 'mission' of the GTU, usually indicating where it
146      *         needs to go. It operates by instantiating tactical planners to do the work.
147      */
148     StrategicalPlanner getStrategicalPlanner(Time time);
149 
150     /** @return TacticalPlanner; the current tactical planner that can generate an operational plan */
151     default TacticalPlanner<?, ?> getTacticalPlanner()
152     {
153         return getStrategicalPlanner().getTacticalPlanner();
154     }
155 
156     /**
157      * @param time Time; time to obtain the tactical planner at
158      * @return TacticalPlanner; the tactical planner that can generate an operational plan at the given time
159      */
160     default TacticalPlanner<?, ?> getTacticalPlanner(final Time time)
161     {
162         return getStrategicalPlanner(time).getTacticalPlanner(time);
163     }
164 
165     /** @return the current operational plan for the GTU */
166     OperationalPlan getOperationalPlan();
167 
168     /**
169      * @param time Time; time to obtain the operational plan at
170      * @return the operational plan for the GTU at the given time.
171      */
172     OperationalPlan getOperationalPlan(Time time);
173 
174     /** Destroy the GTU from the simulation and animation. */
175     void destroy();
176 
177     /**
178      * Returns whether the GTU is destroyed.
179      * @return whether the GTU is destroyed
180      */
181     boolean isDestroyed();
182 
183     /**
184      * Adds the provided GTU to this GTU, meaning it moves with this GTU.
185      * @param gtu GTU; gtu to enter this GTU
186      * @throws GTUException if the gtu already has a parent
187      */
188     void addGtu(GTU gtu) throws GTUException;
189 
190     /**
191      * Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.
192      * @param gtu GTU; gtu to exit this GTU
193      */
194     void removeGtu(GTU gtu);
195 
196     /**
197      * Set the parent GTU.
198      * @param gtu GTU; parent GTU, may be {@code null}
199      * @throws GTUException if the gtu already has a parent
200      */
201     void setParent(GTU gtu) throws GTUException;
202 
203     /**
204      * Returns the parent GTU, or {@code null} if this GTU has no parent.
205      * @return GTU; parent GTU, or {@code null} if this GTU has no parent
206      */
207     GTU getParent();
208 
209     /**
210      * Returns the children GTU's.
211      * @return Set&lt;GTU&gt;; children GTU's
212      */
213     Set<GTU> getChildren();
214 
215     /**
216      * Sets the error handler.
217      * @param errorHandler GTUErrorHandler; error handler
218      */
219     void setErrorHandler(GTUErrorHandler errorHandler);
220 
221     /**
222      * The event type for pub/sub indicating the initialization of a new GTU. <br>
223      * Payload: [String id, PositionVector initialPosition, Direction initialDirection, Length length, Length width]
224      */
225     TimedEventType INIT_EVENT = new TimedEventType("GTU.INIT",
226             new MetaData("GTU init", "GTU id, initial position and size",
227                     new ObjectDescriptor[] { new ObjectDescriptor("Id", "GTU Id", String.class),
228                             new ObjectDescriptor("initial position", "initial position", PositionVector.class),
229                             new ObjectDescriptor("initial direction", "initial direction", Direction.class),
230                             new ObjectDescriptor("Length", "Length", Length.class),
231                             new ObjectDescriptor("Width", "Width", Length.class) }));
232 
233     /**
234      * The event type for pub/sub indicating a move. <br>
235      * Payload: [String id, DirectedPoint position, Speed speed, Acceleration acceleration, Length odometer]
236      */
237     TimedEventType MOVE_EVENT = new TimedEventType("GTU.MOVE",
238             new MetaData("GTU move", "GTU id, position, speed, acceleration, odometer",
239                     new ObjectDescriptor[] { new ObjectDescriptor("Id", "GTU Id", String.class),
240                             new ObjectDescriptor("position", "position", PositionVector.class),
241                             new ObjectDescriptor("direction", "direction", Direction.class),
242                             new ObjectDescriptor("speed", "speed", Speed.class),
243                             new ObjectDescriptor("acceleration", "acceleration", Acceleration.class),
244                             new ObjectDescriptor("Odometer", "Total distance travelled since incarnation", Length.class) }));
245 
246     /**
247      * The event type for pub/sub indicating destruction of the GTU. <br>
248      * Payload: [String id, DirectedPoint lastPosition, Length odometer]
249      */
250     TimedEventType DESTROY_EVENT = new TimedEventType("GTU.DESTROY",
251             new MetaData("GTU destroy", "GTU id, final position, final odometer",
252                     new ObjectDescriptor[] { new ObjectDescriptor("Id", "GTU Id", String.class),
253                             new ObjectDescriptor("position", "position", PositionVector.class),
254                             new ObjectDescriptor("direction", "direction", Direction.class),
255                             new ObjectDescriptor("Odometer", "Total distance travelled since incarnation", Length.class) }));
256 
257 }