Skip to content

ConfigHWCompass: surface MAG_CAL_BAD_OFFSETS/BAD_DIAG_SCALING/BAD_FITNESS failure codes#3722

Draft
christianpetri wants to merge 4 commits into
ArduPilot:masterfrom
christianpetri:mag-cal-bad-fit-status-codes
Draft

ConfigHWCompass: surface MAG_CAL_BAD_OFFSETS/BAD_DIAG_SCALING/BAD_FITNESS failure codes#3722
christianpetri wants to merge 4 commits into
ArduPilot:masterfrom
christianpetri:mag-cal-bad-fit-status-codes

Conversation

@christianpetri
Copy link
Copy Markdown

@christianpetri christianpetri commented May 11, 2026

Summary

Companion GCS change for ArduPilot/ardupilot#32757, which extends \CompassCalibrator::Status\ with three specific failure reasons reported via \MAG_CAL_REPORT.cal_status\ when the calibration fit is rejected:

Wire value Enum name Meaning
8 \MAG_CAL_BAD_OFFSETS\ An offset component >= \COMPASS_OFFS_MAX\
9 \MAG_CAL_BAD_DIAG_SCALING\ Diagonal or off-diagonal scaling out of range
10 \MAG_CAL_BAD_FITNESS\ RMS residual exceeds tolerance

Previously these values fell through silently, leaving the calibration dialog stuck in a running state with no feedback to the user.

Changes

  • *\GCSViews/ConfigurationView/ConfigHWCompass.cs* — legacy onboard calibration dialog
  • *\GCSViews/ConfigurationView/ConfigHWCompass2.cs* — GPS order / compass priority dialog
  • *\MissionPlannerTests/GCSViews/MagCalStatusTests.cs* — new unit tests

Both dialogs now:

  • Use \calStatus > MAG_CAL_SUCCESS\ as the failure guard — catches all current and any future failure codes by design
  • Track the specific failure status per compass ID (\lastFailureStatus\ dictionary)
  • Display the failure code in the result label and set the progress bar / picture box to red on failure

Notes on \Mavlink.cs\

\ExtLibs/Mavlink/Mavlink.cs\ is not changed — it is auto-generated from upstream mavlink XML. The named enum members will appear automatically when mavlink/mavlink#2478 merges and the file is regenerated.

Until then, raw values \8/\9/\10\ are received from firmware and handled correctly by the > MAG_CAL_SUCCESS\ guard. The result label shows e.g. \Mag 0: 8\ until the regen, after which it will show \Mag 0: MAG_CAL_BAD_FITNESS.

Tests

Tests in \MissionPlannerTests/GCSViews/MagCalStatusTests.cs\ cover:

A follow-up to switch from raw casts to named members is tracked in mavlink/mavlink#2478.

Depends on

…l dialogs

ArduPilot/ardupilot#32757 adds three new MAG_CAL_STATUS values sent in
MAG_CAL_REPORT.cal_status when calibration fit is rejected:
  8 = BAD_OFFSETS  - offset component >= COMPASS_OFFS_MAX
  9 = BAD_DIAG     - diagonal/off-diagonal scaling out of range
 10 = BAD_FITNESS  - RMS residual exceeds tolerance

Previously these fell through silently, leaving the cal dialog stuck.

Changes:
- Use calStatus > MAG_CAL_SUCCESS guard (future-proof for any further codes)
- Track failure status per compass in lastFailureStatus dictionary
- Show failure code in result label; set progress/picture to red on failure
- Add unit tests covering the guard logic and wire values

Note: Mavlink.cs is NOT changed - it is auto-generated. Named enum members
MAG_CAL_BAD_OFFSETS/DIAG/FITNESS arrive when mavlink/mavlink#2478 merges
and Mavlink.cs is regenerated. Tests use raw byte casts until then.
@christianpetri christianpetri marked this pull request as draft May 11, 2026 23:25
@christianpetri christianpetri changed the title ConfigHWCompass: surface BAD_OFFSETS/DIAG/FITNESS failure codes in ca… ConfigHWCompass: surface MAG_CAL_BAD_OFFSETS/BAD_DIAG_SCALING/BAD_FITNESS failure codes May 14, 2026
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