TraCI/Traffic Lights Value Retrieval

From Sumo
Jump to: navigation, search

Command 0xa2: Get Traffic Lights Variable

ubyte string
Variable Traffic Lights ID

Asks for the value of a certain variable of the named traffic light. The value returned is the state of the asked variable/value within the last simulation step. The following variable values can be retrieved, the type of the return value is also shown in the table.

Overview Retrievable Traffic Lights Variables
Variable ValueType Description Python Method
id list (0x00) stringList Returns a list of ids of all traffic lights within the scenario (the given Traffic Lights ID is ignored) getIDList
count (0x01) int Returns the number of traffic lights within the scenario (the given Traffic Lights ID is ignored) getIDCount
state (light/priority tuple) (0x20) string Returns the named tl's state as a tuple of light definitions from rRgGyYoO, for red, green, yellow, off, where lower case letters mean that the stream has to decelerate getRedYellowGreenState
default current phase duration (0x24) int Returns the default total duration of the currently active phase [ms]; To obtain the remaining duration use (getNextSwitch - simulation.getCurrentTime()); to obtain the spent duration subtract the remaining from the total duration getPhaseDuration
controlled lanes (0x26) stringList Returns the list of lanes which are controlled by the named traffic light. Returns at least one entry for every element of the phase state (signal index)(1)(2). getControlledLanes
controlled links (0x27) compound object Returns the links controlled by the traffic light, sorted by the signal index and described by giving the incoming, outgoing, and via lane. (2) getControlledLinks
current phase (0x28) int Returns the index of the current phase in the current program getPhase
current program (0x29) string Returns the id of the current program getProgram
complete definition (light/priority tuple) (0x2b) compound object Returns the complete traffic light program, structure described under data types getCompleteRedYellowGreenDefinition
assumed time of next switch (0x2d) int Returns the assumed time (in milliseconds) at which the tls changes the phase. Please note that the time to switch is not relative to current simulation step (the result returned by the query will be absolute time, counting from simulation start); to obtain relative time, one needs to subtract current simulation time from the result returned by this query. Please also note that the time may vary in the case of actuated/adaptive traffic lights getNextSwitch

Please note:

  1. Each lane may be the start of multiple links (connections across the intersection). Thus a lane may occur multiple times in the output
  2. If one signal index controls multiple links, their incoming lanes and links are all returned sequentially. This only happens if set explicitly by the user when building the network.

Response 0xb2: Traffic Lights Variable

ubyte string ubyte <return_type>
Variable Traffic Light ID Return type of the variable <RETURN_VALUE>

The respond to a "Command Get Traffic Lights Variable".

Structure of compound object traffic light program (both 0x25 and 0x2b)

If you request a complete traffic light program, the compound object is structured as following. Attention, each part is preceded by a byte which represents its data type, except "length".

integer type + integer logic ... logic
Length Number of logics logic 1 ... logic n

where logic is decribed by:

type + string type + integer type + compound type + integer type + integer phase ... phase
SubID Type SubParameter Current phase index Number of phases Phase 1 ... Phase n

Type and SubParameter aren't currently implemented therefore they are 0.

where phase is described by:

type + integer type + integer type + integer type + stringList
Duration MinDuration MaxDuration Phase definition

MinDuration and MaxDuration are only relevant in the context of actuated traffic lights. The phase definition differs for 0x25 and 0x2b. The first (0x25) contains the old, deprecated definition which uses three strings that describe the tl's state, the first green y/n, the second for brake y/n, the third for yellow y/n. The second (0x2b) contains a single string representing the lights. Note, that the first (0x25) is also reversed.

Structure of compound object controlled links

If you request the list of links, the compound object is structured as following. Attention, each part is preceded by a byte which represents its data type, except "length".

integer controlled links ... controlled links
Length (number of signals) links controlled by signal 0 ... links controlled by signal n-1

Controlled links:

int stringlist ... stringlist
number of controlled links link 0 ... link n-1

Each link is described by a string list with three entries: the lane which is incoming into the junction, the lane which is outgoing from the junction, and the lane across the junction (junction-internal). Empty strings indicate missing lanes.