simworld.traffic.controller package

Submodules

simworld.traffic.controller.traffic_controller module

Traffic controller module for coordinating all traffic-related components.

This module provides the main controller for the traffic simulation, handling initialization, spawning, and coordination of all traffic elements including vehicles, pedestrians, and traffic signals.

class simworld.traffic.controller.traffic_controller.TrafficController(config: Config, num_vehicles: int | None = None, num_pedestrians: int | None = None, map: str | None = None, seed: int | None = None, dt: float | None = None)

Bases: object

Main controller class for the traffic simulation system.

Coordinates all aspects of the traffic simulation including road network, vehicles, pedestrians, and traffic signals.

property crosswalks

Get all crosswalks in the simulation.

Returns:

List of all crosswalk objects.

disconnect_communicator()

Disconnect the communication interface from the simulation environment.

init_communicator(communicator=None)

Initialize the communication interface with the simulation environment.

Args:

communicator: Optional communicator instance. If None, a new one is created.

init_roadnet_from_file(file_path)

Initialize the road network from a JSON file.

Args:

file_path: Path to the JSON file containing road network data.

Raises:

ValueError: If the file path is not absolute.

property lanes

Get all traffic lanes in the simulation.

Returns:

List of all traffic lane objects.

property pedestrians

Get all pedestrians in the simulation.

Returns:

List of all pedestrian objects.

reset(num_vehicles: int, num_pedestrians: int, map: str)

Reset the simulation with new parameters.

Args:

num_vehicles: New number of vehicles to spawn. num_pedestrians: New number of pedestrians to spawn. map: Path to the new map file to use.

property sidewalks

Get all sidewalks in the simulation.

Returns:

List of all sidewalk objects.

simulation(physical_update_function: Callable, exit_event: Event | None = None, signal_event: Event | None = None)

Run the traffic simulation continuously.

Continuously updates the state of all simulation components at fixed time intervals.

Args:

physical_update_function: Function to update the physical state of the simulation. exit_event: Event to signal the end of the simulation. signal_event: Event to signal the end of the simulation.

spawn_objects_in_unreal_engine()

Spawn all traffic-related objects in the Unreal Engine simulation.

spawn_pedestrians()

Spawn pedestrians in the simulation environment.

spawn_traffic_signals()

Spawn traffic signals in the simulation environment.

spawn_vehicles()

Spawn vehicles in the simulation environment.

stop_simulation()

Stop the traffic simulation.

property traffic_signals

Get all traffic signals in the simulation.

Returns:

List of all traffic signal objects.

update_states()

Update the states of all traffic components from the simulation.

property vehicles

Get all vehicles in the simulation.

Returns:

List of all vehicle objects.

Module contents

Traffic controller package.

This package provides functionality for controlling and managing traffic flow. It includes tools for implementing traffic control strategies, managing traffic signals, and coordinating traffic movements within the simulation.