Implementation:CARLA simulator Carla World Apply Settings For Sync
| Knowledge Sources | |
|---|---|
| Domains | Simulation, Perception |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for enabling synchronous simulation mode to ensure deterministic, tick-based sensor data collection provided by the CARLA simulator.
Description
World.apply_settings() configures the simulation world with a WorldSettings object that controls the execution model. For sensor data collection, the critical settings are synchronous_mode (set to True) and fixed_delta_seconds (set to the desired timestep). When applied, the server transitions to synchronous execution, requiring explicit World.tick() calls to advance. The method returns the ID of the frame in which the settings take effect, allowing the client to confirm the transition.
This is the same underlying API used for general simulation configuration, but in the context of sensor data collection, the focus is on ensuring that every sensor produces exactly one observation per tick and that all observations are temporally aligned.
Usage
This method is called at the beginning of any sensor data collection workflow, before spawning sensors or beginning the data recording loop. It must also be reverted at the end of collection to restore asynchronous mode for other clients.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/client/World.cpp - Lines: L56-84
Signature
World.apply_settings(settings: carla.WorldSettings) -> int
Import
import carla
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| settings | carla.WorldSettings | Yes | Configuration object. Key attributes for sensor data collection: synchronous_mode (bool) and fixed_delta_seconds (float, in seconds). |
Outputs
| Name | Type | Description |
|---|---|---|
| frame_id | int | The simulation frame ID at which the new settings take effect. Can be used to verify that the mode switch has been applied. |
Usage Examples
Basic Example
import carla
# Connect to the CARLA server
client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()
# Save original settings for restoration later
original_settings = world.get_settings()
# Configure synchronous mode for sensor data collection
settings = world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = 0.05 # 20 Hz tick rate
# Apply and confirm
frame_id = world.apply_settings(settings)
print(f"Synchronous mode active from frame {frame_id}")
# ... perform sensor data collection ...
# Restore original settings when done
world.apply_settings(original_settings)
Sensor Collection Timestep Selection
import carla
client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()
original_settings = world.get_settings()
# Choose timestep based on sensor requirements:
# 0.05s = 20 Hz (typical for camera + LiDAR fusion)
# 0.1s = 10 Hz (typical for LiDAR-only collection)
# 0.02s = 50 Hz (high-rate IMU/GNSS collection)
settings = world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = 0.05
world.apply_settings(settings)
try:
# Collect 200 frames of sensor data (10 seconds at 20 Hz)
for frame_num in range(200):
world.tick()
# Sensor callbacks fire here with aligned data
finally:
# Always restore original settings
world.apply_settings(original_settings)