java.lang.Object
org.djutils.event.LocalEventProducer
All Implemented Interfaces:
Serializable, Remote, nl.tudelft.simulation.dsol.animation.Locatable, org.djutils.base.Identifiable, org.djutils.event.EventProducer, org.opentrafficsim.base.geometry.OtsLocatable, Drawable, LocatedObject, LaneBasedObject

public class TrafficLight extends AbstractLaneBasedObject
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
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.djunits.value.vdouble.scalar.Length
    Default elevation of a traffic light (above zero; don't use this for lanes at non-zero elevation).
    static final org.djutils.event.EventType
    The 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_POSITION
  • Constructor Summary

    Constructors
    Constructor
    Description
    TrafficLight(String id, Lane lane, org.djunits.value.vdouble.scalar.Length longitudinalPosition, OtsSimulatorInterface simulator)
    Construct an AbstractTrafficLight at default elevation (use only on roads at elevation 0).
    TrafficLight(String id, Lane lane, org.djunits.value.vdouble.scalar.Length longitudinalPosition, OtsSimulatorInterface simulator, org.djunits.value.vdouble.scalar.Length height)
    Construct an AbstractTrafficLight with specified elevation.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add node GTUs may turn to through red.
    boolean
    canTurnOnRed(Route route, GtuType gtuType)
    Whether a GTU can turn on red.
    Get the current traffic light color.
    final void
    Set the new traffic light color.

    Methods inherited from class org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject

    getFullId, getLane, getLongitudinalPosition, init

    Methods inherited from class org.opentrafficsim.core.object.StaticObject

    create, create, getBounds, getGeometry, getHeight, getId, getLocation

    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, removeListener

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods 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, removeListener

    Methods inherited from interface org.djutils.base.Identifiable

    getId

    Methods inherited from interface org.opentrafficsim.road.network.lane.object.LaneBasedObject

    getLength, getLocation

    Methods inherited from interface nl.tudelft.simulation.dsol.animation.Locatable

    getDirZ, getZ

    Methods inherited from interface org.opentrafficsim.core.object.LocatedObject

    getGeometry, getHeight

    Methods inherited from interface org.opentrafficsim.base.geometry.OtsLocatable

    getBounds
  • Field Details

    • DEFAULT_TRAFFICLIGHT_ELEVATION

      public static final org.djunits.value.vdouble.scalar.Length DEFAULT_TRAFFICLIGHT_ELEVATION
      Default elevation of a traffic light (above zero; don't use this for lanes at non-zero elevation).
    • TRAFFICLIGHT_CHANGE_EVENT

      public static final org.djutils.event.EventType 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, org.djunits.value.vdouble.scalar.Length longitudinalPosition, OtsSimulatorInterface simulator, org.djunits.value.vdouble.scalar.Length height) throws NetworkException
      Construct an AbstractTrafficLight with specified elevation.
      Parameters:
      id - String; traffic light id
      lane - Lane; lane where the traffic light is located
      longitudinalPosition - Length; position of the traffic light on the lane, in the design direction
      simulator - OtsSimulatorInterface; the simulator for animation and timed events
      height - Length; the elevation of the traffic light
      Throws:
      NetworkException - on failure to place the object
    • TrafficLight

      public TrafficLight(String id, Lane lane, org.djunits.value.vdouble.scalar.Length longitudinalPosition, OtsSimulatorInterface simulator) throws NetworkException
      Construct an AbstractTrafficLight at default elevation (use only on roads at elevation 0).
      Parameters:
      id - String; traffic light id
      lane - Lane; lane where the traffic light is located
      longitudinalPosition - Length; position of the traffic light on the lane, in the design direction
      simulator - OtsSimulatorInterface; the simulator for animation and timed events
      Throws:
      NetworkException - on failure to place the object
  • Method Details

    • getTrafficLightColor

      public final TrafficLightColor getTrafficLightColor()
      Get the current traffic light color.
      Returns:
      TrafficLightColor; current traffic light color.
    • setTrafficLightColor

      public final void setTrafficLightColor(TrafficLightColor trafficLightColor)
      Set the new traffic light color.
      Parameters:
      trafficLightColor - TrafficLightColor; set the trafficLightColor
    • addTurnOnRed

      public void addTurnOnRed(Node node)
      Add node GTUs may turn to through red.
      Parameters:
      node - Node; node.
    • canTurnOnRed

      public boolean canTurnOnRed(Route route, GtuType gtuType)
      Whether a GTU can turn on red.
      Parameters:
      route - Route; route.
      gtuType - GtuType; GTU type.
      Returns:
      boolean; whether a GTU can turn on red.
    • toString

      public String toString()
      Overrides:
      toString in class AbstractLaneBasedObject