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 Actor Bindings

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

Overview

Boost.Python binding file that exposes the C++ Actor class hierarchy (Actor, Vehicle, Walker, WalkerAIController, TrafficSign, TrafficLight) to the CARLA Python API.

Description

This file defines the export_actor() function that registers CARLA's actor-related C++ classes with Boost.Python so they are accessible from Python. It exposes the base Actor class with properties such as id, type_id, parent, semantic_tags, actor_state, and bounding_box, along with methods for physics manipulation (add_impulse, add_force, set_simulate_physics, set_enable_gravity). The file also binds the Vehicle subclass with vehicle-specific controls (apply_control, apply_ackermann_control, set_light_state, open_door/close_door), the Walker class for pedestrian control, the WalkerAIController for autonomous pedestrian navigation, and the TrafficLight / TrafficSign classes for traffic infrastructure. Several enumerations are exposed including ActorState, VehicleLightState, VehicleWheelLocation, VehicleDoor, VehicleFailureState, and TrafficLightState.

Usage

This binding is compiled into the carla Python module and is loaded automatically when a user imports carla. It provides the Python-side classes used to interact with actors in a running simulation (e.g., spawning vehicles, applying controls, querying actor state).

Code Reference

Source Location

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

Signature

void export_actor();

// Key classes exposed:
class_<cc::Actor>("Actor", no_init)
class_<cc::Vehicle, bases<cc::Actor>>("Vehicle", no_init)
class_<cc::Walker, bases<cc::Actor>>("Walker", no_init)
class_<cc::WalkerAIController, bases<cc::Actor>>("WalkerAIController", no_init)
class_<cc::TrafficSign, bases<cc::Actor>>("TrafficSign", no_init)
class_<cc::TrafficLight, bases<cc::TrafficSign>>("TrafficLight", no_init)

Import

import carla
actor = world.get_actors()[0]  # returns carla.Actor
vehicle = world.spawn_actor(bp, transform)  # returns carla.Vehicle

I/O Contract

Inputs

Name Type Required Description
control carla.VehicleControl Yes (for apply_control) Vehicle control commands (throttle, steer, brake)
impulse carla.Vector3D Yes (for add_impulse) Impulse vector to apply to actor
force carla.Vector3D Yes (for add_force) Force vector to apply to actor
location carla.Location Yes (for set_location) New location for the actor
transform carla.Transform Yes (for set_transform) New transform for the actor

Outputs

Name Type Description
id int Unique actor identifier
type_id str Blueprint type identifier string
actor_state carla.ActorState Current state (Invalid, Active, Dormant)
bounding_box carla.BoundingBox Axis-aligned bounding box of the actor
velocity carla.Vector3D Current velocity vector

Usage Examples

import carla

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

# Spawn a vehicle
bp = world.get_blueprint_library().find('vehicle.tesla.model3')
spawn_point = world.get_map().get_spawn_points()[0]
vehicle = world.spawn_actor(bp, spawn_point)

# Apply control
control = carla.VehicleControl(throttle=1.0, steer=0.0)
vehicle.apply_control(control)

# Query state
print(vehicle.get_velocity())
print(vehicle.get_light_state())

# Open a door
vehicle.open_door(carla.VehicleDoor.FL)

# Destroy actor
vehicle.destroy()

Related Pages

Page Connections

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