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

From Leeroopedia
Revision as of 12:14, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CARLA_simulator_Carla_Python_Control_Bindings.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Python Bindings, Vehicle Control, Physics
Last Updated 2026-02-15 05:00 GMT

Overview

Control.cpp provides the Boost.Python bindings that expose CARLA's vehicle and walker control types, physics control parameters, and related RPC structures to the Python API.

Description

This binding file exposes a comprehensive set of vehicle physics and control types to Python. The implementation includes:

Helper Functions for List Conversion

  • GetVectorOfVector2DFromList -- Converts Python lists to std::vector<carla::geom::Vector2D>, supporting both direct Vector2D extraction and tuple-based construction.
  • GetVectorOfBoneTransformFromList -- Converts Python lists to std::vector<carla::rpc::BoneTransformDataIn> for walker bone control.

VehiclePhysicsControl Property Accessors

Static getter/setter pairs for complex properties that require Python list conversion:

  • GetWheels / SetWheels -- Converts between C++ vector of WheelPhysicsControl and Python lists.
  • GetForwardGearRatios / SetForwardGearRatios -- Forward gear ratio list conversion.
  • GetReverseGearRatios / SetReverseGearRatios -- Reverse gear ratio list conversion.
  • GetTorqueCurve / SetTorqueCurve -- Torque curve (Vector2D points) conversion.
  • GetSteeringCurve / SetSteeringCurve -- Steering curve (Vector2D points) conversion.

VehiclePhysicsControl Init

The VehiclePhysicsControl_init function implements a custom Python __init__ with keyword arguments supporting over 29 parameters including: torque_curve, max_torque, max_rpm, idle_rpm, brake_effect, rev_up_moi, rev_down_rate, differential_type, front_rear_split, use_automatic_gears, gear_change_time, final_ratio, forward_gear_ratios, reverse_gear_ratios, mass, drag_coefficient, center_of_mass, steering_curve, wheels, use_sweep_wheel_collision, and more.

Usage

This file is compiled as part of the CARLA Python module. Once built, Python users can create and manipulate VehicleControl, VehicleAckermannControl, WalkerControl, VehiclePhysicsControl, and WheelPhysicsControl objects directly from Python.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/carla/src/Control.cpp (491 lines)

Signature

// Key helper functions
static auto GetVectorOfVector2DFromList(const boost::python::list &list);
static auto GetVectorOfBoneTransformFromList(const boost::python::list &list);

// VehiclePhysicsControl property accessors
static auto GetWheels(const carla::rpc::VehiclePhysicsControl &self);
static void SetWheels(carla::rpc::VehiclePhysicsControl &self, const boost::python::list &list);
static auto GetTorqueCurve(const carla::rpc::VehiclePhysicsControl &self);
static void SetTorqueCurve(carla::rpc::VehiclePhysicsControl &self, const boost::python::list &list);
static auto GetSteeringCurve(const carla::rpc::VehiclePhysicsControl &self);
static void SetSteeringCurve(carla::rpc::VehiclePhysicsControl &self, const boost::python::list &list);
static auto GetForwardGearRatios(const carla::rpc::VehiclePhysicsControl &self);
static void SetForwardGearRatios(carla::rpc::VehiclePhysicsControl &self, const boost::python::list &list);
static auto GetReverseGearRatios(const carla::rpc::VehiclePhysicsControl &self);
static void SetReverseGearRatios(carla::rpc::VehiclePhysicsControl &self, const boost::python::list &list);

// Custom __init__ for VehiclePhysicsControl
boost::python::object VehiclePhysicsControl_init(boost::python::tuple args, boost::python::dict kwargs);

Import

#include <PythonAPI.h>

I/O Contract

Inputs

Name Type Required Description
list boost::python::list Yes Python list of values to convert to C++ vectors
self carla::rpc::VehiclePhysicsControl& Yes The physics control object being modified
args boost::python::tuple Yes Positional arguments for VehiclePhysicsControl init
kwargs boost::python::dict No Keyword arguments (torque_curve, max_torque, mass, etc.)

Outputs

Name Type Description
Python list boost::python::list Converted C++ vectors as Python lists (for getters)
VehiclePhysicsControl Python object Initialized physics control object (for __init__)

Usage Examples

import carla

# Create vehicle physics control from Python
physics = carla.VehiclePhysicsControl(
    torque_curve=[carla.Vector2D(0, 400), carla.Vector2D(1300, 600)],
    max_rpm=5000.0,
    mass=1500.0,
    drag_coefficient=0.3,
    use_automatic_gears=True
)

# Apply control to a vehicle
vehicle.apply_physics_control(physics)

# Create vehicle control
control = carla.VehicleControl(throttle=0.5, steer=0.0, brake=0.0)
vehicle.apply_control(control)

Related Pages

Page Connections

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