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