All Implemented Interfaces:
nl.tudelft.simulation.dsol.animation.Locatable, Identifiable, EventProducer, OtsShape, 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, Wouter Schakel
  • Field Details

    • DEFAULT_TRAFFICLIGHT_ELEVATION

      public static final 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 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, Length longitudinalPosition, Length height) throws NetworkException
      Construct an AbstractTrafficLight with specified elevation.
      Parameters:
      id - traffic light id
      lane - lane where the traffic light is located
      longitudinalPosition - position of the traffic light on the lane, in the design direction
      height - the elevation of the traffic light
      Throws:
      NetworkException - on failure to place the object
    • TrafficLight

      public TrafficLight(String id, Lane lane, Length longitudinalPosition) throws NetworkException
      Construct an AbstractTrafficLight at default elevation (use only on roads at elevation 0).
      Parameters:
      id - traffic light id
      lane - lane where the traffic light is located
      longitudinalPosition - position of the traffic light on the lane, in the design direction
      Throws:
      NetworkException - on failure to place the object
  • Method Details

    • getTrafficLightColor

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

      public final TrafficLightColor getTrafficLightColor(Duration time)
      Get the traffic light color in the past.
      Parameters:
      time - simulation time to obtain traffic light color.
      Returns:
      current traffic light color.
    • setTrafficLightColor

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

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

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

      public String toString()
      Overrides:
      toString in class AbstractLaneBasedObject