You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
7.1 KiB
7.1 KiB
Fox CARLA ADAS Simulation Project: Agent Intelligence (gemini.md)
This document is the consolidated source of truth for AI agents working on the Fox CARLA Simulation project. It combines high-level architecture, component-level details, and best practices.
🏗️ 1. Project Overview & Architecture
Objective: A modular, scenario-driven simulation framework built on CARLA 0.9.16 for demonstrating structured ADAS driving scenarios with multi-modal sensor data.
The Pipeline:
CARLA Simulator → Multi-Sensor Capture → Dataset (PNG/NPY/JSONL) → [SHENRON SYNTHESIS] → MCAP Conversion → Foxglove Visualization
Repository Layout
dashboard.bat: One-click launcher for the Flask GUI orchestrator.run.bat: One-click runner for the simulation (activatescarla312conda env).config.py: Global simulation constants (FPS, sensor specs, ego model).src/main.py: Thin CLI wrapper for thePipelineManager.src/pipeline/: [NEW] Core stage-based architecture (Manager + Stages).src/processing/: [NEW] Centralized physics and sensor augmentation logic.src/sensors.py:SensorManager— Handles camera, radar, and lidar sync.src/recorder.py:Recorder— Serializes raw frames to disk asynchronously.scenarios/: Contains scenario implementations (e.g.,braking.py,cutin.py,showcase.py).scripts/: Utility scripts for data processing (e.g.,data_to_mcap.py,generate_shenron.py).dashboard/: Flask backend and static web assets for the GUI.intel/: Detailed deep-dive documentation for specific components.intel/CHRONICLES.md: Project History — Weekly evolution and major milestones.intel/memory_update.md: Agent Protocol — Standardized guide for repo memory updates.intel/radar/: Deep dives into radar physics (e.g.research/isotropic_illumination_problem.md).scripts/ISOLATE/: High-fidelity radar simulation engine and plotting utils.
🛠️ 2. Component Reference
src/pipeline/manager.py (The Director)
- Role: Sequential executor for pipeline stages.
- Workflow: Reads
PipelineContext→ Skips stages if requested → ExecutesSim→Shenron→MCAP→Video. - Error Handling: Halts the pipeline on critical stage failures but ensures cleanup for all started stages.
src/main.py (CLI Entry Point)
- Role: Parses arguments and initializes the
PipelineManager. - Features: Supports selective execution via
--only-mcapor--skip-shenron.
src/pipeline/stages/ (The Workers)
SimulationStage: Handles CARLA connection, ego spawning, and the capture loop.ShenronStage: Triggers physics-based radar synthesis viagenerate_shenron.py.McapStage: Performs Foxglove serialization via upgradeddata_to_mcap.py.
src/processing/physics.py (The Math Layer)
- Centralized source of truth for:
- Radial Velocity Injection: Projecting relative velocity onto LOS.
- ADAS Metrics: Real-time Range, Azimuth, and Closing Velocity.
- Actor Categorization: Classifying CARLA actors for telemetry.
src/sensors.py (SensorManager)
- Manages Camera (RGB), Radar, and LiDAR.
- Uses synchronized queues to ensure frame alignment.
- Coordinate System: Left-handed (CARLA Default).
scenarios/base.py (The Plugin Contract)
- All scenarios must inherit from
ScenarioBase. - Required methods:
setup(),step(),cleanup(), andnameproperty. - Support for CLI parameter injection via
apply_parameters(args.params).
🛰️ 3. Data & Visualization
Data Recording (src/recorder.py)
- Saves images as
.png, radar/lidar as.npy, and metadata as.jsonl. - Relative ADAS Metrics: Calculates range, azimuth, and closing velocity for all actors.
MCAP Conversion (scripts/data_to_mcap.py)
- Converts raw dataset folders into Foxglove-compatible
.mcapfiles. - Coordinate Conversion: Negates Y and Yaw to switch from CARLA left-handed to ROS/Foxglove right-handed convention.
- Radar Math: Converts spherical (Depth/Az/Alt) to Cartesian (XYZ) for PointCloud representation.
🖥️ 4. GUI Dashboard Architecture
- Backend: Flask (
app.py) running on port 5000. - Simulator Lifecycle: Dashboard polls
/api/simulator/statusto detect if CARLA is Offline/Ready. Provides one-click initialization via the UI. - GPU Resource Control: Incorporates "Idle Mode" (Synchronous Throttling) to drop CARLA GPU usage to ~0% when inactive or while Shenron processing is active.
- Streaming: Uses Server-Sent Events (SSE) to stream
stdoutto the browser. - Execution: Spawns
run.batas a subprocess. - Crucial Rule: Always set
PYTHONUNBUFFERED=1to prevent log delays in the GUI console.
🧠 5. Scenario Design & Best Practices
The "Deterministic Pattern"
- Use manual coordinate-based control and
set_target_velocityinstead of Traffic Manager for repeatable maneuvers. - Spawn-and-Move: Spawn ego at a safe point, then
set_transformto the exact start location. - Z-Axis Lift: Always spawn NPCs with a +0.5m offset to avoid ground-mesh collision errors ("Spot occupied").
Common Pitfalls
- Stale Physics: Always
world.tick()once after spawning the Ego but before starting scenario logic. - Graceful Shutdown: Use the "Stop Simulation" button in the dashboard. It writes a
tmp/stop.flagwhich the orchestrator checks to ensure all recorders and data converters (Shenron/MCAP) finalize correctly. - Progress Bar Clash: Use
pbar.write()for logs if atqdmprogress bar is active. - Asynchronous I/O: Use
ThreadPoolExecutorfor disk writes (images) to prevent simulation frame drops.
🚀 6. Execution Commands
- Run Scenario:
cmd /c run.bat <scenario_name> --frames <N> --params "KEY=VAL" --weather <Preset> - List Scenarios:
cmd /c run.bat --list-scenarios - Run Testbench:
cmd /c "call C:\ProgramData\miniconda3\Scripts\activate.bat carla312 && python scripts/test_shenron.py --iter <Name>"
🤖 7. Agent Execution Rules
- Shell Environment: This repository is hosted on Windows. All commands MUST use PowerShell syntax for general file operations and directory management.
- Python Execution: All simulation and scenario commands MUST be launched via the
run.batorchestrator using thecmd /cprefix. - Standalone Scripts: Scripts like
test_shenron.pyor diagnostic tools must also usecmd /cwith explicit environment activation to ensure compatibility:- Correct:
cmd /c "call C:\ProgramData\miniconda3\Scripts\activate.bat carla312 && python scripts/test_shenron.py --iter test" - Incorrect:
python scripts/test_shenron.py --iter test
- Correct:
- Cmdlet Preference: Prioritize native PowerShell cmdlets or robust Windows utilities:
- Use
Select-Stringorripgrepinstead ofgrep. - Use
;to chain commands instead of&&. - Use
move/Copy-Iteminstead ofmv/cp. - Use
tree /ffor recursive directory visualization.
- Use
Generated by Antigravity AI | Last Updated: 2026-04-23 | Refer to .cursorrules for start-of-turn instructions.