Skip to content

Sim-to-real: one pipeline for the car and the sim - #1

Merged
daniel-debrun merged 35 commits into
mainfrom
sim-to-real
Nov 9, 2026
Merged

daniel-debrun merged 35 commits into
mainfrom
sim-to-real

Conversation

@daniel-debrun

@daniel-debrun daniel-debrun commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Camera-only mapping and racing in the AutoDRIVE sim on the same workers as the car, plus the tooling to deploy and measure on the Jetson.

  • One pipeline: the car and the sim build the same segmentation, scan, mapping, control, state and actuator workers (a test enforces it).
  • Mapping-lap walls from an occupancy grid over the segmentation-edge scans, live in MappingWorker. The offline seg_map.py uses the same code and reproduces the saved compete map exactly.
  • In the loop: the practice track maps in 55 s with no hits in 3 of 3 runs, then races 10 laps clean. The compete track maps in 3 of 3 runs with 4 to 5 hits (bench/2026-11-09_live_mapping).
  • Optional SLAM-like degradation of the sim pose. Latency and dropouts, not noise, are what the current race settings cannot take.
  • Jetson self-test, per-stage latency report, deploys from car-v* tags, arm64 image workflow.
  • docs/sim_to_real.md lists every sim-to-car gap. Also: a licence notice for the GPLv3 wrapper, ORB_SLAM3 pinned to the fork's master, and the data-v1 release.

Not yet run on the car; docs/roadmap.md lists the steps.

Arms at start-up and re-arms after a critical worker restarts; refused unless
sim: autodrive, so the car is still armed only by the operator.
steer_speed_limit caps the speed ref at sqrt(a_lat / kappa_cmd), with its own
steer_lat_accel. The centre-line profile lets the car accelerate out of a hairpin
while it is still at large steering; in the AutoDRIVE sim it then slides into the
outer wall (compete track: 2 hits per lap at any lat_accel_fraction >= 1.6;
0 with steer_lat_accel 4.0). Off by default.
control/raceline.py: the line as normal offsets of the centre-line, bounded by the
walls minus a margin (ray-cast), second differences minimised by bounded least
squares, re-linearised over 4 passes, returned as a periodic cubic spline.
TrackModel.set_path follows it between the same walls; ControlWorker loads it from
track_control.raceline_path; scripts/make_raceline.py writes <map>/raceline.npy plus a
preview and the speed planner's lap estimate (compete: 10.33 s centre-line ->
7.33 s). autodrive_bench run: --max-collisions.
config_autodrive_compete.yaml: saved map, racing line (margin 0.5 m), shorter pure
pursuit lookahead, profile a_lat 10.3 m/s^2 plus the steered-curvature cap at 5 m/s^2,
auto_arm. Stock 2026-iros compete build, 10 laps: 0 collisions, laps 10.53-10.71 s,
108.0 s total (was 19.5 s per lap). raceline: enforce the true nearest-wall distance
(the normal ray misses sharp inner corners). Racing lines for both maps; docs.
Wrapper: IMU_RGBD / IMU_STEREO / IMU_MONOCULAR constants, track_rgbd(..., imu) with
(N, 7) [t, acc, gyro] samples, origin_pose() and imu_initialized().
RawIMUBuffer (accel + all three gyro axes): CameraWorker fills it from the OAK-D when
slam.inertial is on, independent of use_oakd_imu, so imu_buf can keep the external
Arduino IMU. SLAMWorker passes the samples between consecutive frames and publishes
inertial poses / map points relative to the origin keyframe, which ORB-SLAM3's gravity
re-rotations move with the map (the frame of a rotation is withheld).
gen_orbslam_settings.py --imu writes the IMU block (T_b_c1 from the factory
calibration, D435i-example noise values) and checks T_b_c1 against gravity.

