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 Visualize Radar Example

From Leeroopedia
Knowledge Sources
Domains Sensor Visualization, Example Scripts
Last Updated 2026-02-15 05:00 GMT

Overview

A Python example script that visualizes radar sensor detections as colored 3D points in the CARLA simulation, with color encoding relative velocity.

Description

This script spawns a vehicle with an attached radar sensor and visualizes detections in real-time using CARLA's debug drawing. The radar_callback(radar_data, world) function processes each radar detection by converting azimuth and altitude angles from radians to degrees, computing the 3D position of the detection point relative to the radar sensor transform, and drawing colored points. The color encoding maps detection velocity to an RGB gradient: red for approaching objects (positive velocity), green for stationary objects, and blue for receding objects, normalized against a 7.5 m/s reference. The main function sets up synchronous mode (0.05s delta), spawns a Lincoln vehicle with autopilot, configures a radar sensor with customizable horizontal_fov, vertical_fov, points_per_second, and range attributes, and follows the vehicle with a trailing spectator camera. The spectator camera offset is computed using the vehicle's yaw to maintain a chase view. A pygame clock manages the 20 FPS tick rate.

Usage

Use this script to visualize and understand radar sensor behavior in CARLA, debug radar configurations, or demonstrate how radar data can be processed for object detection.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/examples/visualize_radar.py

Signature

def radar_callback(radar_data, world):
    """Process radar detections and draw colored points in the world."""

def main():
    """Set up vehicle, radar sensor, and visualization loop."""

Import

# Run as standalone script
python visualize_radar.py -hfov 35 -vfov 20 -pps 1500 -r 100

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)
-hfov str No Radar horizontal field of view in degrees (default: 35)
-vfov str No Radar vertical field of view in degrees (default: 20)
-pps str No Radar points per second (default: 1500)
-r str No Radar maximum range in meters (default: 100)

Outputs

Name Type Description
Debug points Visual Colored 3D points representing radar detections
Color encoding Visual Red=approaching, Green=stationary, Blue=receding

Usage Examples

# Run with default radar settings
# python visualize_radar.py

# Custom radar configuration
# python visualize_radar.py -hfov 60 -vfov 30 -pps 3000 -r 200

# Radar callback processing pattern
def radar_callback(radar_data, world):
    for detect in radar_data:
        # detect.azimuth - horizontal angle in radians
        # detect.altitude - vertical angle in radians
        # detect.depth - distance in meters
        # detect.velocity - relative velocity in m/s
        pass

Related Pages

Page Connections

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