torchdrivesim.traffic_lights

Attributes

Classes

TrafficLightControl

Traffic lights, with default allowed states of ['red', 'yellow', 'green'].

TrafficLightState

Generic enumeration.

TrafficLightGroupState

Representing a single state of a group of traffic lights.

TrafficLightStateMachine

TrafficLightController

Functions

Module Contents

class torchdrivesim.traffic_lights.TrafficLightControl(pos: torch.Tensor, allowed_states: List[str] | None = None, replay_states: torch.Tensor | None = None, mask: torch.Tensor | None = None)[source]

Bases: BaseTrafficControl

Traffic lights, with default allowed states of [‘red’, ‘yellow’, ‘green’]. An agent is regarded to violate the traffic light if the light is red and the agent bounding box substantially overlaps with the stop line.

violation_rear_factor = 0.1
classmethod _default_allowed_states() List[str][source]
compute_violation(agent_state: torch.Tensor) torch.Tensor[source]

Given a collection of agents, computes which agents violate the traffic control. As deciding violations is typically complex, this function provides an approximate answer only. The base class reports no violations.

Parameters:

agent_state – BxAx5 tensor of agents states - x,y,length,width,orientation

Returns:

BxA boolean tensor indicating which agents violated the traffic control

torchdrivesim.traffic_lights.logger[source]
class torchdrivesim.traffic_lights.TrafficLightState[source]

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

none[source]
green[source]
yellow[source]
red[source]
torchdrivesim.traffic_lights.ActorStates[source]
class torchdrivesim.traffic_lights.TrafficLightGroupState[source]

Representing a single state of a group of traffic lights.

actor_states: ActorStates[source]
sequence_number: int[source]
duration: float[source]
next_state: int[source]
class torchdrivesim.traffic_lights.TrafficLightStateMachine(group_states: List[TrafficLightGroupState])[source]
classmethod from_json(json_file_path: str) typing_extensions.Self[source]

Current json format: [

{
“actor_states”: {

“4411”: “red”, “3411”: “red”, ………

}, “state”: “0”, “duration”: 10, “next_state”: “1”

]

to_json() str[source]
reset()[source]
set_to(state_index: int, time_remaining: float)[source]

Set the TrafficLightStateMachine to a specific state.

tick(dt: float)[source]

Update the time remaining for the current state.

property states: List[TrafficLightGroupState][source]
property duration: float[source]
property current_state: TrafficLightGroupState[source]
property time_remaining: float[source]
get_current_actor_states() ActorStates[source]
class torchdrivesim.traffic_lights.TrafficLightController(traffic_fsms: List[TrafficLightStateMachine])[source]
classmethod from_json(json_file_path: str) typing_extensions.Self[source]

Current json format: [

[
{
“actor_states”: {

“4411”: “red”, “3411”: “red”, ………

}, “state”: “0”, “duration”: 10, “next_state”: “1”

]

to_json() str[source]
tick(dt)[source]
set_to(light_states: List[List[float]])[source]
reset()[source]
update_current_state_and_time()[source]
property current_state[source]
property current_state_with_name[source]
property state_per_machine[source]
property time_remaining[source]
get_number_of_light_groups()[source]
collect_all_current_light_states()[source]
torchdrivesim.traffic_lights.current_light_state_tensor_from_controller(traffic_light_controller: TrafficLightController, traffic_light_ids: List[int]) torch.Tensor[source]