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 Client Show Recorder Collisions

From Leeroopedia
Knowledge Sources
Domains Simulation, Recording
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for querying collision events and blocked actor detection from a CARLA recording file provided by the CARLA simulator.

Description

This implementation covers two complementary event query methods:

Client.show_recorder_collisions filters a recording file for collision events between actors of specified types. Each actor type is represented by a single-character code: h (Hero), v (Vehicle), w (Walker), t (TrafficLight), o (Other), a (Any). The method returns a formatted string listing each collision with its timestamp, the IDs and types of the actors involved.

Client.show_recorder_actors_blocked scans a recording file for actors that remained near-stationary for longer than a specified duration and distance threshold. This detects stuck or deadlocked vehicles. The method returns a formatted string listing each blocked actor with its ID, type, the time at which blocking was detected, and the duration of the blocking event.

Both methods operate on the recording file without performing a replay, making them efficient tools for post-hoc analysis of recorded scenarios.

Usage

Use show_recorder_collisions to find collision events for safety analysis, to identify which actors were involved in crashes, and to determine the timestamps of collisions for targeted replay. Use show_recorder_actors_blocked to detect pathfinding failures, traffic deadlocks, or other anomalies where vehicles become permanently stuck during a scenario.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/carla/src/Client.cpp:L207-208, LibCarla/source/carla/client/Client.h:L133-139

Signature

Client.show_recorder_collisions(filename: str, type1: str, type2: str) -> str

Client.show_recorder_actors_blocked(filename: str, min_time: float, min_distance: float) -> str

Import

import carla

I/O Contract

Inputs

show_recorder_collisions:

Name Type Required Description
filename str Yes Path or name of the recording file to query.
type1 str Yes Single-character type code for the first actor category. Valid codes: h (Hero), v (Vehicle), w (Walker), t (TrafficLight), o (Other), a (Any).
type2 str Yes Single-character type code for the second actor category. Same valid codes as type1.

show_recorder_actors_blocked:

Name Type Required Description
filename str Yes Path or name of the recording file to query.
min_time float Yes Minimum time in seconds an actor must be near-stationary to be considered blocked.
min_distance float Yes Minimum distance in meters. Actors that moved less than this distance over min_time seconds are considered blocked.

Outputs

Name Type Description
return (collisions) str Formatted multi-line string listing each collision event with timestamp, actor IDs, and actor types.
return (blocked) str Formatted multi-line string listing each blocked actor with ID, type, detection time, and blocking duration.

Usage Examples

Basic Example

import carla

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

filename = "traffic_scenario_01.log"

# Find all vehicle-to-vehicle collisions
vv_collisions = client.show_recorder_collisions(filename, "v", "v")
print("Vehicle-Vehicle Collisions:")
print(vv_collisions)

# Example output:
# Version: 1
# Map: Town03
#   Time  Types     Id Actor 1                     Id Actor 2
#  12.30  v   v     42 vehicle.tesla.model3         67 vehicle.audi.a2
#  35.80  v   v     51 vehicle.bmw.grandtourer      42 vehicle.tesla.model3

Query All Collision Types

import carla

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

filename = "urban_scenario.log"

# Vehicle-pedestrian collisions (safety-critical)
vw_collisions = client.show_recorder_collisions(filename, "v", "w")
print("Vehicle-Pedestrian Collisions:")
print(vw_collisions)

# All collisions involving the hero vehicle
hero_collisions = client.show_recorder_collisions(filename, "h", "a")
print("Hero Vehicle Collisions:")
print(hero_collisions)

# All collisions of any type
all_collisions = client.show_recorder_collisions(filename, "a", "a")
print("All Collisions:")
print(all_collisions)

Detect Blocked Actors

import carla

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

filename = "long_scenario.log"

# Find actors stuck for more than 30 seconds within 1 meter
blocked = client.show_recorder_actors_blocked(filename, 30.0, 1.0)
print("Blocked Actors (>30s, <1m movement):")
print(blocked)

# Example output:
# Version: 1
# Map: Town05
#   Time     Id Actor
#  120.50    89 vehicle.carlamotors.carlacola
#  245.10   102 vehicle.volkswagen.t2

# Use more sensitive thresholds to catch shorter blocking events
short_blocked = client.show_recorder_actors_blocked(filename, 10.0, 0.5)
print("Actors blocked briefly (>10s, <0.5m movement):")
print(short_blocked)

Complete Analysis Pipeline

import carla
import time

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

filename = "highway_merge_scenario.log"

# Step 1: Get recording overview
info = client.show_recorder_file_info(filename, show_all=False)
print("=== Recording Info ===")
print(info)

# Step 2: Find all vehicle-vehicle collisions
collisions = client.show_recorder_collisions(filename, "v", "v")
print("\n=== Vehicle-Vehicle Collisions ===")
print(collisions)

# Step 3: Find blocked vehicles (possible traffic jams)
blocked = client.show_recorder_actors_blocked(filename, 20.0, 2.0)
print("\n=== Blocked Vehicles ===")
print(blocked)

# Step 4: Replay the first collision in slow motion
# Parse collision output to extract time and actor IDs
# Suppose first collision at t=25.7s, actor 42
collision_time = 25.7
actor_id = 42

print(f"\n=== Replaying collision at t={collision_time}s ===")
client.replay_file(
    filename,
    start_time=max(0.0, collision_time - 5.0),
    duration=10.0,
    follow_id=actor_id
)
client.set_replayer_time_factor(0.2)  # Slow-motion at 20% speed
time.sleep(50)  # 10 sim-seconds at 0.2x

print("Analysis complete")

Related Pages

Implements Principle

Page Connections

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