Wrapper compile-checked against the fork's headers only (no ORB-SLAM3 library here);
not yet run on the camera.
scripts/vio_bench: the rgbdi sequence format; sim_to_rgbdi.py (AutoDRIVE run ->
sequence: LiDAR depth, ground truth on the sim's own clock, synthetic 200 Hz IMU from
the low-passed pose); runners for ORB-SLAM3 IMU_RGBD / RGBD through orbslam3_python and
for cuVSLAM 17 Multisensor RGB-D + IMU + SLAM / RGBD; score.py (ATE, 1 s RPE, coverage,
per-frame latency). bench/2026-10-29_vio_sim: textured compete track, 3 race laps,
3 repeats on an L40S. ORB-SLAM3's inertial mode never initialised its IMU there (map
reset loop); cuVSLAM tracked every frame at 3.6 ms median vs 8.6 ms. Sim depth is ~15 %
short, so the accuracy numbers are pessimistic for both; real-track data decides.
…accuracy

start.py: raw_imu: true records the OAK-D's 6-axis IMU (raw_imu_buf) without running
inertial SLAM live; raw_imu is a recorded buffer. vio_bench: make_record_config.py (every
frame and IMU sample kept, IMU at 200 Hz), car_to_rgbdi.py (recording + ORB-SLAM3
settings with the IMU block -> rgbdi sequence, streamed), markers.py (AprilTags located
by IPPE from their printed size; per result: lap-to-lap repeatability of each tag, its
growth per lap, absolute error against a tape-measured survey after one rigid
alignment, start/end closure). score.py skips ground-truth metrics and the plot without
a groundtruth.csv. README: the field procedure. Tests: tag location on rendered images,
the metrics on perfect and drifting trajectories, the converter on a recorder-written
recording, markers.py end to end.
A 1920x1080 sim window did not fit the fixed 1280x720 display, so the HUD buttons
autodrive_sim_ctl.py clicks were off-screen. Default unchanged.
…mark renders, IMU extrinsics check

- ORB_SLAM3 -> e8bacc9 (branch inertial-depth-recovery, not pushed): for IMU_RGBD /
  IMU_STEREO a tracking loss before IMU initialisation relocalises instead of wiping the
  map, and weak visual tracking asks for a keyframe. IMU.UpstreamPolicy: 1 restores
  upstream. Upstream looped 84-154 resets per 32 s and never initialised the IMU; the
  fork initialises it at ~1.2 s with 0 resets (bench/2026-10-29_vio_sim/inertial_fix.md).
- scripts/vio_bench/render_track.py: re-render a sim sequence's track and trajectory with
  exact depth and a non-repeating texture, same IMU and ground truth (--blackout forces
  losses). The sim's LiDAR depth fits only ~35-65 % of ORB matches, so ORB-SLAM3 can't
  be judged on it.
- run_orbslam3.py: --upstream-policy, --depth-baseline / --close-depth (Stereo.b and
  ThDepth were fixed at the OAK-D's).
- gen_orbslam_settings.py --imu: devices without IMU calibration (the repo's OAK-D Lite
  dump has none) raised or could write a zero rotation as T_b_c1; now stops with an
  explanation, --imu-extrinsics gives the transform.
Both runners fed frames as fast as tracking allowed (~3x real time for ORB-SLAM3), so its
local-mapping thread (keyframes, IMU initialisation, inertial BA) fell behind; and on
the vast.ai container (nproc 255, cgroup cap 30.6 CPUs) thread pools sized to nproc got
the process throttled, which was ORB-SLAM3's 40-60 ms p95. Now frames are fed on the
sequence's clock (--speed, 1 = real time) and cpulimit.py pins to --cpus cores (default
the cgroup cap). ORB-SLAM3 RGB-D-inertial (fork, IMU noise x10) on the clean render:
100/83/100 % tracked, ATE 0.09-2.4 m, p95 10.4 ms (was 42).
… comparison with cuVSLAM

- ORB_SLAM3 -> 7cb97e4 (branch inertial-depth-recovery, not pushed): RGB-D frame-tracking
  rules until the IMU is initialised (18/18 clean starts, was 7/9), a young lost map given
  up after 0.5 s (IMU.EarlyLostTimeout), IMU.InitTime.
- run_orbslam3.py: --imu-init-time, --early-lost-timeout.
- inertial_fix.md: real-time, CPU-pinned results. RGB-D + IMU + SLAM on the rendered laps:
  ORB-SLAM3 CUDA 100 % tracked, ATE 0.10-0.17 m, p95 ~10 ms (3/3 runs); cuVSLAM 100 %,
  0.24 m, p95 1.8 s (SLAM back end in the tracking call).
