Classes

CarlaClient

class CarlaClient(ip, port, timeout)[source]

Bases: object

Communication interface for the CARLA simulator.

This class handles the connection to the CARLA server, identifies the player vehicle (tagged as ‘hero’), and extracts real-time simulation data required for the sound engine and logic processing.

client

The official CARLA client instance. carla.Client

Type:

carla.Client

world

The current simulation world instance. carla.World

Type:

carla.World

vehicle

The identified player vehicle. carla.Vehicle

Type:

carla.Vehicle

collision_sensor

Sensor for detecting impact events. Collision detector

Type:

CollisionSensor

crash_counter

Counter to track the number of collisions.

Type:

int

honk_trigger

State tracker for the horn input logic.

Type:

bool

retrieve_data()[source]

Extracts and aggregates simulation state data into a telemetry packet.

This method polls the CARLA world for environmental conditions (weather), monitors hardware/keyboard inputs (honk), and fetches real-time vehicle physics. It also manages the lifecycle of the collision sensor and processes collision impulses based on defined intensity thresholds.

The resulting data packet is formatted for downstream consumption, typically for synchronization with the FMOD audio engine.

Returns:

A dictionary containing telemetry data, or None if no vehicle is found or initialized.

Telemetry dictionary keys:
  • speed (float): Vehicle speed in km/h.

  • throttle (float): Throttle position [0.0, 1.0].

  • brake (float): Brake position [0.0, 1.0].

  • speed_limit (float): Current road speed limit.

  • gear (int): Current active gear.

  • collision_event (bool): True if a collision above intensity 100 is detected.

  • rain_intensity (float): Precipitation amount [0, 100].

  • wind_intensity (float): Wind strength [0, 100].

  • acceleration (float): Lateral acceleration (Y-axis).

  • honk (bool): Single-trigger state of the horn.

  • handbrake (bool): State of the handbrake.

Return type:

dict or None

Raises:

AttributeError – Handled internally if vehicle reference is lost during actor switching or rapid simulation resets.

set_rain(in_rain_intensity)[source]

Adjusts the precipitation and road wetness levels in the simulation.

This method updates the CARLA weather parameters simultaneously to ensure visual rain matches the physical road conditions (puddles/friction).

Parameters:

in_rain_intensity (float/int) – The intensity of the rain. Typically a value between 0 (none) and 100 (heavy).

Returns:

None

set_wind(in_wind_intensity=0)[source]

Sets the wind intensity for the simulation environment.

Updates the physical wind force acting on actors and environmental elements like trees or rain particles.

Parameters:

in_wind_intensity (float/int, optional) – The wind strength. Ranges from 0 to 100. Defaults to 0.

Returns:

None

CollisionSensor

class CollisionSensor(parent_actor)[source]

Bases: object

Sensor responsible for detecting and logging vehicle collisions.

This class wraps a CARLA collision sensor, attaching it to a parent vehicle to monitor physical impacts. It maintains a rolling history of collision intensities and uses class-level variables to track global collision events.

collision_counter = 0

A global counter incremented on every collision event.

Type:

int

intensity = 0

The magnitude (Euclidean norm) of the last detected collision impulse.

Type:

float

__init__(parent_actor)[source]

Initializes the sensor and attaches it to the parent actor.

Parameters:

parent_actor (carla.Actor) – The vehicle actor to which the collision sensor will be attached.

get_collision_history()[source]

Retrieves the collision history.

Returns:

A mapping of simulation frames to the total collision intensity recorded during that frame.

Return type:

collections.defaultdict

Socket

class Socket[source]

Bases: object

Handles UDP networking for broadcasting simulation telemetry.

This class initializes a local UDP socket to transmit JSON-encoded data packets. It acts as the primary transmitter for sending CARLA vehicle states and environmental data to external listeners, such as the FMOD integration layer.

UDP_IP

The destination IP address (default: “127.0.0.1”).

Type:

str

UDP_PORT

The destination port number (default: 5005).

Type:

int

__init__()[source]

Initializes the UDP socket and sets network parameters.

publish_data(data_packet)[source]

Serializes and sends a data packet over the UDP socket.

Converts a dictionary-based data packet into a JSON string, encodes it into bytes, and transmits it to the pre-configured IP and Port.

Parameters:

data_packet (dict) – The telemetry data dictionary generated by the CarlaClient’s retrieve_data method.

Returns:

None

Weather

class Weather(client)[source]

Bases: object

A graphical user interface for real-time CARLA weather manipulation.

This class creates a Tkinter-based window with sliders to dynamically adjust environmental parameters in the simulation. It maps UI inputs directly to the control methods of a provided CARLA client.

client

An instance of the CARLA client (e.g., CarlaClient) responsible for executing weather updates.

root

The main Tkinter window instance.

Type:

Tk

__init__(client)[source]

Initializes the Weather UI with a reference to the simulation client.

Parameters:

client – The client object containing set_rain and set_wind methods to be controlled via the UI sliders.

run()[source]

Starts the Tkinter event loop to display the weather control window.

This method blocks execution until the window is closed.