Humanoid State Estimation ← back to dashboard

▍ Stage 4 — The Sim-to-Real Gap

embedded pipelinetiming > amplitudeablation studybuffer-and-replay fix

The sim-to-real gap for a low-cost humanoid is dominated by the embedded pipeline — finite sensor resolution, sequential CAN reads, transport latency, sample jitter — not physics fidelity. This stage injects those effects, stress-tests the estimator to find which ones actually matter — and then fixes the dominant one: with source capture timestamps and buffer-and-replay fusion, the timing damage is fully recovered.

The model

apply_embedded_noise corrupts a logged dataset by re-sampling each sensor stream at its true (perturbed) capture time and quantizing: encoder/IMU quantization (14-bit / 16-bit LSBs), per-joint CAN stagger (the bus reads joints sequentially), transport latency, and sample-interval jitter. Physics is untouched — only the measurement pipeline is made realistic.

The finding: timing dominates, amplitude is negligible
Left: ESKF drift under each effect alone. Amplitude effects (quantization, jitter) are no worse than clean; timing effects (inter-joint stagger, latency) blow drift up several-fold. Right: drift climbs steeply with latency.
Left: ESKF drift under each effect alone. Amplitude effects (quantization, jitter) are no worse than clean; timing effects (inter-joint stagger, latency) blow drift up several-fold. Right: drift climbs steeply with latency.
effectdriftverdict
clean (Gaussian IMU noise only)0.32%baseline
+ all embedded effects together0.92%realistic full stack — jitter dithers the coherent latency skew
+ encoder/IMU quantization0.32%negligible
+ sample jitter (0.8 ms)0.07%negligible
+ inter-joint stagger (2 ms)1.51%hurts
+ transport latency (5 ms)2.04%hurts most
+ latency (5 ms, uniform — contact delayed too)1.74%still ~5× clean
+ latency (15 ms)6.46%catastrophic
The fix — buffer-and-replay on source timestamps

The timing damage is mis-ordered information, not lost information — so it is recoverable. Each sample now carries its capture time from the master clock (a real pipeline stamps at the source MCU, not on arrival). The estimator (timing.py) keeps a ~200 ms rolling buffer of filter states, covariances and IMU inputs; a measurement stamped in the past is fused at its stamp: roll back to the buffered state, apply it there, then re-propagate the buffered IMU — and every already-fused measurement in between, in order — forward to now. Encoder and gyro inputs are reconstructed per joint at the contact instant (undoing the CAN stagger); a contact flag racing ahead of the delayed IMU head waits in a pending queue and fuses at the correct instant via a split of the covering IMU interval. With zero delay every path reduces bit-for-bit to the naive loop, and a late-delivered measurement provably (tests) matches the posterior of an oracle that received it on time.

Left: the same corruption rows, naive vs compensated — every timing row collapses to the clean baseline while irreversible quantization sets the all-effects floor. Right: naive drift climbs steeply with latency; compensated drift is flat out to 20 ms, and the skew/uniform distinction disappears entirely.
Left: the same corruption rows, naive vs compensated — every timing row collapses to the clean baseline while irreversible quantization sets the all-effects floor. Right: naive drift climbs steeply with latency; compensated drift is flat out to 20 ms, and the skew/uniform distinction disappears entirely.
effectnaivecompensatedcontact NIS (naive → comp)
clean (Gaussian IMU noise only)0.32%0.32%6.3 → 6.3 (bit-identical run)
+ all embedded effects together0.92%0.70%10.5 → 6.4
+ quantization only0.32%0.32%6.3 → 6.3
+ sample jitter (0.8 ms)0.07%0.32%6.3 → 6.3
+ inter-joint stagger (2 ms)1.51%0.24%6.6 → 6.3
+ latency 5 ms (vs contact skew)2.04%0.24%9.6 → 6.3
+ latency 5 ms (uniform)1.74%0.24%6.7 → 6.3
+ latency 15 ms (vs contact skew)6.46%0.23%16.5 → 6.2
+ latency 15 ms (uniform)4.61%0.23%6.7 → 6.2
flat to 20 ms
compensated drift vs latency
0.21–0.32% across the sweep
27×
drift cut at 15 ms latency
6.46% → 0.23%
NIS 6.3
consistency restored
= clean, every row (was up to 16.5)
0.70%
all-effects floor
quantization — amplitude, irreversible

Honest footnotes: the naive jitter row’s 0.07% is a dither fluke (random skew decorrelating the coherent contact error), not a real win — the compensated filter sits at the honest 0.32%. The compensated timing rows land a hair below clean (0.23–0.24%) because the corruption re-samples the noisy streams by linear interpolation, which mildly low-passes the injected sensor noise. Position NEES tells the consistency story hardest: at 15 ms latency the naive filter scores 26 (confidently wrong — tight covariance around a bad estimate); compensated returns to ~2.5, matching clean’s 2.7.

Seed-firmness (run_timing.py seeds, 3 corruption draws): the compensated timing rows hold 0.21–0.24% on every draw — the pure-latency rows are deterministic and identical across seeds — while the naive side is draw-sensitive: the all-effects row’s 0.92% above was a favorable roll (3-seed median 3.20%, range 0.92–3.81), stagger’s 1.51% reached 3.87% on one draw, and the jitter fluke swung 0.07–0.70%. Compensation doesn’t just fix the mean — it removes the draw sensitivity.

Why it ties back to Stage 3

The dominant killer is timing — latency and the relative skew between sensor streams — while sensor precision barely registers — to close the sim-to-real gap you model the pipeline's timing structure, not its amplitude. The defense comes in two complementary halves: when the pipeline can stamp at the source, buffer-and-replay above recovers the loss outright; when a stream's offset is unknown or unstamped (the camera's clock), Stage 3’s approach — model the offset as a filter state (td) and calibrate it online — is the fallback, given a trajectory that excites it.

TakeawayLatency is the dominant drift driver, and it is the recoverable kind of damage: source timestamps + buffer-and-replay collapse a 6.5% failure back to the 0.32% baseline, with the covariance honest again. What timestamps cannot buy back — quantization, and a clock offset nobody measured — is exactly where Stage 3’s online calibration picks up.