…ost keyframes on for the car and the bench

- ORB_SLAM3 -> 881eec2 (branch inertial-depth-recovery, not pushed): keyframes at the IMU
  pose while lost, visual optimisation when recovering, NaN / null-prior guards in the
  inertial tracking optimisation. Rendered laps, RGB-D + IMU, x10 noise, 6 runs each:
  clean 100 % (ATE 0.09-0.14 m), blackouts at 20/26 s 98 % in one map (0.11-0.58 m),
  blackouts at 3/9 s 5 of 6 in one map (0.22-0.43 m); 0 crashes in 18 runs.
- gen_orbslam_settings.py --imu and run_orbslam3.py: IMU.InsertKFsWhenLost: 1 (was 0,
  which switched the mechanism off); run_orbslam3 --no-lost-keyframes, --early-lost-timeout
  default 1.0.
…ual IMU, option A)

- control.ImuEKF: planar EKF driven by an IMU on the car, state [x, y, yaw, vx, vy, b_gz,
  b_ax, b_ay]; SLAM poses applied at their capture time (IMU replayed after late ones), a
  chi-square gate against SLAM's bad poses after a loss (re-anchor after 2 s), a no-slip
  pseudo-measurement for a rear-axle IMU. Same interface as PoseEKF.
- scripts/vio_bench/make_rear_imu.py: the Arduino's ICM-20948 at the rear axle as the car
  reads it (noise, bias, 24 Hz DLPF, 100 Hz I2C polling stamped on arrival).
- scripts/vio_bench/fuse_rear_imu.py: causal replay (poses arrive after their tracking
  time), rear-IMU time offset by yaw-rate cross-correlation, ImuEKF vs PoseEKF vs the held
  SLAM pose against ground truth.
- Rendered race laps, 30 ORB-SLAM3 runs: position RMSE 0.10-0.13 m (PoseEKF 0.12-0.39),
  through SLAM gaps ~0.1 m (PoseEKF 0.3-0.8), speed 0.08 m/s (0.6-1.1), yaw rate
  0.7 deg/s (PoseEKF 33-41 deg/s). bench/2026-10-29_vio_sim/rear_imu_fusion.md.
… StateWorker on ImuEKF, check tool

- IMUWorker: parses the frame's accel (g) and gyro (deg/s), already sent by the firmware,
  into rear_imu_buf (m/s^2, rad/s, sensor axes) when rear_imu is enabled; polls that repeat
  the last sample (the Jetson polls faster than new samples) are not written; logs the new
  rate and repeat share. Corrects the frame comment: the timestamp is micros() of the last
  DMP quaternion update, not ms.
- StateWorker: with rear_imu_buffer runs control.ImuEKF; rear_imu.rotation turns the sensor
  axes into the car's, lever_m moves the camera pose to the IMU and back (the published
  state is the camera's point, as before), delay_s shifts the IMU's stamps.
- start.py / config.yaml: rear_imu block (enabled: false until checked), the buffer wired to
  IMUWorker, StateWorker and the recorder; rejected with the OAK-D IMU or the sim.
- scripts/check_rear_imu.py: live on the car (rate, repeats, bias at rest, the mounting
  from a hand turn and a push: the firmware's start-up calibration hides it at rest) and
  on a recording (the delay to the OAK-D IMU from |angular rate| cross-correlation).
  car_to_rgbdi exports rear_imu.csv.
- Tests: the firmware frame's units and repeats, StateWorker end to end on a circle with a
  rotated mount and a lever arm, the mounting / delay logic, the wiring.
…eEKF through blackouts; yaw rate in fuse_rear_imu's ticks.csv
…t; re-run qualifier and final

The re-run qualifier first did 0 laps and 2217 collisions: the race config arms itself on
connect, so the car drove off before the bench reset teleported it, and from then on every
collision respawn (a 0.7 m jump back) was read by PoseEKF as a huge speed and yaw rate;
predict_to extrapolated the heading with it and the controller steered into the same wall,
every ~0.5 s for 20 minutes.

- PoseEKF: estimator.jump_reset_m restarts the filter at a pose that far from the prediction,
  standing still (0.4 m in the sim configs; off by default, i.e. on the car).
- ControlWorker: resets the followers on such a state jump (speed integrator, etc.).
- autodrive_bench: auto_arm off in its runs (it resets, then arms).

Re-run: qualifier (practice) 10 laps 0 collisions, 6.89-6.98 s laps; final (compete) 10 laps
0 collisions, 109.07 s: 15th of 23 against the published 2026-iros results.
…xit and is no faster; the config's 5.0 stays
…uns, 0 collisions (was 109.1 s): 14th of 23; qualifier still clean
…ound-truth speed

pilot_core never uses a LiDAR (the car has none). Following an adversarial review of the sim
pipeline:

- start.py refuses lidar.enabled: true and sim_depth.depth: lidar; the defaults are off
  (seg_scan.source segmentation, sim_depth.depth none). No lidar_buf is ever created.
- SegScanWorker (new): segmentation mask -> track-edge scan in the LiDAR's format, edges placed
  on the floor plane (no depth), with a short memory (seg_scan.memory_s, 1.5 s) of edges that
  have left the camera's ~60 deg view so the gap follower still sees the inside of a hairpin.
  The mapping drive drives on it; LidarProjectionWorker projects it into the map's walls
  (mapping.scan_offset, mapping.scan_range_max 2 m: floor-placed edges are good to ~2 m),
  each scan with the pose of its own frame, not the latest.
- AutoDRIVEWorker: sim_depth.depth none prepares the frames the segmentation was trained on
  (upscaled, car body painted out) with no depth.
- The sim's own velocity is no longer fused into the state (use_pose_speed false): the car
  has no speed sensor. The sim's ground-truth pose stays, standing in for ORB-SLAM3.
- Segmentation runs only for a mapping lap in the sim (racing on a saved map nothing reads it).
- autodrive_bench run --competition-start: the sim restarted, the config's auto_arm, no reset
  or arm key, as the competition container starts.
- Docs and the 2026-10-29 results marked superseded where they relied on LiDAR maps, the
  sim's speed or the first VIO runs; caveats added (synthetic data, tuning on the scored
  sequences, LiDAR-derived training labels for the segmentation model).

Practice track mapped from segmentation live: 0 collisions, walls 5 / 9 cm (median) from the
old LiDAR map; qualifier on it 10 laps, 0 collisions, 7.1-7.2 s laps.
…d its racing line

Mapping lap 2026-10-29 on the sim's practice build (config_autodrive.yaml, SegScanWorker; 0
collisions). Walls 5 / 9 cm (median, inner / outer) from the old LiDAR map, up to 0.8-1.0 m
off where the camera saw little, both narrower than the real track. Qualifier on it: 10 laps,
0 collisions, 7.1-7.2 s laps (still with the sim's speed fused, before a17c02e).
… AutoDRIVE in a Slurm job

The mapping lap hits walls 2-3 times a lap on this track and MappingWorker's accumulated cloud
fills the dark corners with edges placed short. seg_map.py replays the recorded masks into an
occupancy grid: rays clear the floor they cross, masks near a hit or standing still are dropped,
no wall where the car drove, outer wall closed, at most 0.9 m from the driven path. Walls median
0.13 / 0.10 m (outer / inner) from the LiDAR map, used to score it only. Racing line margin 0.65 m.

MappingWorker: a respawn up to 2 m off the path keeps the lap (the sim respawns to fixed
checkpoints, up to 1.3 m off). scripts/cluster runs the sim in a Slurm job with stand-ins for
xdotool, xwininfo and supervisorctl. autodrive_sim.sh resolves its directory before the cd.
autodrive_sim_ctl.wait_scene waits out the splash, which outlasts UnloadTime on a slow disk.
…qualifier clean

First valid compete runs under the no-LiDAR rule, L40S. Behind 15th of the published
final (113.19 s), on a known track with the sim's ground-truth pose. Qualifier 10 laps, 0
collisions, 75.21 s. Corrects the racing section's old numbers, which came from a LiDAR map.
@daniel-debrun
daniel-debrun marked this pull request as ready for review November 9, 2026 16:52
@daniel-debrun
daniel-debrun merged commit 3e7e45f into main Nov 9, 2026
1 check passed
@daniel-debrun
daniel-debrun deleted the sim-to-real branch November 9, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant