All Implemented Interfaces:
Comparable<LaneDetector>, nl.tudelft.simulation.dsol.animation.Locatable, Identifiable, EventProducer, OtsShape, HierarchicallyTyped<DetectorType,Detector>, Detector, LocatedObject, LaneBasedObject
Direct Known Subclasses:
LoopDetector, ReportingDetector, SinkDetector, TrafficLightDetector.StartEndDetector

public abstract class LaneDetector extends AbstractLaneBasedObject implements Comparable<LaneDetector>, LaneBasedObject, Detector
A detector is a lane-based object that can be triggered by a relative position of the GTU (e.g., front, back) when that relative position passes over the detector location on the lane.

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

    • DETECTOR_TRIGGER_EVENT

      public static final EventType DETECTOR_TRIGGER_EVENT
      The timed event type for pub/sub indicating the triggering of a Detector on a lane.
      Payload: Object[] {String detectorId, Detector detector, LaneBasedGtu gtu, RelativePosition.TYPE relativePosition}
    • DEFAULT_DETECTOR_ELEVATION

      public static final org.djunits.value.vdouble.scalar.Length DEFAULT_DETECTOR_ELEVATION
      Default elevation of a detector; if the lane is not at elevation 0; this value is probably far off.
  • Constructor Details

    • LaneDetector

      public LaneDetector(String id, Lane lane, org.djunits.value.vdouble.scalar.Length longitudinalPosition, RelativePosition.Type positionType, PolyLine2d line, org.djunits.value.vdouble.scalar.Length elevation, DetectorType detectorType) throws NetworkException
      Create a detector on a lane at a position on that lane.
      Parameters:
      id - the id of the detector.
      lane - the lane for which this is a detector.
      longitudinalPosition - the position (between 0.0 and the length of the Lane) of the detector on the design line of the lane.
      positionType - RelativePosition.TYPE; the relative position type (e.g., FRONT, BACK) of the vehicle that triggers the detector.
      line - the line of the object, which provides its location and bounds as well
      elevation - elevation of the detector
      detectorType - detector type.
      Throws:
      NetworkException - when the position on the lane is out of bounds
    • LaneDetector

      public LaneDetector(String id, Lane lane, org.djunits.value.vdouble.scalar.Length longitudinalPosition, RelativePosition.Type positionType, PolyLine2d line, DetectorType detectorType) throws NetworkException
      Create a detector on a lane at a position on that lane at elevation Detector.DEFAULT_DETECTOR_ELEVATION.
      Parameters:
      id - the id of the detector.
      lane - the lane for which this is a detector.
      longitudinalPosition - the position (between 0.0 and the length of the Lane) of the detector on the design line of the lane.
      positionType - RelativePosition.TYPE; the relative position type (e.g., FRONT, BACK) of the vehicle that triggers the detector.
      line - the contour of the object, which provides its location and bounds as well
      detectorType - detector type.
      Throws:
      NetworkException - when the position on the lane is out of bounds
    • LaneDetector

      public LaneDetector(String id, Lane lane, org.djunits.value.vdouble.scalar.Length longitudinalPosition, RelativePosition.Type positionType, DetectorType detectorType) throws NetworkException
      Create a new Detector on a lane at a position on that lane at elevation Detector.DEFAULT_DETECTOR_ELEVATION and default geometry.
      Parameters:
      id - the id of the new Detector
      lane - the lane on which the new Detector is positioned
      longitudinalPosition - the position (between 0.0 and the length of the Lane) of the detector on the design line of the lane
      positionType - RelativePosition.TYPE; the relative position type (e.g., FRONT, BACK) of the vehicle that triggers the detector.
      detectorType - detector type.
      Throws:
      NetworkException - when the position on the lane is out of bounds
  • Method Details

    • getType

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

      public final void trigger(LaneBasedGtu gtu)
      Trigger an action on the GTU. Normally this is the GTU that triggered the detector. The typical call therefore is detector.trigger(this);.
      Parameters:
      gtu - the GTU for which to carry out the trigger action.
    • triggerResponse

      protected abstract void triggerResponse(LaneBasedGtu gtu)
      Implementation of the response to a trigger of this detector by a GTU.
      Parameters:
      gtu - the lane based GTU that triggered this detector.
    • getPositionType

      public final RelativePosition.Type getPositionType()
      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.
    • isCompatible

      public final boolean isCompatible(GtuType gtuType)
      Returns whether this Detector can detector GTUs of the given type.
      Parameters:
      gtuType - GTU type.
      Returns:
      whether this Detector can detector GTUs of the given type.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(LaneDetector o)
      Specified by:
      compareTo in interface Comparable<LaneDetector>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractLaneBasedObject