Package org.opentrafficsim.core.gtu
Class Gtu
java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.core.gtu.Gtu
- All Implemented Interfaces:
Serializable,Remote,nl.tudelft.simulation.dsol.animation.Locatable,org.djutils.base.Identifiable,org.djutils.event.EventProducer,DynamicSpatialObject,OtsLocatable,SpatialObject,HierarchicallyTyped<GtuType,Gtu>
public class Gtu
extends org.djutils.event.LocalEventProducer
implements HierarchicallyTyped<GtuType,Gtu>, DynamicSpatialObject, OtsLocatable, Serializable, org.djutils.base.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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intaligned schedule count.static booleanaligned or not.static org.djutils.event.EventTypeThe event type for pub/sub indicating destruction of the GTU.static org.djutils.event.EventTypeThe event type for pub/sub indicating a move.Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION -
Constructor Summary
ConstructorsConstructorDescriptionGtu(String id, GtuType gtuType, OtsSimulatorInterface simulator, PerceivableContext perceivableContext, org.djunits.value.vdouble.scalar.Length length, org.djunits.value.vdouble.scalar.Length width, org.djunits.value.vdouble.scalar.Speed maximumSpeed, org.djunits.value.vdouble.scalar.Length front, org.djunits.value.vdouble.scalar.Length centerOfGravity) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the provided GTU to this GTU, meaning it moves with this GTU.voiddestroy()Destructor.booleanfinal org.djunits.value.vdouble.scalar.Accelerationfinal org.djunits.value.vdouble.scalar.AccelerationgetAcceleration(org.djunits.value.vdouble.scalar.Time time) final org.djutils.draw.bounds.Bounds2dfinal RelativePositionReturns the children GTU's.org.djutils.draw.line.Polygon2dReturn the shape of the GTU for the validity time of the operational plan.org.djutils.draw.line.Polygon2dgetContour(org.djunits.value.vdouble.scalar.Time time) Return the shape of a dynamic object at time 'time'.protected GtuErrorHandlerfinal RelativePositiongetFront()final StringgetId()final org.djunits.value.vdouble.scalar.Lengthorg.djutils.draw.point.OrientedPoint2dfinal org.djunits.value.vdouble.scalar.Accelerationfinal org.djunits.value.vdouble.scalar.Accelerationfinal org.djunits.value.vdouble.scalar.Speedfinal nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent<org.djunits.value.vdouble.scalar.Duration>Note that destroying the next move event of the GTU can be dangerous!final org.djunits.value.vdouble.scalar.Lengthfinal org.djunits.value.vdouble.scalar.LengthgetOdometer(org.djunits.value.vdouble.scalar.Time time) final OperationalPlanfinal OperationalPlangetOperationalPlan(org.djunits.value.vdouble.scalar.Time time) final ParametersReturns the parent GTU, ornullif this GTU has no parent.final RelativePositiongetRear()final RelativePositionfinal org.djutils.immutablecollections.ImmutableMap<RelativePosition.Type,RelativePosition> getShape()final OtsSimulatorInterfacefinal org.djunits.value.vdouble.scalar.SpeedgetSpeed()final org.djunits.value.vdouble.scalar.SpeedgetSpeed(org.djunits.value.vdouble.scalar.Time time) getStrategicalPlanner(org.djunits.value.vdouble.scalar.Time time) TacticalPlanner<?,?> TacticalPlanner<?,?> getTacticalPlanner(org.djunits.value.vdouble.scalar.Time time) Returns the value for the given tag, these are used for specific use cases of any sort.getType()final org.djunits.value.vdouble.scalar.LengthgetWidth()inthashCode()voidinit(StrategicalPlanner strategicalPlanner, org.djutils.draw.point.OrientedPoint2d initialLocation, org.djunits.value.vdouble.scalar.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(org.djutils.draw.point.OrientedPoint2d 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.voidsetErrorHandler(GtuErrorHandler errorHandler) Sets the error handler.final voidsetMaximumAcceleration(org.djunits.value.vdouble.scalar.Acceleration maximumAcceleration) final voidsetMaximumDeceleration(org.djunits.value.vdouble.scalar.Acceleration maximumDeceleration) Set the maximum deceleration.protected voidsetOperationalPlan(OperationalPlan operationalPlan) Set the operational plan.final voidsetParameters(Parameters parameters) voidSet the parent GTU.voidSets a tag, these are used for specific use cases of any sort.Methods inherited from class org.djutils.event.LocalEventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opentrafficsim.base.HierarchicallyTyped
isOfTypeMethods inherited from interface nl.tudelft.simulation.dsol.animation.Locatable
getDirZ, getZ
-
Field Details
-
ALIGNED
public static boolean ALIGNEDaligned or not. -
ALIGN_COUNT
public static int ALIGN_COUNTaligned schedule count. -
MOVE_EVENT
public static org.djutils.event.EventType MOVE_EVENTThe event type for pub/sub indicating a move.
Payload: [String id, DirectedPoint position, Speed speed, Acceleration acceleration, Length odometer] -
DESTROY_EVENT
public static org.djutils.event.EventType DESTROY_EVENTThe 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, org.djunits.value.vdouble.scalar.Length length, org.djunits.value.vdouble.scalar.Length width, org.djunits.value.vdouble.scalar.Speed maximumSpeed, org.djunits.value.vdouble.scalar.Length front, org.djunits.value.vdouble.scalar.Length centerOfGravity) throws GtuException - 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 registeredlength- the maximum length of the GTU (parallel with driving direction)width- the maximum width of the GTU (perpendicular to driving direction)maximumSpeed- Speed;the maximum speed of the GTU (in the driving direction)front- front distance relative to the reference positioncenterOfGravity- distance from the center of gravity to the reference position- Throws:
GtuException- when the preconditions of the constructor are not met
-
-
Method Details
-
init
public void init(StrategicalPlanner strategicalPlanner, org.djutils.draw.point.OrientedPoint2d initialLocation, org.djunits.value.vdouble.scalar.Speed initialSpeed) throws nl.tudelft.simulation.dsol.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:
nl.tudelft.simulation.dsol.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
- Returns:
- the front position of the GTU, relative to its reference point.
-
getRear
- Returns:
- the rear position of the GTU, relative to its reference point.
-
getCenter
- Returns:
- the center position of the GTU, relative to its reference point.
-
getRelativePositions
public final org.djutils.immutablecollections.ImmutableMap<RelativePosition.Type,RelativePosition> getRelativePositions()- Returns:
- the positions for this GTU, but not the contour points.
-
getLength
public final org.djunits.value.vdouble.scalar.Length getLength()- Returns:
- the maximum length of the GTU (parallel with driving direction).
-
getWidth
public final org.djunits.value.vdouble.scalar.Length getWidth()- Returns:
- the maximum width of the GTU (perpendicular to driving direction).
-
getMaximumSpeed
public final org.djunits.value.vdouble.scalar.Speed getMaximumSpeed()- Returns:
- the maximum speed of the GTU, in the direction of movement.
-
getBounds
public final org.djutils.draw.bounds.Bounds2d getBounds()- Specified by:
getBoundsin interfacenl.tudelft.simulation.dsol.animation.Locatable- Specified by:
getBoundsin interfaceOtsLocatable
-
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(org.djutils.draw.point.OrientedPoint2d fromLocation) throws nl.tudelft.simulation.dsol.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:
nl.tudelft.simulation.dsol.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 nl.tudelft.simulation.dsol.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:
nl.tudelft.simulation.dsol.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 interfaceorg.djutils.base.Identifiable- Returns:
- the id of the GTU
-
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, or
nullif it is not given to the GTU.
-
getType
- Specified by:
getTypein interfaceHierarchicallyTyped<GtuType,Gtu>
-
getReference
- Returns:
- the reference position of the GTU, by definition (0, 0, 0).
-
getSimulator
- Returns:
- the simulator of the GTU.
-
getParameters
- Returns:
- Parameters.
-
setParameters
- Parameters:
parameters- parameters
-
getStrategicalPlanner
- 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
- Parameters:
time- 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
- Returns:
- the current tactical planner that can generate an operational plan
-
getTacticalPlanner
- Parameters:
time- time to obtain the tactical planner at- Returns:
- the tactical planner that can generate an operational plan at the given time
-
getOperationalPlan
- Returns:
- the current operational plan for the GTU
-
getOperationalPlan
- Parameters:
time- 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
public final org.djunits.value.vdouble.scalar.Length getOdometer()- Returns:
- the current odometer value.
-
getOdometer
public final org.djunits.value.vdouble.scalar.Length getOdometer(org.djunits.value.vdouble.scalar.Time time) - Parameters:
time- time to obtain the odometer at- Returns:
- the odometer value at given time.
-
getSpeed
public final org.djunits.value.vdouble.scalar.Speed getSpeed()- Returns:
- the current speed of the GTU, along the direction of movement.
-
getSpeed
public final org.djunits.value.vdouble.scalar.Speed getSpeed(org.djunits.value.vdouble.scalar.Time time) - Parameters:
time- time at which to obtain the speed- Returns:
- the current speed of the GTU, along the direction of movement.
-
getAcceleration
public final org.djunits.value.vdouble.scalar.Acceleration getAcceleration()- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getAcceleration
public final org.djunits.value.vdouble.scalar.Acceleration getAcceleration(org.djunits.value.vdouble.scalar.Time time) - Parameters:
time- time at which to obtain the acceleration- Returns:
- the current acceleration of the GTU, along the direction of movement.
-
getMaximumAcceleration
public final org.djunits.value.vdouble.scalar.Acceleration getMaximumAcceleration()- Returns:
- maximumAcceleration
-
setMaximumAcceleration
public final void setMaximumAcceleration(org.djunits.value.vdouble.scalar.Acceleration maximumAcceleration) - Parameters:
maximumAcceleration- set maximumAcceleration
-
getMaximumDeceleration
public final org.djunits.value.vdouble.scalar.Acceleration getMaximumDeceleration()- Returns:
- maximumDeceleration
-
setMaximumDeceleration
public final void setMaximumDeceleration(org.djunits.value.vdouble.scalar.Acceleration maximumDeceleration) Set the maximum deceleration.- Parameters:
maximumDeceleration- set maximumDeceleration, must be a negative number
-
getLocation
public org.djutils.draw.point.OrientedPoint2d getLocation()- Specified by:
getLocationin interfacenl.tudelft.simulation.dsol.animation.Locatable- Specified by:
getLocationin interfaceOtsLocatable
-
getContour
public org.djutils.draw.line.Polygon2d getContour(org.djunits.value.vdouble.scalar.Time time) 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:
getContourin interfaceDynamicSpatialObject- Parameters:
time- the time for which we want the shape- Returns:
- the shape of the object at time 'time'
-
getContour
public org.djutils.draw.line.Polygon2d getContour()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:
getContourin interfaceSpatialObject- Returns:
- the shape of the object over the validity of the operational plan
-
getShape
- Specified by:
getShapein interfaceOtsLocatable
-
isDestroyed
public final boolean isDestroyed()Returns whether the GTU is destroyed.- Returns:
- whether the GTU is destroyed
-
getPerceivableContext
- 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, or
nullif this GTU has no parent
-
getChildren
Returns the children GTU's.- Returns:
- children GTU's
-
getErrorHandler
- Returns:
- errorHandler.
-
setErrorHandler
Sets the error handler.- Parameters:
errorHandler- error handler
-
getNextMoveEvent
public final nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEvent<org.djunits.value.vdouble.scalar.Duration> 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
-