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.

Principle:CARLA simulator Carla Obstacle Detection

From Leeroopedia
Revision as of 17:28, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/CARLA_simulator_Carla_Obstacle_Detection.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Computational Geometry, Obstacle Detection, Autonomous Driving
Last Updated 2026-02-15 00:00 GMT

Overview

Obstacle Detection in the CARLA navigation agent is a geometric approach to determining whether vehicles, pedestrians, or other actors pose a collision threat along the ego vehicle's planned route. Rather than using sensor-based perception (cameras, LiDAR), the agent leverages CARLA's server-side ground truth to query actor positions and bounding boxes, then tests for spatial intersection with a corridor polygon generated from the planned route waypoints.

Description

The obstacle detection system operates at each simulation step within the agent's run_step() loop. It performs the following logical sequence:

  1. Actor enumeration: Queries the CARLA world for all vehicles and/or walkers within a maximum detection distance of the ego vehicle.
  1. Route corridor construction: From the upcoming waypoints in the local planner's queue, constructs a rectangular corridor polygon using the Shapely library. The corridor extends along the route direction with a width corresponding to the lane width, optionally offset for adjacent lane checking.
  1. Bounding box projection: For each candidate actor, projects its 3D bounding box onto the 2D ground plane to create a Shapely polygon representing the actor's footprint.
  1. Intersection testing: Tests whether each actor's projected bounding box intersects the route corridor polygon. If an intersection is found, the actor is classified as an obstacle.
  1. Angular filtering: Applies vertical angle thresholds (up_angle_th and low_angle_th) to filter out actors that are on different elevation levels (e.g., vehicles on overpasses or underpasses) even though their 2D projections may overlap.
  1. Result: Returns a tuple of (is_obstacle_detected, blocking_actor, distance) for the closest detected obstacle.

Usage

Use obstacle detection when you need to:

  • Determine whether the ego vehicle should brake or stop due to vehicles or pedestrians ahead
  • Implement collision avoidance in an autonomous driving pipeline
  • Check adjacent lanes for vehicles before performing a lane change
  • Evaluate traffic density along the planned route

Theoretical Basis

Corridor-Based Geometric Detection

The detection uses a swept polygon approach. Given a sequence of upcoming waypoints W = [w_0, w_1, ..., w_n], the corridor is constructed by:

For each waypoint w_i:
    right_i = w_i.position + (lane_width/2) * right_vector(w_i)
    left_i  = w_i.position - (lane_width/2) * right_vector(w_i)

corridor = Polygon(
    [right_0, right_1, ..., right_n, left_n, ..., left_1, left_0]
)

The right vector is computed as the perpendicular to the waypoint's forward direction in the ground plane.

Bounding Box Intersection

For each candidate actor A with bounding box B:

footprint_A = project_to_2d(bounding_box(A))
is_obstacle = corridor.intersects(footprint_A)

The Shapely library's intersects() method performs the geometric predicate efficiently using the DE-9IM (Dimensionally Extended 9-Intersection Model) spatial relationship model.

Angular Filtering for Elevation

To handle multi-level road structures (bridges, tunnels, overpasses), the detection computes the vertical angle between the ego vehicle and each candidate actor:

delta_z = actor.z - ego.z
horizontal_dist = sqrt((actor.x - ego.x)^2 + (actor.y - ego.y)^2)
angle = atan2(delta_z, horizontal_dist)

is_same_level = (low_angle_th <= angle <= up_angle_th)

Only actors passing both the polygon intersection test and the angular filter are reported as obstacles.

Complexity

For k candidate actors and a corridor built from m waypoints:

  • Corridor construction: O(m)
  • Per-actor intersection test: O(m) worst case for polygon intersection (though typically much faster with Shapely's spatial indexing)
  • Total per-step: O(k * m)

In practice, the maximum detection distance pre-filters the actor list, keeping k small (typically < 20 actors).

Related Pages

Implemented By

Page Connections

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