infrastructure package¶
Overview¶
Infrastructure package is used to model traffic signals, stop lights, pedestrian crossing boards. Currently, the infrastructure implemented are TrafficController and Traffic Signal. TrafficController is an attribute of a Intersection. It coordinates the switching of signals on the traffic signals on the corresponding intersection. TrafficSignal is an attribute on a Node which is controlled by a TrafficController of the Intersection which has the Node. Each Lane of the Road ending at the Node corresponds to a TrafficSignal on that Node.
infrastructure.traffic module¶
Traffic module contains classes and methods for controlling the traffic signals in the simulator.
-
class
core.lib.infrastructure.traffic.
TrafficController
¶ Controls and synchronizes all the traffic signals at an intersection.
The number of signals on a controller and the number of phases are coupled. In the current implementation, a fixed number of traffic signals is assumed (12) and the no of phases is fixed. The future implementation must include dynamically changing the “__no_phases” if a controller is instantiated with a different number of signals.
-
__no_phases
¶ int – indicates the number of phases (this depends on the functionality and no of signals)
-
__dt
¶ float – time between successive traffic state updates
-
__scale
¶ float – ten times of __dt
-
__cycle_length
¶ float – cycle length is the time taken for one complete cycle (a signal going from g-y-r-g)
-
__table
¶ dict – table defines the times at which the signals should switch. The entire control lies with this table
-
signals
¶ list – list of TrafficSignal objects
-
generate_table
()¶ Generates a table as described above with specified green time ratio, yellow time ratio and red time ratio. These ratios are coupled with the phase of the signal so care must be taken while changing these values.
Returns: keys as the traffic signal tcid, and the value as a list described in the above example Return type: dict
-
reset_signals
()¶ Resets all the signals to the beginning of the time cycle. This can be used to adaptively change the relative phase of the all the signals.
-
set_table
(table)¶ Currently a public method to enable the users to set a custom and phase timing (relative to the start of the cycle).
Parameters: table – A dict with keys as the indices to the traffic signals and values as a list containing the phase Example: Consider a TrafficController of cycle length 30. The entry for signal 0 in the self.__table looks like this.
table[0] = ['g', 10, 'y', 15, 'r', 30]
Traffic Signal at index 0 is green for the first 10 seconds, yellow for the next five seconds, and red for the next 15 seconds. The last entry should match with the cycle length of the TrafficController.
-
update_signals
()¶ This method is called every update step in the main simulation loop to update all the signal states and timings.
-
-
class
core.lib.infrastructure.traffic.
TrafficSignal
(tcid)¶ Traffic Signal is an interface for the vehicle to ‘see’ the states. It is controlled by a TrafficController.
-
color
¶ str – indicates the traffic state (red, green, yellow/amber)
-
time_remaining
¶ float – time after which the color changes
-
tcid
¶ int – unique identifier of the signal with respect to the controller
-
node
¶ Node – the node that has the traffic signal
-
tick
¶ int – counter/ time
-
x
¶ object – x coord of signal
-
y
¶ object – y coord of signal
-
get_state
()¶ Enables direct querying of the traffic signals’ states by the vehicles or any other object that has access to nodes. In the future implementation, communication module (v2x) should be interfaced with traffic signals.
Returns: [color, time remaining] Return type: list
-
set_coords
(x, y)¶ Sets the coordinates of the signal.
Parameters: - x (object) – x coord of signal
- y (object) – y coord of signal
-
set_node
(node)¶ Links the signal to a node object, to enable referencing nodes while accessing signals. It is used while creating a map and assigning traffic signals to end nodes of roads ending at intersections.
Parameters: node (Node) – the node object to which the signal is assigned
-
set_state
(color, time_remaining)¶ Sets the state of the signals regarding to the color and remaining time.
Parameters: - color (str) – ‘r’ for red, ‘g’ for green, ‘a’ for amber/yellow
- time_remaining (float) – time remaining in the current phase (time after which the color changes)
-