Heuristic:CARLA simulator Carla Traffic Manager Sync Mode
| Knowledge Sources | |
|---|---|
| Domains | Simulation, Debugging |
| Last Updated | 2026-02-15 07:00 GMT |
Overview
When the world runs in synchronous mode, the Traffic Manager must also be set to synchronous mode to prevent traffic from freezing or behaving erratically.
Description
CARLA's Traffic Manager (TM) runs as a separate subsystem that controls autopilot vehicles. By default, TM operates asynchronously. When the world is set to synchronous mode, TM must be explicitly synchronized as well, otherwise the TM will not advance with each `world.tick()` call. This causes autopilot vehicles to freeze in place or exhibit jittery movement. The synchronization is achieved by calling `traffic_manager.set_synchronous_mode(True)` before applying world settings.
Usage
Use this heuristic whenever combining synchronous mode with Traffic Manager autopilot vehicles. This applies to:
- Traffic generation scripts that use synchronous mode
- Sensor data collection where deterministic traffic behavior is needed
- Any scenario where `vehicle.set_autopilot(True)` is used alongside `settings.synchronous_mode = True`
The Insight (Rule of Thumb)
- Action: Call `traffic_manager.set_synchronous_mode(True)` before enabling synchronous mode on the world.
- Value: Boolean flag, matches world's synchronous mode state.
- Trade-off: TM sync mode ties traffic updates to `world.tick()`, meaning traffic won't advance between ticks. This is the desired behavior for deterministic simulations.
- Cleanup: When disabling synchronous mode, also disable TM sync mode and restore `fixed_delta_seconds = None`.
Reasoning
The generate_traffic.py example at line 127 demonstrates the correct order: set TM sync mode first, then enable world sync mode. The finally block at lines 300-305 shows the cleanup pattern: disable sync mode and reset delta seconds. Running async traffic in a sync world is explicitly warned against at line 135: "You are currently in asynchronous mode, and traffic might experience some issues".
# PythonAPI/examples/generate_traffic.py:125-136
settings = world.get_settings()
if not args.asynch:
traffic_manager.set_synchronous_mode(True)
if not settings.synchronous_mode:
synchronous_master = True
settings.synchronous_mode = True
settings.fixed_delta_seconds = 0.05
else:
synchronous_master = False
else:
print("You are currently in asynchronous mode, and traffic might experience some issues")
# PythonAPI/examples/generate_traffic.py:300-305 (cleanup)
if not args.asynch and synchronous_master:
settings = world.get_settings()
settings.synchronous_mode = False
settings.no_rendering_mode = False
settings.fixed_delta_seconds = None
world.apply_settings(settings)