Class TrafficLightDetector

java.lang.Object
org.djutils.event.LocalEventProducer
org.opentrafficsim.road.network.object.detector.TrafficLightDetector
All Implemented Interfaces:
EventListener, nl.tudelft.simulation.dsol.animation.Locatable, Identifiable, EventListener, EventProducer, OtsShape, HierarchicallyTyped<DetectorType,Detector>, Detector, LocatedObject

public class TrafficLightDetector extends LocalEventProducer implements EventListener, Detector
This traffic light reports whether any GTUs are within its area. The area is two sub-sections on one or two lanes. This traffic does not report the total number of GTUs within the area; only whether that number is zero or non-zero. This class does not derive from Detector as it concerns an area, not a cross-section. All sides of the 2 areas are managed by 4 Detectors to capture GTU longitudinal movement, and by listening to events to capture lane changes, vehicle generation, and vehicle destruction.

Copyright (c) 2013-2026 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

    • TRAFFIC_LIGHT_DETECTOR_TRIGGER_ENTRY_EVENT

      public static final EventType TRAFFIC_LIGHT_DETECTOR_TRIGGER_ENTRY_EVENT
      The timed event type for pub/sub indicating the triggering of the entry of a NonDirectionalOccupancyDetector.
      Payload: Object[] {String detectorId}
    • TRAFFIC_LIGHT_DETECTOR_TRIGGER_EXIT_EVENT

      public static final EventType TRAFFIC_LIGHT_DETECTOR_TRIGGER_EXIT_EVENT
      The timed event type for pub/sub indicating the triggering of the exit of an NonDirectionalOccupancyDetector.
      Payload: Object[] {String detectorId}
  • Constructor Details

    • TrafficLightDetector

      public TrafficLightDetector(String id, Lane laneA, org.djunits.value.vdouble.scalar.Length positionA, Lane laneB, org.djunits.value.vdouble.scalar.Length positionB, List<Lane> intermediateLanes, RelativePosition.Type entryPosition, RelativePosition.Type exitPosition, DetectorType detectorType) throws NetworkException
      Construct a new traffic light detector.
      TODO Possibly provide the GtuTypes that trigger the detector as an argument for the constructor
      Parameters:
      id - id of this detector
      laneA - the lane of the A detection point of this traffic light detector
      positionA - the position of the A detection point of this traffic light detector
      laneB - the lane of the B detection point of this traffic light detector
      positionB - the position of the B detection point of this traffic light detector
      intermediateLanes - list of intermediate lanes
      entryPosition - the position on the GTUs that trigger the entry events
      exitPosition - the position on the GTUs that trigger the exit events
      detectorType - detector type.
      Throws:
      NetworkException - when the network is inconsistent.
  • Method Details

    • addGtu

      protected final void addGtu(LaneBasedGtu gtu)
      Add a GTU to the set.
      Parameters:
      gtu - the GTU that must be added
    • removeGtu

      protected final void removeGtu(LaneBasedGtu gtu)
      Remove a GTU from the set.
      Parameters:
      gtu - the GTU that must be removed
    • notify

      public final void notify(Event event)
      Specified by:
      notify in interface EventListener
    • getPositionTypeEntry

      public final RelativePosition.Type getPositionTypeEntry()
      Returns the relative position type of the vehicle (e.g., FRONT, BACK) that triggers the detector.
      Returns:
      the relative position type of the vehicle (e.g., FRONT, BACK) that triggers the detector.
    • getPositionTypeExit

      public final RelativePosition.Type getPositionTypeExit()
      Returns the relative position type of the vehicle (e.g., FRONT, BACK) that triggers the detector.
      Returns:
      the relative position type of the vehicle (e.g., FRONT, BACK) that triggers the detector.
    • getLanePositionA

      public final org.djunits.value.vdouble.scalar.Length getLanePositionA()
      Return the A position of this NonDirectionalOccupancyDetector.
      Returns:
      the lane and position on the lane where GTU entry is detected
    • getLanePositionB

      public final org.djunits.value.vdouble.scalar.Length getLanePositionB()
      Return the B position of this NonDirectionalOccupancyDetector.
      Returns:
      the lane and position on the lane where GTU exit is detected
    • signalDetection

      public final void signalDetection(TrafficLightDetector.StartEndDetector detector, LaneBasedGtu gtu)
      One of our start/end detectors has triggered.
      Parameters:
      detector - the detector that was triggered
      gtu - the gtu that triggered the flank detector
    • getId

      public final String getId()
      Returns the id.
      Specified by:
      getId in interface Identifiable
      Returns:
      The id of the detector.
    • getSimulator

      public final OtsSimulatorInterface getSimulator()
      Returns the simulator.
      Returns:
      The simulator.
    • getLocation

      public final DirectedPoint2d getLocation()
      Specified by:
      getLocation in interface nl.tudelft.simulation.dsol.animation.Locatable
      Specified by:
      getLocation in interface OtsShape
    • getRelativeBounds

      public final Bounds2d getRelativeBounds()
      Specified by:
      getRelativeBounds in interface nl.tudelft.simulation.dsol.animation.Locatable
      Specified by:
      getRelativeBounds in interface OtsShape
    • getOccupancy

      public final boolean getOccupancy()
      Return the state of this traffic light detector.
      Returns:
      true if one or more GTUs are currently detected; false of no GTUs are currently detected
    • getAbsoluteContour

      public Polygon2d getAbsoluteContour()
      Specified by:
      getAbsoluteContour in interface OtsShape
    • getRelativeContour

      public Polygon2d getRelativeContour()
      Specified by:
      getRelativeContour in interface OtsShape
    • getHeight

      public org.djunits.value.vdouble.scalar.Length getHeight()
      Specified by:
      getHeight in interface LocatedObject
    • getFullId

      public String getFullId()
      Specified by:
      getFullId in interface LocatedObject
    • getType

      public DetectorType getType()
      Specified by:
      getType in interface HierarchicallyTyped<DetectorType,Detector>
    • toString

      public final String toString()
      Overrides:
      toString in class Object