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 Commands API Spec

From Leeroopedia
Knowledge Sources
Domains Simulation, Autonomous Driving, API Specification
Last Updated 2026-02-15 05:00 GMT

Overview

YML specification file that defines the command module classes used for batch operations in the CARLA Python API, including SpawnActor, DestroyActor, ApplyVehiclePhysicsControl, ApplyVehicleControl, and Response.

Description

This YML file specifies the command classes under the command module that enable batch execution of simulation operations via client.apply_batch() and client.apply_batch_sync(). The Response class reports success (actor_id) or failure (error string) for each command. SpawnActor spawns actors with a blueprint and transform, optionally attached to a parent, and supports chaining via the then() method. DestroyActor removes actors by ID. ApplyVehiclePhysicsControl and ApplyVehicleControl modify vehicle physics and driving controls respectively. These commands allow efficient batch spawning, destruction, and configuration of many actors in a single simulation step.

Usage

Use these command classes with client.apply_batch() or client.apply_batch_sync() to perform efficient batch operations. This is particularly useful for spawning or destroying many actors at once, such as in traffic generation scripts.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/docs/commands.yml

Signature

- module_name: command
  classes:
  - class_name: Response
    instance_variables:
    - var_name: actor_id       # type: int
    - var_name: error          # type: str
    methods:
    - def_name: has_error       # return: bool

  - class_name: SpawnActor
    instance_variables:
    - var_name: transform      # type: carla.Transform
    - var_name: parent_id      # type: int
    methods:
    - def_name: __init__(blueprint, transform)
    - def_name: __init__(blueprint, transform, parent)
    - def_name: then(command)

  - class_name: DestroyActor
    instance_variables:
    - var_name: actor_id       # type: int

  - class_name: ApplyVehiclePhysicsControl
    instance_variables:
    - var_name: actor_id           # type: int
    - var_name: physics_control    # type: carla.VehiclePhysicsControl

  - class_name: ApplyVehicleControl

Import

import carla
SpawnActor = carla.command.SpawnActor
DestroyActor = carla.command.DestroyActor

I/O Contract

Class Input Output Description
SpawnActor blueprint, transform, [parent] actor_id via Response Spawns an actor into the simulation
DestroyActor actor or actor_id bool via Response Destroys an actor
ApplyVehiclePhysicsControl actor, physics_control None Applies physics parameters to vehicle
ApplyVehicleControl actor, control None Applies driving controls to vehicle
Response N/A actor_id or error Result of a batch command execution

Usage Examples

import carla

client = carla.Client('localhost', 2000)
world = client.get_world()
bp_lib = world.get_blueprint_library()
spawn_points = world.get_map().get_spawn_points()

# Batch spawn with autopilot chaining
SpawnActor = carla.command.SpawnActor
SetAutopilot = carla.command.SetAutopilot
FutureActor = carla.command.FutureActor

batch = []
for i, sp in enumerate(spawn_points[:10]):
    bp = bp_lib.filter('vehicle.*')[i % len(bp_lib.filter('vehicle.*'))]
    batch.append(SpawnActor(bp, sp).then(SetAutopilot(FutureActor, True)))

results = client.apply_batch_sync(batch, True)
vehicles = [r.actor_id for r in results if not r.has_error()]

# Batch destroy
batch = [carla.command.DestroyActor(v) for v in vehicles]
client.apply_batch_sync(batch)

Related Pages

Page Connections

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