Class TrafficLight
java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.core.object.StaticObject
org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject
org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLight
- All Implemented Interfaces:
nl.tudelft.simulation.dsol.animation.Locatable,Identifiable,EventProducer,OtsShape,LocatedObject,LaneBasedObject
Standard implementation of a traffic light.
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, Wouter Schakel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LengthDefault elevation of a traffic light (above zero; don't use this for lanes at non-zero elevation).static final EventTypeThe timed event type for pub/sub indicating the change of color of a traffic light.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
ConstructorsConstructorDescriptionTrafficLight(String id, Lane lane, Length longitudinalPosition) Construct an AbstractTrafficLight at default elevation (use only on roads at elevation 0).TrafficLight(String id, Lane lane, Length longitudinalPosition, Length height) Construct an AbstractTrafficLight with specified elevation. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTurnOnRed(Node node) Add node GTUs may turn to through red.booleancanTurnOnRed(Route route, GtuType gtuType) Whether a GTU can turn on red.final TrafficLightColorGet the current traffic light color.final TrafficLightColorgetTrafficLightColor(Duration time) Get the traffic light color in the past.final voidsetTrafficLightColor(TrafficLightColor trafficLightColor) Set the new traffic light color.toString()Methods inherited from class org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject
getFullId, getLane, getLine, getLongitudinalPosition, initMethods inherited from class org.opentrafficsim.core.object.StaticObject
create, create, getAbsoluteContour, getHeight, getId, getLocation, getRelativeBounds, getRelativeContourMethods inherited from class org.djutils.event.LocalEventProducer
getEventListenerMapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from interface org.djutils.base.Identifiable
getIdMethods inherited from interface org.opentrafficsim.road.network.lane.object.LaneBasedObject
getLength, getLocation, getSimulatorMethods inherited from interface nl.tudelft.simulation.dsol.animation.Locatable
getZMethods inherited from interface org.opentrafficsim.core.object.LocatedObject
getHeightMethods inherited from interface org.opentrafficsim.base.geometry.OtsShape
contains, contains, getAbsoluteBounds, getAbsoluteContour, getAbsoluteContour, getDirZ, getRelativeBounds, getRelativeContour, signedDistance, signedDistance
-
Field Details
-
DEFAULT_TRAFFICLIGHT_ELEVATION
Default elevation of a traffic light (above zero; don't use this for lanes at non-zero elevation). -
TRAFFICLIGHT_CHANGE_EVENT
The timed event type for pub/sub indicating the change of color of a traffic light.
Payload: Object[] {String trafficLightId, TrafficLight trafficLight, TrafficLightColor newColor}
-
-
Constructor Details
-
TrafficLight
public TrafficLight(String id, Lane lane, Length longitudinalPosition, Length height) throws NetworkException Construct an AbstractTrafficLight with specified elevation.- Parameters:
id- traffic light idlane- lane where the traffic light is locatedlongitudinalPosition- position of the traffic light on the lane, in the design directionheight- the elevation of the traffic light- Throws:
NetworkException- on failure to place the object
-
TrafficLight
Construct an AbstractTrafficLight at default elevation (use only on roads at elevation 0).- Parameters:
id- traffic light idlane- lane where the traffic light is locatedlongitudinalPosition- position of the traffic light on the lane, in the design direction- Throws:
NetworkException- on failure to place the object
-
-
Method Details
-
getTrafficLightColor
Get the current traffic light color.- Returns:
- current traffic light color.
-
getTrafficLightColor
Get the traffic light color in the past.- Parameters:
time- simulation time to obtain traffic light color.- Returns:
- current traffic light color.
-
setTrafficLightColor
Set the new traffic light color.- Parameters:
trafficLightColor- set the trafficLightColor
-
addTurnOnRed
Add node GTUs may turn to through red.- Parameters:
node- node.
-
canTurnOnRed
Whether a GTU can turn on red.- Parameters:
route- route.gtuType- GTU type.- Returns:
- whether a GTU can turn on red.
-
toString
- Overrides:
toStringin classAbstractLaneBasedObject
-