Implementation:CARLA simulator Carla Lane Explorer Example
| Knowledge Sources | |
|---|---|
| Domains | Map Visualization, Example Scripts |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
A Python example script that sequentially visualizes OpenDRIVE road data by randomly exploring waypoints, lanes, and junctions with debug drawing in the CARLA simulator.
Description
This script connects to a CARLA server and performs a random walk through the road network using the waypoint API. Starting from a user-specified location, it generates candidate next waypoints (including lane changes when available), randomly selects one, and renders the path using debug drawing primitives. The script visualizes chosen paths in cyan/green, rejected alternatives in red, directional transforms in white, and junction bounding boxes in orange. Helper functions include draw_transform for directional arrows, draw_waypoint_union for connecting waypoints with lines, draw_waypoint_info for lane/road ID text labels, and draw_junction for rendering junction bounding boxes with begin/end waypoint pairs. The exploration checks lane_change properties and lane_type to determine valid driving lanes. Command-line arguments control host, port, starting position (x, y, z), random seed, tick time, and information display.
Usage
Use this script to visually explore and understand the road network topology of any CARLA map, inspect lane configurations, examine junction structures, and verify OpenDRIVE data correctness.
Code Reference
Source Location
- Repository: CARLA
- File: PythonAPI/examples/lane_explorer.py
Signature
def draw_transform(debug, trans, col=carla.Color(255, 0, 0), lt=-1)
def draw_waypoint_union(debug, w0, w1, color=carla.Color(255, 0, 0), lt=5)
def draw_waypoint_info(debug, w, lt=5)
def draw_junction(debug, junction, l_time=10)
def main()
Import
# Run as standalone script
python lane_explorer.py --host localhost -p 2000 -x 100 -y 200
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --host | str | No | CARLA server IP (default: 127.0.0.1) |
| --port | int | No | CARLA server port (default: 2000) |
| -x, -y, -z | float | No | Starting position coordinates (default: 0.0) |
| --seed | int | No | Random seed for reproducible exploration |
| --tick-time | float | No | Delay between waypoint steps in seconds (default: 0.2) |
| -i, --info | flag | No | Show lane/road text information |
Outputs
| Name | Type | Description |
|---|---|---|
| Debug lines | Visual | Colored lines connecting explored waypoints |
| Debug arrows | Visual | Directional arrows at each waypoint |
| Junction boxes | Visual | Orange bounding boxes for junctions |
| Text labels | Visual | Lane ID, road ID, and lane change information |
Usage Examples
# Explore starting from the origin with lane info
# python lane_explorer.py -x 0 -y 0 -z 0 --info --seed 42
# Explore from a specific map location
# python lane_explorer.py -x 100 -y -50 --tick-time 0.5