Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Python TrafficManager Bindings

From Leeroopedia
Knowledge Sources
Domains Python Bindings, Traffic Management
Last Updated 2026-02-15 05:00 GMT

Overview

Boost.Python binding file that exposes the CARLA Traffic Manager to the Python API for controlling autonomous vehicle behavior.

Description

This file defines the export_trafficmanager() function that registers the TrafficManager class. It exposes per-vehicle behavior control: vehicle_percentage_speed_difference, vehicle_lane_offset, set_desired_speed, update_vehicle_lights, collision_detection, force_lane_change, auto_lane_change, distance_to_leading_vehicle, and percentage-based rule violation (ignore_walkers_percentage, ignore_vehicles_percentage, ignore_lights_percentage, ignore_signs_percentage, keep_slow_lane_rule_percentage, random_left_lanechange_percentage, random_right_lanechange_percentage). Global settings include global_percentage_speed_difference, global_lane_offset, set_global_distance_to_leading_vehicle, set_synchronous_mode, set_hybrid_physics_mode/set_hybrid_physics_radius, set_random_device_seed, and set_osm_mode. Path and route control is provided via set_path and set_route. Dormant vehicle management uses set_respawn_dormant_vehicles and set_boundaries_respawn_dormant_vehicles. Action queries use get_next_action and get_all_actions. Helper functions convert between Python lists and C++ types for custom paths and RoadOption routes.

Usage

The Traffic Manager is used to configure the behavior of vehicles running in autopilot mode, controlling their speed, lane changing, traffic rule compliance, and custom routes.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/carla/src/TrafficManager.cpp

Signature

void export_trafficmanager();

// Key class exposed:
class_<ctm::TrafficManager>("TrafficManager", no_init)

Import

import carla
tm = client.get_trafficmanager(8000)

I/O Contract

Inputs

Name Type Required Description
actor carla.Actor Yes (per-vehicle methods) Vehicle actor to configure
percentage float Yes (speed_difference) Speed difference percentage (-100 to 100)
distance float Yes (distance_to_leading_vehicle) Following distance in meters
mode_switch bool Yes (set_synchronous_mode) Enable/disable synchronous mode
path list[carla.Location] Yes (set_path) Custom path waypoints

Outputs

Name Type Description
port int Traffic Manager port number
next_action list [RoadOption_string, carla.Waypoint] pair
all_actions list[list] Buffer of upcoming [RoadOption, Waypoint] pairs

Usage Examples

import carla

client = carla.Client('localhost', 2000)
world = client.get_world()
tm = client.get_trafficmanager(8000)

# Enable synchronous mode
tm.set_synchronous_mode(True)

# Configure vehicle behavior
vehicle.set_autopilot(True)
tm.vehicle_percentage_speed_difference(vehicle, -20)  # 20% faster
tm.distance_to_leading_vehicle(vehicle, 5.0)
tm.auto_lane_change(vehicle, True)
tm.ignore_lights_percentage(vehicle, 0)

# Set global speed limit
tm.global_percentage_speed_difference(10)  # 10% slower globally

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment