Conversation
Raw magnetometer samples were not obtainable from a blackbox log. The
existing magADC fields are written after the magZero/magGain correction
and after sensor and board alignment have been applied, so they cannot
be used to solve for hard and soft iron offsets externally. On a board
that already has a stored calibration the original sample cannot be
recovered from them at all.
Publish mag.dev.magADCRaw into debug[0..2] straight after the sensor
read, before calibration and before alignment, mirroring how DEBUG_ACC
already exposes acc.dev.ADCRaw in acceleration.c.
Enable with:
set debug_mode = MAG
The three axes then appear as debug[0] (X), debug[1] (Y) and debug[2]
(Z) in the blackbox log and in the CLI "debug" command.
This reuses the existing debug channel, so the log format is unchanged.
debug_mode defaults to NONE and the debug columns are only emitted when
debug_mode is not NONE, so logs from users who do not opt in are
unaffected. DEBUG_MAG is appended to the end of debugType_e so the
numbering of the existing debug modes is preserved.
Closes iNavFlight#10758
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoAdd MAG debug mode for raw magnetometer logging
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1.
|
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #11924 249 targets built. Find your board's
|
|
FYI, in case useful: PR #11708 just added |
Problem
Fixes #10758. @and-sh asked for the raw magnetometer data to be saved to the blackbox so the compass can be calibrated with an external tool; @AlexC176 confirmed the need for out-of-application calibration. The
magADCfields in the log are written after themagZero/magGaincorrection and after sensor and board alignment, so on a board with a stored calibration the original sample cannot be recovered from them.Cause
src/main/sensors/compass.c:493applies themagZero/magGaincorrection andcompass.c:514-515apply sensor and board alignment tomag.magADC;src/main/blackbox/blackbox.c:1772logs that corrected value.mag.dev.magADCRawis never published, anddebugType_ehas no compass entry (src/main/build/debug.h:85). Separately,src/main/drivers/compass/compass_mlx90393.c:108ignores thebusReadBufresult and returnstrue(line 114), so a failed bus read would yield zeros.Change
Adds
DEBUG_MAGat the end ofdebugType_e, todebugModeNamesincli.cand todebug_modesinsettings.yaml, so existing debug numbers do not shift.compassUpdate()writesmag.dev.magADCRaw[X..Z]intodebug[0..2]right after the driver read, before calibration and alignment, asDEBUG_ACCdoes withacc.dev.ADCRaw(acceleration.c:582).mlx90393Read()now returnsfalsewhenbusReadBuffails, so the existing failure branch incompassUpdate()skips the sample instead of logging zeros (raised by the Qodo review on this PR). Enable withset debug_mode = MAG; the values appear in blackboxdebug[0..2]and in the CLIdebugcommand.Test
Not run on hardware or SITL. Cause verified by reading
compass.c:493/514andblackbox.c:1772onmaintenance-10.x. Fork CI ran only theSettings.mdconsistency check, on f0dca86: https://github.com/Raffi1202/inav/actions/runs/34532494452 (success). No firmware build has run; the upstream "Build firmware" runs for both commits are waiting for approval (https://github.com/iNavFlight/inav/actions/runs/34619099396).Flash / RAM
Not measured yet. The upstream firmware CI has not been released for this PR, so no size report exists.
Docs
docs/Blackbox.mdlistsMAGamong the debug modes;docs/Settings.mdregenerated fromsettings.yaml(checked by the docs workflow run above).