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

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

Overview

YML specification file that defines sensor data classes in the CARLA Python API, including SensorData, Image, ColorConverter, CityObjectLabel, and various measurement types.

Description

This YML file specifies the data classes generated by CARLA sensors. SensorData is the base class with frame (int), timestamp (float, seconds), and transform properties. ColorConverter provides image conversion patterns (CityScapesPalette, Depth, LogarithmicDepth, Raw). CityObjectLabel enumerates semantic tags for bounding box filtering (Buildings, Vehicles, Pedestrians, etc.). Image (inheriting from SensorData) represents 32-bit BGRA camera output with fov, height, width, and raw_data properties, plus convert() and save_to_disk() methods. The file also covers CollisionEvent, GnssMeasurement, IMUMeasurement, LaneInvasionEvent, LidarMeasurement, ObstacleDetectionEvent, RadarMeasurement, and SemanticLidarMeasurement data types.

Usage

Use these classes to process data from CARLA sensors in callback functions. Each sensor type produces a specific data subclass that should be handled in the sensor's listen() callback.

Code Reference

Source Location

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

Signature

- module_name: carla
  classes:
  - class_name: SensorData
    instance_variables:
    - var_name: frame        # type: int
    - var_name: timestamp    # type: float (seconds)
    - var_name: transform    # type: carla.Transform

  - class_name: ColorConverter
    instance_variables:
    - var_name: CityScapesPalette
    - var_name: Depth
    - var_name: LogarithmicDepth
    - var_name: Raw

  - class_name: CityObjectLabel
    instance_variables:
    - var_name: Buildings
    - var_name: Pedestrians
    - var_name: Vehicles
    - var_name: TrafficSigns
    - var_name: TrafficLight
    - var_name: Any

  - class_name: Image
    parent: carla.SensorData
    instance_variables:
    - var_name: fov          # type: float (degrees)
    - var_name: height       # type: int
    - var_name: width        # type: int
    - var_name: raw_data     # type: bytes
    methods:
    - def_name: convert
    - def_name: save_to_disk

Import

import carla
# Sensor data is received via callbacks:
camera.listen(lambda image: image.save_to_disk('output/%06d.png' % image.frame))

I/O Contract

Class Source Sensor Key Properties
Image RGB/Depth/Semantic Camera fov, height, width, raw_data
CollisionEvent Collision Detector other_actor, normal_impulse
GnssMeasurement GNSS Sensor latitude, longitude, altitude
IMUMeasurement IMU Sensor accelerometer, gyroscope, compass
LaneInvasionEvent Lane Invasion Detector crossed_lane_markings
LidarMeasurement LIDAR Sensor channels, raw_data
RadarMeasurement Radar Sensor raw_data (velocity, azimuth, altitude, depth)
SemanticLidarMeasurement Semantic LIDAR channels, raw_data with semantic info

Usage Examples

import carla
import numpy as np

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

# Spawn an RGB camera
bp = world.get_blueprint_library().find('sensor.camera.rgb')
bp.set_attribute('image_size_x', '800')
bp.set_attribute('image_size_y', '600')
transform = carla.Transform(carla.Location(x=1.5, z=2.4))
vehicle = world.get_actors().filter('vehicle.*')[0]
camera = world.spawn_actor(bp, transform, attach_to=vehicle)

# Process image data
def process_image(image):
    array = np.frombuffer(image.raw_data, dtype=np.uint8)
    array = array.reshape((image.height, image.width, 4))
    image.save_to_disk('output/%06d.png' % image.frame)

camera.listen(process_image)

Related Pages

Page Connections

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