4.0 KiB
Implementation Plan: Stage-Based Pipeline Refactor
Refactor the Fox CARLA ADAS simulation pipeline to separate concerns across environment management, data processing, and serialization. This moves the project from a monolithic main.py to a modular, stage-based architecture.
User Review Required
[!IMPORTANT] Dashboard Telemetry Persistence: The Dashboard backend (
app.py) parses specificstdoutpatterns like[SHENRON_STEP]and[AUTO-MCAP]. We must ensure the newPipelineManageror the individual stages continue to emit these strings to avoid breaking the UI progress bars.
[!WARNING] Resource Management: During the transition from
SimulationStagetoShenronStage, we must explicitly ensure CARLA's synchronous mode is either released or the process is handled such that GPU memory is freed for the heavy Shenron Torch operations.
Proposed Changes
[NEW] Pipeline Core (src/pipeline/)
Establish the foundational classes for stage-based execution.
[NEW] base.py
- Define
PipelineContext: Dataclass to carrysession_path,scenario_config, andargs. - Define
PipelineStage: Abstract Base Class withrun(context)andcleanup()methods.
[NEW] manager.py
- Implement
PipelineManager: Orchestrates the execution of a list ofPipelineStageobjects. - Handles error propagation and graceful halts.
[NEW] Processing Layer (src/processing/)
Extract physics and data-augmentation logic to make it reusable and testable.
[NEW] physics.py
calculate_radial_velocity: Extracted fromrecorder.py. Calculates line-of-sight velocity for LiDAR points.compute_adas_metrics: Extracted fromrecorder.py. Calculates range, azimuth, and closing velocity for NPCs.
[MODIFY] Simulation & Recording
Clean up existing components to focus on their primary responsibilities.
[MODIFY] recorder.py
- Remove physics calculation logic.
- Update
save()to accept pre-calculated metrics. - Move
_generate_videosto a utility function.
[MODIFY] main.py
- Remove monolithic simulation loop.
- Transform into a thin wrapper that initializes
PipelineManagerwithSimStage,ShenronStage, andMcapStage.
[NEW] Pipeline Stages (src/pipeline/stages/)
Encapsulate logic into discrete execution units.
[NEW] sim_stage.py
- Port the CARLA simulation loop from
main.py. - Manage
SensorManagerandRecorderlifecycles.
[NEW] shenron_stage.py
- Wrap
scripts/generate_shenron.pylogic. - Ensure
[SHENRON_STEP]telemetry is emitted.
[NEW] mcap_stage.py
- Wrap
scripts/data_to_mcap.pylogic. - Register Foxglove schemas and handle final serialization.
Verification Plan
Automated Tests
- Physics Parity Test: Create a script in
scratch/that runs the oldrecorder.pylogic and the newphysics.pylogic on the same frame to ensure bit-identical results for radial velocity and ADAS metrics. - Pipeline Dry-Run: Run the pipeline with
--skip-simon an existing data folder to verify thatShenronStageandMcapStagecorrectly identify and process the files.
Manual Verification
- Dashboard Validation: Launch the Dashboard via
dashboard.bat, trigger a simulation, and verify that:- The console log shows the new stage transitions.
- The progress bars for Shenron and MCAP update correctly.
- Foxglove Check: Open the generated
.mcapin Foxglove and verify that the LiDAR (with radial velocity) and Radar pointclouds are visualized correctly.