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

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

Overview

Boost.Python binding file that exposes the ActorSnapshot and WorldSnapshot classes to the CARLA Python API for querying simulation state at a point in time.

Description

This file defines the export_snapshot() function that registers snapshot classes. ActorSnapshot provides a read-only id field and methods get_transform(), get_velocity(), get_angular_velocity(), and get_acceleration() to retrieve an actor's state at a specific simulation tick. WorldSnapshot provides id, frame, timestamp (with sub-properties frame_count, elapsed_seconds, delta_seconds, platform_timestamp for backwards compatibility), has_actor(actor_id) to check actor presence, find(actor_id) to locate a specific actor's snapshot, and supports len() and iteration via Python protocols. The file also defines operator<< overloads for readable string representations of both snapshot types.

Usage

Snapshots are used for querying the full simulation state at a given frame without making individual RPC calls per actor, which is particularly useful in synchronous mode where world.tick() returns a WorldSnapshot.

Code Reference

Source Location

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

Signature

void export_snapshot();

// Key classes exposed:
class_<cc::ActorSnapshot>("ActorSnapshot", no_init)
class_<cc::WorldSnapshot>("WorldSnapshot", no_init)

Import

import carla
snapshot = world.get_snapshot()
# or in synchronous mode:
snapshot = world.tick()

I/O Contract

Inputs

Name Type Required Description
actor_id int Yes (for has_actor/find) Actor identifier to look up

Outputs

Name Type Description
id int Unique snapshot identifier
frame int Simulation frame number
timestamp carla.Timestamp Timing information for this frame
actor_snapshot carla.ActorSnapshot Per-actor state data (transform, velocity, etc.)

Usage Examples

import carla

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

# Get current world snapshot
snapshot = world.get_snapshot()
print(f"Frame: {snapshot.frame}, Elapsed: {snapshot.timestamp.elapsed_seconds}")

# Find a specific actor in the snapshot
actor_snapshot = snapshot.find(vehicle.id)
if actor_snapshot:
    print(f"Vehicle transform: {actor_snapshot.get_transform()}")
    print(f"Vehicle velocity: {actor_snapshot.get_velocity()}")

# Iterate over all actor snapshots
for actor_snap in snapshot:
    print(f"Actor {actor_snap.id}: {actor_snap.get_transform()}")

Related Pages

Page Connections

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