命令 0xa2: 获取交通信号灯变量#
| ubyte | string |
|---|---|
| 变量 (Variable) | 交通信号灯 ID (Traffic Lights ID) |
请求获取指定名称交通信号灯的某个变量的值。返回的值是上一个仿真步长内所请求变量/值的状态。以下变量值可以被检索和订阅。返回值的类型也在表中显示。无法订阅交换约束 (0x32),这在技术上更像一个变更函数,仅作为检索函数实现是因为它需要一个返回值。
可检索的交通信号灯变量概览
| 变量 (Variable) | 取值类型 (ValueType) | 描述 (Description) | Python 方法 |
|---|---|---|---|
| id list (0x00) | stringList | 返回场景中所有交通信号灯的 ID 列表(忽略给定的交通信号灯 ID) | getIDList |
| count (0x01) | int | 返回场景中交通信号灯的数量(忽略给定的交通信号灯 ID) | getIDCount |
| state (light/priority tuple) (0x20) | string | 将指定交通信号灯的状态作为灯光定义的元组返回,定义来自 rRgGyYoO,分别代表红、绿、黄、关闭,其中小写字母表示车流必须减速 | getRedYellowGreenState |
| default current phase duration (0x24) | double | 返回当前活跃相位的默认总持续时间(秒);要获取剩余持续时间,请使用 (getNextSwitch() - simulation.getTime());要获取已花费的持续时间,请从总持续时间中减去剩余时间 | getPhaseDuration |
| controlled lanes (0x26) | stringList | 返回由指定交通信号灯控制的车道列表。为相位状态(信号索引)的每个元素至少返回一个条目(1)(2)。 | getControlledLanes |
| controlled links (0x27) | compound object | 返回交通信号灯控制的连接(links),返回列表中的索引对应于连接的 tls 链接索引。每个索引映射到一个共享相同链接索引的链接对象列表。每个链接对象通过给出进入车道、离开车道和途经车道来描述。 | getControlledLinks |
| current phase (0x28) | int | 返回当前程序中当前相位的索引 | getPhase |
| current program (0x29) | string | 返回当前程序的 ID | getProgram |
| complete definition (light/priority tuple) (0x2b) | compound object | 返回完整的交通信号灯程序,结构在数据类型下描述 | getCompleteRedYellowGreenDefinition |
| assumed time of next switch (0x2d) | double | 返回交通信号灯切换相位的假定时间(秒)。请注意,切换时间不是相对于当前仿真步长的(查询返回的结果将是绝对时间,从仿真开始计数);要获取相对时间,需要从查询返回的结果中减去当前仿真时间。另请注意,在感应式/自适应交通信号灯的情况下,时间可能会有所不同。 | getNextSwitch |
| spent duration (0x38) | double | 返回在当前相位花费的时间(秒) | getSpentDuration |
| blocking vehicles (0x25) | stringList | 返回占用后续铁路信号块的车辆 ID | getBlockingVehicles |
| rival vehicles (0x30) | stringList | 返回正在接近同一铁路信号块的车辆 ID | getRivalVehicles |
| priority vehicles (0x31) | stringList | 返回以更高优先级接近同一铁路信号块的车辆 ID | getPriorityVehicles |
| swap constraints (0x32) | list(Constraint) | 反转给定约束并返回为避免死锁而创建的新约束列表(通过交换)。 | swapConstraints |
请注意:
- 每条车道可能是多个连接(穿过交叉口的连接)的起点。因此,一条车道可能在输出中出现多次。
响应 0xb2: 交通信号灯变量#
| ubyte | string | ubyte | <return_type> |
|---|---|---|---|
| 变量 (Variable) | 交通信号灯 ID (Traffic Light ID) | 变量的返回类型 (Return type of the variable) | <RETURN_VALUE> |
对 "命令获取交通信号灯变量" 的响应。
复合对象交通信号灯程序的结构 (0x25 和 0x2b)#
如果您请求完整的交通信号灯程序,复合对象的结构如下。注意,除了 "length" 外,每个部分前面都有一个字节,表示其数据类型。
| integer | type + integer | logic | ... | logic |
|---|---|---|---|---|
| 长度 (Length) | 逻辑数量 (Number of logics) | 逻辑 1 (logic 1) | ... | 逻辑 n (logic n) |
其中 逻辑 (logic) 描述如下:
| type + string | type + integer | type + compound | type + integer | type + integer | phase | ... | phase |
|---|---|---|---|---|---|---|---|
| 子ID (SubID) | 类型 (Type) | 子参数 (SubParameter) | 当前相位索引 (Current phase index) | 相位数量 (Number of phases) | 相位 1 (Phase 1) | ... | 相位 n (Phase n) |
类型 (Type) 和子参数 (SubParameter) 目前尚未实现,因此它们为 0。
其中 相位 (phase) 描述如下:
| type + double | type + double | type + double | type + string |
|---|---|---|---|
| 持续时间 (Duration) (秒) | 最小持续时间 (MinDuration) (秒) | 最大持续时间 (MaxDuration) (秒) | 相位定义 (Phase definition) |
最小持续时间 (MinDuration) 和最大持续时间 (MaxDuration) 仅在感应式交通信号灯的上下文中相关。相位定义对于 0x25 和 0x2b 是不同的。第一个 (0x25) 包含旧的、已弃用的定义,该定义使用三个字符串来描述交通信号灯的状态,第一个表示绿灯 y/n,第二个表示刹车 y/n,第三个表示黄灯 y/n。第二个 (0x2b) 包含一个表示灯光的单字符串。请注意,第一个 (0x25) 也是反转的。
复合对象受控连接的结构#
如果您请求连接列表,复合对象的结构如下。注意,除了 "length" 外,每个部分前面都有一个字节,表示其数据类型。
| integer | controlled links | ... | controlled links |
|---|---|---|---|
| 长度 (Length) (信号数量) | 信号 0 控制的连接 (links controlled by signal 0) | ... | 信号 n-1 控制的连接 (links controlled by signal n-1) |
受控连接 (Controlled links):
| int | stringlist | ... | stringlist |
|---|---|---|---|
| 受控连接数量 (number of controlled links) | 连接 0 (link 0) | ... | 连接 n-1 (link n-1) |
每个连接由一个包含三个条目的字符串列表描述:进入交叉口的车道、离开交叉口的车道,以及穿过交叉口的车道(交叉口内部)。空字符串表示缺少车道。
该方法基本上返回一个 3 元组列表的列表。外部列表的长度对应于每个相位 'state' 属性的长度。每个内部列表(位于外部列表的位置 i)描述由索引 i 处的状态控制的连接。
默认情况下,状态的每个索引精确控制一个连接,因此所有内部列表的长度均为 1。但是,如果使用信号组来简化 'state' 属性,内部列表可能更长。
结果复合对象交换约束的结构 (0x32)#
如果您请求约束交换,结果约束列表指示作为交换结果创建的所有新约束。除了 "length" 外,每个部分前面都有一个字节,表示其数据类型。
| integer | constraint | ... |
|---|---|---|
| 长度 (Length) (约束数量) | 约束组件,见下文 (constraint components, see below) | ... |
约束 (constraint):
| string | string | string | string | int | int | byte | byte | stringList |
|---|---|---|---|---|---|---|---|---|
| signalId | tripId | foeId | foeSignalId | limit | 约束类型 (constraint type) | mustWait | 激活状态 (active) | 参数形式:key,value,...,key,value (params of the form: key,value,...,key,value) |
扩展检索消息#
交换约束 (0x32)#
| byte | int | byte | string | byte | string | byte | string |
|---|---|---|---|---|---|---|---|
| 值类型 compound (value type compound) | 元素数量 (始终=3) (number of elements (always=3)) | 值类型 string (value type string) | 约束的 tripId (tripId of constraint) | 值类型 string (value type string) | 对抗信号 ID (foe signal id) | 值类型 string (value type string) | 对抗 trip ID (foe trip id) |
获取交通信号灯参数 (0x7e)#
交通信号灯支持使用通用参数检索调用检索其他参数。
| 键 (key) | 返回值类型 (表示为字符串) | 支持的 tlType | 描述 |
|---|---|---|---|
| cycleTime | double (s) | static, actuated, delay_based | 默认周期持续时间(对静态交通信号灯无影响) |
| cycleSecond | double (s) | static, actuated, delay_based | 周期内的时间 |
| offset | double (s) | static, actuated, delay_based | 相对于仿真开始的周期开始偏移 |
| coordinated | bool | static, actuated, delay_based | 周期内的时间是否相对于仿真时间计算 |
| max-gap | double (s) | actuated | 放弃相位的检测器超时 |
| show-detectors | bool | actuated | 在视图中显示/隐藏检测器 |
| inactive-threshold | double (s) | actuated | 使用默认相位跳过逻辑运行时,切换到未服务相位的超时 |
| condition.CONDITION_ID | double | actuated | 检索 ID 为 CONDITION_ID 的自定义切换条件的当前值。 |
| typeName | string | all | 以字符串形式检索类型(例如 "static") |
