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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassEmbedded detectors used by a TrafficLightDetector. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EventTypeThe timed event type for pub/sub indicating the triggering of the entry of a NonDirectionalOccupancyDetector.static final EventTypeThe timed event type for pub/sub indicating the triggering of the exit of an NonDirectionalOccupancyDetector.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
ConstructorsConstructorDescriptionTrafficLightDetector(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) Construct a new traffic light detector.
TODO Possibly provide the GtuTypes that trigger the detector as an argument for the constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddGtu(LaneBasedGtu gtu) Add a GTU to the set.org.djunits.value.vdouble.scalar.Lengthfinal StringgetId()Returns the id.final org.djunits.value.vdouble.scalar.LengthReturn the A position of this NonDirectionalOccupancyDetector.final org.djunits.value.vdouble.scalar.LengthReturn the B position of this NonDirectionalOccupancyDetector.final DirectedPoint2dfinal booleanReturn the state of this traffic light detector.final RelativePosition.TypeReturns the relative position type of the vehicle (e.g., FRONT, BACK) that triggers the detector.final RelativePosition.TypeReturns the relative position type of the vehicle (e.g., FRONT, BACK) that triggers the detector.final Bounds2dfinal OtsSimulatorInterfaceReturns the simulator.getType()final voidprotected final voidremoveGtu(LaneBasedGtu gtu) Remove a GTU from the set.final voidsignalDetection(TrafficLightDetector.StartEndDetector detector, LaneBasedGtu gtu) One of our start/end detectors has triggered.final StringtoString()Methods 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.opentrafficsim.base.HierarchicallyTyped
isOfTypeMethods inherited from interface nl.tudelft.simulation.dsol.animation.Locatable
getZMethods inherited from interface org.opentrafficsim.base.geometry.OtsShape
contains, contains, getAbsoluteBounds, getAbsoluteContour, getDirZ, signedDistance, signedDistance
-
Field Details
-
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
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 detectorlaneA- the lane of the A detection point of this traffic light detectorpositionA- the position of the A detection point of this traffic light detectorlaneB- the lane of the B detection point of this traffic light detectorpositionB- the position of the B detection point of this traffic light detectorintermediateLanes- list of intermediate lanesentryPosition- the position on the GTUs that trigger the entry eventsexitPosition- the position on the GTUs that trigger the exit eventsdetectorType- detector type.- Throws:
NetworkException- when the network is inconsistent.
-
-
Method Details
-
addGtu
Add a GTU to the set.- Parameters:
gtu- the GTU that must be added
-
removeGtu
Remove a GTU from the set.- Parameters:
gtu- the GTU that must be removed
-
notify
- Specified by:
notifyin interfaceEventListener
-
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
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
One of our start/end detectors has triggered.- Parameters:
detector- the detector that was triggeredgtu- the gtu that triggered the flank detector
-
getId
Returns the id.- Specified by:
getIdin interfaceIdentifiable- Returns:
- The id of the detector.
-
getSimulator
Returns the simulator.- Returns:
- The simulator.
-
getLocation
- Specified by:
getLocationin interfacenl.tudelft.simulation.dsol.animation.Locatable- Specified by:
getLocationin interfaceOtsShape
-
getRelativeBounds
- Specified by:
getRelativeBoundsin interfacenl.tudelft.simulation.dsol.animation.Locatable- Specified by:
getRelativeBoundsin interfaceOtsShape
-
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
- Specified by:
getAbsoluteContourin interfaceOtsShape
-
getRelativeContour
- Specified by:
getRelativeContourin interfaceOtsShape
-
getHeight
public org.djunits.value.vdouble.scalar.Length getHeight()- Specified by:
getHeightin interfaceLocatedObject
-
getFullId
- Specified by:
getFullIdin interfaceLocatedObject
-
getType
- Specified by:
getTypein interfaceHierarchicallyTyped<DetectorType,Detector>
-
toString
-