Skip to content

Fix: calibrated scales keep their size, and snap in the unit they were written in - #31

Merged
Sherin-SEF-AI merged 1 commit into
mainfrom
feat/calibrate-units
Sep 23, 2026
Merged

Sherin-SEF-AI merged 1 commit into
mainfrom
feat/calibrate-units

Conversation

@Sherin-SEF-AI

@Sherin-SEF-AI Sherin-SEF-AI commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Defects

  1. Small scales became zero. Scales were rounded to six decimal places, so a field in 1e-7 degrees (a common GPS encoding) came back with scale 0.0, and the DBC layer reads a zero scale as 1. Scales and offsets now keep seven significant figures. The new test fails on the old code.
  2. Snapping ignored units. A GPS logger reports m/s; a car's DBC says 0.01 km/h per bit, which is 0.0027778 m/s. No round number in m/s matches that, so it never snapped. Given the reference's unit, snap_calibration now also tries km/h, mph and knots (degrees for radians, psi and bar for kPa), under the same bias gate, and candidate_to_signal_def writes the signal in the unit the manufacturer used, noting the reference unit in its description.

A real-data check the calibrator lacked

phase_reference in acceptance_new_sources.py fetches comma.ai's comma2k19 example segment (MIT, about 6 MB): one minute of a Toyota RAV4's CAN bus with a u-blox receiver, and openpilot's DBC as the answer key. From the GNSS speed alone:

Check Result
Speed signals found 0x0B4 bytes 5-6 (vehicle speed) and all four 0x0AA wheel words, R² 0.998
Wheel scale as written 0.01 km/h per bit, offset -67.05 to -67.19; openpilot says 0.01 and -67.67
UTC reference onto the capture's clock within 0.168 s of the true offset
That residual the receiver's latency: 0.14 s measured by the search, 0.16 s by a cross-correlation of openpilot's own speed against GNSS that does not use CanLab
The written signal decodes the car within 0.87% of openpilot's decode

The vehicle-speed field does not snap to 0.01 km/h, correctly: this car's speed signal reads about 0.8% above GPS, and forcing the round scale would move the decode past the 1% bias budget.

pytest -q: 726 passed. phase_reference: 4/4. ruff clean.

…e written in

Two defects in the reference calibrator, and a real-data check it lacked.

Scales were rounded to six decimal places. A field in 1e-7 degrees, a
common GPS encoding, came back with scale 0.0, and the DBC layer reads a
zero scale as 1. Scales and offsets now keep seven significant figures.

Snapping only knew round numbers in the reference's own unit. A GPS
logger reports m/s; a car's DBC says 0.01 km/h per bit, which is
0.0027778 m/s and no round number at all, so it never snapped. Given the
reference unit, the snapper now also tries km/h, mph and knots (and
degrees for radians, psi and bar for kPa), under the same bias gate, and
the DBC signal is written in the unit the manufacturer used.

The lag search had only been tested on the shipped sample. A new phase
in acceptance_new_sources.py runs the calibrator on comma.ai's comma2k19
segment (MIT): a real Toyota RAV4's CAN bus, a u-blox receiver, and
openpilot's DBC as the answer key. From the GNSS speed alone it finds
0x0B4 bytes 5-6 (vehicle speed) and the four 0x0AA wheel words, R2
0.998; the wheel scale comes back as 0.01 km/h with an offset of -67.1
against openpilot's -67.67; a UTC-stamped reference lands within 0.17 s
of the true clock offset, which is the receiver's own latency (0.16 s
by an independent cross-correlation that does not use CanLab); and the
signal it writes decodes the car within 0.9% of openpilot's decode.
@Sherin-SEF-AI
Sherin-SEF-AI merged commit da03780 into main Sep 23, 2026
2 checks passed
@Sherin-SEF-AI
Sherin-SEF-AI deleted the feat/calibrate-units branch September 23, 2026 19:16
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