Package org.opentrafficsim.core.gtu
Class Gtu
java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.core.gtu.Gtu
- All Implemented Interfaces:
Locatable,Identifiable,EventProducer,OtsShape,HierarchicallyTyped<GtuType,Gtu>
public class Gtu
extends LocalEventProducer
implements HierarchicallyTyped<GtuType,Gtu>, OtsShape, Identifiable
Implements the basic functionalities of any GTU: the ability to move on 3D-space according to a plan.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EventTypeThe event type for pub/sub indicating destruction of the GTU.static final EventTypeThe event type for pub/sub indicating a move.Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITIONFields inherited from interface org.opentrafficsim.base.geometry.OtsShape
DEFAULT_POLYGON_SEGMENTS, WORLD_MARGIN_LINE -
Constructor Summary
ConstructorsConstructorDescriptionGtu(String id, GtuType gtuType, OtsSimulatorInterface simulator, PerceivableContext perceivableContext, Length length, Length width, Length front, Speed maximumSpeed) Constructor using length, width and front.Gtu(String id, GtuType gtuType, OtsSimulatorInterface simulator, PerceivableContext perceivableContext, Polygon2d contour, Speed maximumSpeed) Constructor using contour. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the provided GTU to this GTU, meaning it moves with this GTU.voiddestroy()Destructor.booleanReturn the shape of the GTU for the validity time of the operational plan.getAbsoluteContour(Duration time) Return the shape of a dynamic object at time 'time'.final AccelerationGet acceleration.final AccelerationgetAcceleration(Duration time) Get acceleration at time.doubleReturns the align step.final RelativePositionGet center.Returns the children GTU's.protected GtuErrorHandlerGet error handler.final RelativePositiongetFront()Get front.final StringgetId()final LengthGet length.getLocation(Duration time) Returns the location of the GTU at the given time.final AccelerationGet maximum acceleration.final AccelerationGet maximum deceleration.final SpeedGet maximum speed.final SimEventInterface<Duration>Note that destroying the next move event of the GTU can be dangerous!final LengthGet odometer.final LengthgetOdometer(Duration time) Get odometer at time.final OperationalPlanGet operational plan.final OperationalPlangetOperationalPlan(Duration time) Get operational plan at time.final ParametersGet parameters.Returns the parent GTU, ornullif this GTU has no parent.Return perceivable context.final RelativePositiongetRear()Get rear.final RelativePositionGet reference.final Bounds2dGet relative positions.final OtsSimulatorInterfaceGet simulator.final SpeedgetSpeed()Get speed.final SpeedGet speed at time.Get strategical planner.Get strategical planner at time.TacticalPlanner<?,?> Get tactical planner.TacticalPlanner<?,?> getTacticalPlanner(Duration time) Get tactical planner at time.Returns the value for the given tag, these are used for specific use cases of any sort.getType()final LengthgetWidth()Get width.inthashCode()voidinit(StrategicalPlanner strategicalPlanner, DirectedPoint2d initialLocation, Speed initialSpeed) Initialize the GTU at a location and speed, and give it a mission to fulfill through the strategical planner.protected voidInterrupt the move and ask for a new plan.final booleanReturns whether the GTU is destroyed.protected booleanmove(DirectedPoint2d fromLocation) Move from the current location according to an operational plan to a location that will bring us nearer to reaching the location provided by the strategical planner.voidRemoves the provided GTU from this GTU, meaning it no longer moves with this GTU.voidsetAlignStep(double alignStep) Set align step, use NaN to not align.voidsetErrorHandler(GtuErrorHandler errorHandler) Sets the error handler.final voidsetMaximumAcceleration(Acceleration maximumAcceleration) Set maximum deceleration.final voidsetMaximumDeceleration(Acceleration maximumDeceleration) Set the maximum deceleration.protected voidsetOperationalPlan(OperationalPlan operationalPlan) Set the operational plan.final voidsetParameters(Parameters parameters) Set parameters.voidSet the parent GTU.voidSets a tag, these are used for specific use cases of any sort.doublesignedDistance(Point2d point) Methods inherited from class org.djutils.event.LocalEventProducer
getEventListenerMapMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from interface org.opentrafficsim.base.HierarchicallyTyped
isOfTypeMethods inherited from interface org.opentrafficsim.base.geometry.OtsShape
contains, contains, getAbsoluteBounds, getDirZ, signedDistance
-
Field Details
-
MOVE_EVENT
The event type for pub/sub indicating a move.
Payload: [String id, DirectedPoint position, Speed speed, Acceleration acceleration, Length odometer] -
DESTROY_EVENT
The event type for pub/sub indicating destruction of the GTU.
Payload: [String id, DirectedPoint lastPosition, Length odometer]
-
-
Constructor Details
-
Gtu
public Gtu(String id, GtuType gtuType, OtsSimulatorInterface simulator, PerceivableContext perceivableContext, Polygon2d contour, Speed maximumSpeed) throws GtuException Constructor using contour.- Parameters:
id- the id of the GTUgtuType- the type of GTU, e.g. TruckType, CarType, BusTypesimulator- the simulator to schedule plan changes onperceivableContext- the perceivable context in which this GTU will be registeredcontour- contour relative to reference positionmaximumSpeed- the maximum speed of the GTU (in the driving direction)- Throws:
GtuException- when id already exists in the contextNullPointerException- when any input is null
-
Gtu
public Gtu(String id, GtuType gtuType, OtsSimulatorInterface simulator, PerceivableContext perceivableContext, Length length, Length width, Length front, Speed maximumSpeed) throws GtuException Constructor using length, width and front.- Parameters:
id- the id of the GTUgtuType- the type of GTU, e.g. NL.CAR or NL.TRUCKsimulator- the simulator to schedule plan changes onperceivableContext- the perceivable context in which this GTU will be registeredlength- the maximum length of the GTU (parallel with driving direction)width- the maximum width of the GTU (perpendicular to driving direction)front- front distance relative to the reference positionmaximumSpeed- the maximum speed of the GTU (in the driving direction)- Throws:
GtuException- when id already exists in the contextNullPointerException- when any input is null
-
-
Method Details
-
init
public void init(StrategicalPlanner strategicalPlanner, DirectedPoint2d initialLocation, Speed initialSpeed) throws SimRuntimeException, GtuException Initialize the GTU at a location and speed, and give it a mission to fulfill through the strategical planner.- Parameters:
strategicalPlanner- the strategical planner responsible for the overall 'mission' of the GTU, usually indicating where it needs to go. It operates by instantiating tactical planners to do the work.initialLocation- the initial location (and direction) of the GTUinitialSpeed- the initial speed of the GTU- Throws:
SimRuntimeException- when scheduling after the first move failsGtuException- when the preconditions of the parameters are not met or when the construction of the original waiting path fails
-
getFront
Get front.- Returns:
- the front position of the GTU, relative to its reference point.
-
getRear
Get rear.- Returns:
- the rear position of the GTU, relative to its reference point.
-
getCenter
Get center.- Returns:
- the center position of the GTU, relative to its reference point.
-
getRelativePositions
Get relative positions.- Returns:
- the positions for this GTU, but not the contour points.
-
getLength
Get length.- Returns:
- the maximum length of the GTU (parallel with driving direction).
-
getWidth
Get width.- Returns:
- the maximum width of the GTU (perpendicular to driving direction).
-
getMaximumSpeed
Get maximum speed.- Returns:
- the maximum speed of the GTU, in the direction of movement.
-
getRelativeBounds
- Specified by:
getRelativeBoundsin interfaceLocatable- Specified by:
getRelativeBoundsin interfaceOtsShape
-
destroy
public void destroy()Destructor. Don't forget to call with super.destroy() from any override to avoid memory leaks in the network. -
move
protected boolean move(DirectedPoint2d fromLocation) throws SimRuntimeException, GtuException, NetworkException, ParameterException Move from the current location according to an operational plan to a location that will bring us nearer to reaching the location provided by the strategical planner.
This method can be overridden to carry out specific behavior during the execution of the plan (e.g., scheduling of triggers, entering or leaving lanes, etc.). Please bear in mind that the call to super.move() is essential, and that one has to take care to handle the situation that the plan gets interrupted.- Parameters:
fromLocation- the last known location (initial location, or end location of the previous operational plan)- Returns:
- whether an exception occurred
- Throws:
SimRuntimeException- when scheduling of the next move failsGtuException- when there is a problem with the state of the GTU when planning a pathNetworkException- in case of a problem with the network, e.g., a dead end where it is not expectedParameterException- in there is a parameter problem
-
interruptMove
protected void interruptMove() throws SimRuntimeException, GtuException, NetworkException, ParameterExceptionInterrupt the move and ask for a new plan. This method can be overridden to carry out the bookkeeping needed when the current plan gets interrupted.- Throws:
SimRuntimeException- when scheduling of the next move failsGtuException- when there is a problem with the state of the GTU when planning a pathNetworkException- in case of a problem with the network, e.g., unreachability of a certain pointParameterException- when there is a problem with a parameter
-
getId
- Specified by:
getIdin interfaceIdentifiable
-
setTag
Sets a tag, these are used for specific use cases of any sort.- Parameters:
tag- name of the tag.value- value of the tag.
-
getTag
Returns the value for the given tag, these are used for specific use cases of any sort.- Parameters:
tag- name of the tag.- Returns:
- value of the tag, empty if it is not given to the GTU.
-
getType
- Specified by:
getTypein interfaceHierarchicallyTyped<GtuType,Gtu>
-
getReference
Get reference.- Returns:
- the reference position of the GTU, by definition (0, 0, 0).
-
getSimulator
Get simulator.- Returns:
- the simulator of the GTU.
-
getParameters
Get parameters.- Returns:
- Parameters.
-
setParameters
Set parameters. This method clears any existing parameter history and should normally only be invoked for initialization.- Parameters:
parameters- parameters
-
getStrategicalPlanner
Get strategical planner.- Returns:
- the planner responsible for the overall 'mission' of the GTU, usually indicating where it needs to go. It operates by instantiating tactical planners to do the work.
-
getStrategicalPlanner
Get strategical planner at time.- Parameters:
time- simulation time to obtain the strategical planner at- Returns:
- the planner responsible for the overall 'mission' of the GTU, usually indicating where it needs to go. It operates by instantiating tactical planners to do the work.
-
getTacticalPlanner
Get tactical planner.- Returns:
- the current tactical planner that can generate an operational plan
-
getTacticalPlanner
Get tactical planner at time.- Parameters:
time- simulation time to obtain the tactical planner at- Returns:
- the tactical planner that can generate an operational plan at the given time
-
getOperationalPlan
Get operational plan.- Returns:
- the current operational plan for the GTU
-
getOperationalPlan
Get operational plan at time.- Parameters:
time- simulation time to obtain the operational plan at- Returns:
- the operational plan for the GTU at the given time.
-
setOperationalPlan
Set the operational plan. This method is for sub classes.- Parameters:
operationalPlan- operational plan.
-
getOdometer
Get odometer.- Returns:
- the current odometer value.
-
getOdometer
Get odometer at time.- Parameters:
time- simulation time to obtain the odometer at- Returns:
- the odometer value at given time.
-
getSpeed
Get speed.- Returns:
- the current speed of the GTU, along the direction of movement.
-
getSpeed
Get speed at time.- Parameters:
time- simulation time at which to obtain the speed- Returns:
- the current speed of the GTU, along the direction of movement.
-
getAcceleration
Get acceleration.- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getAcceleration
Get acceleration at time.- Parameters:
time- simulation time at which to obtain the acceleration- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getMaximumAcceleration
Get maximum acceleration.- Returns:
- maximumAcceleration
-
setMaximumAcceleration
Set maximum deceleration.- Parameters:
maximumAcceleration- set maximumAcceleration
-
getMaximumDeceleration
Get maximum deceleration.- Returns:
- maximumDeceleration
-
setMaximumDeceleration
Set the maximum deceleration.- Parameters:
maximumDeceleration- set maximumDeceleration, must be a negative number
-
getLocation
- Specified by:
getLocationin interfaceLocatable- Specified by:
getLocationin interfaceOtsShape
-
getLocation
Returns the location of the GTU at the given time.- Parameters:
time- simulation time- Returns:
- location of the GTU at the given time
-
signedDistance
- Specified by:
signedDistancein interfaceOtsShape
-
getAbsoluteContour
Return the shape of a dynamic object at time 'time'. Note that the getContour() method without a time returns the Minkowski sum of all shapes of the spatial object for a validity time window, e.g., a contour that describes all locations of a GTU for the next time step, i.e., the contour of the GTU belonging to the next operational plan.- Specified by:
getAbsoluteContourin interfaceOtsShape- Parameters:
time- simulation time for which we want the shape- Returns:
- the shape of the object at time 'time'
-
getAbsoluteContour
Return the shape of the GTU for the validity time of the operational plan. Note that this method without a time returns the Minkowski sum of all shapes of the spatial object for a validity time window, e.g., a contour that describes all locations of a GTU for the next time step, i.e., the contour of the GTU belonging to the next operational plan.- Specified by:
getAbsoluteContourin interfaceOtsShape- Returns:
- the shape of the object over the validity of the operational plan
-
getRelativeContour
- Specified by:
getRelativeContourin interfaceOtsShape
-
isDestroyed
public final boolean isDestroyed()Returns whether the GTU is destroyed.- Returns:
- whether the GTU is destroyed
-
getPerceivableContext
Return perceivable context.- Returns:
- the context to which the GTU belongs
-
addGtu
Adds the provided GTU to this GTU, meaning it moves with this GTU.- Parameters:
gtu- gtu to enter this GTU- Throws:
GtuException- if the gtu already has a parent
-
removeGtu
Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.- Parameters:
gtu- gtu to exit this GTU
-
setParent
Set the parent GTU.- Parameters:
gtu- parent GTU, may benull- Throws:
GtuException- if the gtu already has a parent
-
getParent
Returns the parent GTU, ornullif this GTU has no parent.- Returns:
- parent GTU, empty if this GTU has no parent
-
getChildren
Returns the children GTU's.- Returns:
- children GTU's
-
getErrorHandler
Get error handler.- Returns:
- errorHandler.
-
setErrorHandler
Sets the error handler.- Parameters:
errorHandler- error handler
-
getAlignStep
public double getAlignStep()Returns the align step.- Returns:
- align step, NaN if not present
-
setAlignStep
public void setAlignStep(double alignStep) Set align step, use NaN to not align.- Parameters:
alignStep- align step
-
getNextMoveEvent
Note that destroying the next move event of the GTU can be dangerous!- Returns:
- nextMoveEvent the next move event of the GTU, e.g. to cancel it from outside.
-
hashCode
public int hashCode() -
equals
-