View Javadoc
1   package org.opentrafficsim.trafficcontrol;
2   
3   import org.djutils.event.EventListener;
4   import org.djutils.event.EventProducer;
5   import org.djutils.event.EventType;
6   import org.djutils.metadata.MetaData;
7   import org.djutils.metadata.ObjectDescriptor;
8   import org.opentrafficsim.core.object.NonLocatedObject;
9   import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLightColor;
10  
11  /**
12   * Interface for traffic light controllers.
13   * <p>
14   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
19   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
20   */
21  public interface TrafficController extends EventProducer, EventListener, NonLocatedObject
22  {
23      /**
24       * Retrieve the Id of the traffic light controller.
25       * @return String; the id of the traffic light controller
26       */
27      @Override
28      String getId();
29  
30      /** Traffic controller is starting up. Particular traffic control programs may use additional states not listed here. */
31      String STARTING_UP = "starting up";
32  
33      /** Traffic controller is being cloned. Particular traffic control programs may use additional states not listed here. */
34      String BEING_CLONED = "being cloned";
35  
36      /** Traffic controller is running. */
37      String RUNNING = "running";
38  
39      /** Traffic controller is shutting down. */
40      String SHUTTING_DOWN = "shutting down";
41  
42      /** Traffic controller is off. */
43      String OFF = "off";
44  
45      /** Constant to select variables that have no associated traffic stream. */
46      int NO_STREAM = -1;
47  
48      /**
49       * The <b>timed</b> event type for pub/sub that a newly created traffic controller emits. <br>
50       * Payload: Object[] { String trafficControllerId, String initialState }
51       */
52      EventType TRAFFICCONTROL_CONTROLLER_CREATED = new EventType("TRAFFICCONTROL.CONTROLLER_CREATED",
53              new MetaData("Controller created", "Controller id, initial state",
54                      new ObjectDescriptor("Controller id", "Id of the controller", String.class),
55                      new ObjectDescriptor("Initial state", "Initial state", String.class)));
56  
57      /**
58       * The <b>timed</b> event type for pub/sub that a traffic controller emits when it begins the computations to determine its
59       * response to the current input (detector states).<br>
60       * Payload: Object[] { String trafficControllerId }
61       */
62      EventType TRAFFICCONTROL_CONTROLLER_EVALUATING =
63              new EventType("TRAFFICCONTROL.CONTROLLER_EVALUATING", new MetaData("Controller eveluating", "Controller id",
64                      new ObjectDescriptor("Controller id", "Id of the controller", String.class)));
65  
66      /**
67       * The <b>timed</b> event type for pub/sub that a traffic controller uses to convey warnings.<br>
68       * Payload: Object[] { String trafficControllerId, String message }
69       */
70      EventType TRAFFICCONTROL_CONTROLLER_WARNING = new EventType("TRAFFICCONTROL.CONTROLLER_WARNING",
71              new MetaData("Controller warning", "Controller id, warning message",
72                      new ObjectDescriptor("Controller id", "Id of the controller", String.class),
73                      new ObjectDescriptor("Message", "Message", String.class)));
74  
75      /**
76       * The <b>timed</b> event for pub/sub emitted by a traffic control machine when it changes state (STARTING_UP, RUNNING,
77       * SHUTTING_DOWN, OFF, etc. The exact set of states may vary depending on the type of traffic control machine. <br>
78       * Payload: Object[] { String trafficControllerId, String oldState, String newState }
79       */
80      EventType TRAFFICCONTROL_STATE_CHANGED = new EventType("TRAFFIC_CONTROL.STATE_CHANGED",
81              new MetaData("Controller state changed", "Controller id, old state, new state",
82                      new ObjectDescriptor("Controller id", "Id of the controller", String.class),
83                      new ObjectDescriptor("Old state", "Old state", String.class),
84                      new ObjectDescriptor("New state", "New state", String.class)));
85  
86      /**
87       * The <b>timed</b>event that is fired by a traffic control program when a traffic light must change state. <br>
88       * Payload: Object[] { String trafficControllerId, Short stream, TrafficLightColor newColor }
89       */
90      EventType TRAFFIC_LIGHT_CHANGED = new EventType("TrafficLightChanged",
91              new MetaData("Controller state changed", "Controller id, old state, new state",
92                      new ObjectDescriptor("Controller id", "Id of the controller", String.class),
93                      new ObjectDescriptor("Stream", "Stream number", Short.class),
94                      new ObjectDescriptor("Light color", "New traffic light color", TrafficLightColor.class)));
95  
96      /**
97       * The <b>timed</b> event type for pub/sub indicating the creation of a traffic control program variable. <br>
98       * Listeners to this event can send <code>TRAFFICCONTROL_SET_TRACE</code> messages to set the tracing level of a
99       * variable.<br>
100      * Payload: Object[] {String trafficControllerId, String variableId, Short trafficStream, Double initialValue}
101      */
102     EventType TRAFFICCONTROL_VARIABLE_CREATED = new EventType("TRAFFICCONTROL.VARIABLE_CREATED",
103             new MetaData("Controller state changed", "Controller id, old state, new state",
104                     new ObjectDescriptor("Controller id", "Id of the controller", String.class),
105                     new ObjectDescriptor("Variable id", "Id of the variable", String.class),
106                     new ObjectDescriptor("Stream", "Stream number", Short.class),
107                     new ObjectDescriptor("Initial value", "Initial value", Double.class)));
108 
109     /**
110      * The <b>timed</b> event type that instruct a traffic controller to change the tracing level of a variable. <br>
111      * Payload: Object[] { String trafficControllerId, String variableId, Short trafficStream, Boolean trace } <br>
112      * Remark 1: an empty string for the variableId sets or clears tracing for all variables associated with the traffic stream.
113      * <br>
114      * Remark 2: The stream number <code>NO_STREAM</code> selects variable(s) that are not associated with a particular traffic
115      * stream. <br>
116      * Remark 3: setting the tracing level of a variable changes the amount of
117      * <code>TRAFFICCONTROL_TRACED_VARIABLE_UPDATED</code> events sent to <b>all</b> listeners; i.e. it is not possible to
118      * affect tracing on a per listener basis.
119      */
120     EventType TRAFFICCONTROL_SET_TRACING = new EventType("TRAFFICCONTROL.SET_TRACING",
121             new MetaData("Controller state changed", "Controller id, old state, new state",
122                     new ObjectDescriptor("Controller id", "Id of the controller", String.class),
123                     new ObjectDescriptor("Variable id", "Id of the variable", String.class),
124                     new ObjectDescriptor("Stream", "Stream number", Short.class),
125                     new ObjectDescriptor("Trace", "Trace", Boolean.class)));
126 
127     /**
128      * The <b>timed</b> event type for pub/sub indicating the update of a traced control program variable. <br>
129      * Payload: Object[] {String trafficControllerId, String variableId, Short trafficStream, Double oldValue, Double newValue,
130      * String expressionOrDescription} <br>
131      * Remark 1: for variable that are not associated with a particular traffic stream, the trafficStream value shall be
132      * <code>NO_STREAM</code> <br>
133      * Remark 2: if the variable is a timer that has just been initialized; newValue will reflect the duration in seconds
134      */
135     EventType TRAFFICCONTROL_TRACED_VARIABLE_UPDATED = new EventType("TRAFFICCONTROL.VARIABLE_UPDATED",
136             new MetaData("Controller state changed", "Controller id, old state, new state",
137                     new ObjectDescriptor("Controller id", "Id of the controller", String.class),
138                     new ObjectDescriptor("Variable id", "Id of the variable", String.class),
139                     new ObjectDescriptor("Stream", "Stream number", Short.class),
140                     new ObjectDescriptor("Old value", "Old value", Double.class),
141                     new ObjectDescriptor("New value", "New value", Double.class),
142                     new ObjectDescriptor("Expression", "Expression or description", String.class)));
143 
144     /**
145      * The <b>timed</b> event for pub/sub emitted by a traffic control machine when it changes to another conflict group. <br>
146      * Payload: Object[] { String trafficControllerId, String oldConflictGroupStreams, String newConflictGroupStreams } <br>
147      * Remark 1: a conflict group is described as a space-separated list of traffic stream numbers. The traffic streams within a
148      * conflict group should be compatible; i.e. not conflicting. <br>
149      * Remark 2: The value <code>00</code> can be used as a place holder for a stream in a conflict groups that have fewer than
150      * the maximum number of traffic streams that occur in any conflict group.<br>
151      * Remark 3: The very first event of this type may use an empty string for <code>oldConflictGroupStreams</code>.<br>
152      * Remark 4: Some traffic control systems may not operate in a conflict group by conflict group fashion and therefore not
153      * emit these events.
154      */
155     EventType TRAFFICCONTROL_CONFLICT_GROUP_CHANGED = new EventType("TRAFFICCONTROL.CONFLICT_GROUP_CHANGED",
156             new MetaData("Controller state changed", "Controller id, old state, new state",
157                     new ObjectDescriptor("Controller id", "Id of the controller", String.class),
158                     new ObjectDescriptor("Old stream", "Old conflict group stream", String.class),
159                     new ObjectDescriptor("New stream", "New conflict group stream", String.class)));
160 
161 }