Skip to content

ConfigHWCompass: surface MAG_CAL_FAILED_OFFSETS / FAILED_DIAG_SCALING / FAILED_RESIDUALS_HIGH failure codes - #3722

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

ConfigHWCompass: surface MAG_CAL_FAILED_OFFSETS / FAILED_DIAG_SCALING / FAILED_RESIDUALS_HIGH failure codes#3722
christianpetri wants to merge 9 commits into
ArduPilot:masterfrom
christianpetri:mag-cal-bad-fit-status-codes

Conversation

@christianpetri

@christianpetri christianpetri commented May 11, 2026

Copy link
Copy Markdown

Summary

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

Named enum members are present in Mavlink.cs following the merge of mavlink/mavlink#2478 via ArduPilot/mavlink#506, and applied to Mission Planner's vendored copy in #3750.

Wire value Enum name Meaning
5 MAG_CAL_FAILED Generic failure (old firmware, no detail)
6 MAG_CAL_FAILED_ORIENTATION Vehicle orientation outside required tolerance
7 MAG_CAL_FAILED_RADIUS Fitted sphere radius unrealistically small or large
8 MAG_CAL_FAILED_OFFSETS Offset component >= COMPASS_OFFS_MAX
9 MAG_CAL_FAILED_DIAG_SCALING Diagonal or off-diagonal scaling out of range
10 MAG_CAL_FAILED_RESIDUALS_HIGH RMS residual exceeds tolerance

Previously codes 6–10 fell through silently, leaving the calibration dialog stuck in a running state with no feedback to the user.

Changes

GCSViews/ConfigurationView/ConfigHWCompass.cs — legacy dialog (shown when COMPASS_PRIO1_ID is absent):

  • Uses calStatus > MAG_CAL_SUCCESS as the failure guard — catches all current and future failure codes by design
  • Tracks the specific failure status per compass ID as a sticky footer that persists across firmware auto-retries
  • Resets progress bar to 0 on retry so the climbing bar is visually fresh
  • Shows a partial-save banner when some compasses have autosaved while others are still failing/retrying
  • Fixes the all-success completion gate (was compasscount == completecount, now uses autosaved count vs expected count)

GCSViews/ConfigurationView/ConfigHWCompass2.cs — new compass priority dialog (shown when COMPASS_PRIO1_ID is present):

  • StatusText() returns upstream [Description] text directly from the enum attribute with no local string mapping, so new status codes are picked up automatically. MAG_CAL_SUCCESS (4) and MAG_CAL_FAILED (5) both have empty upstream descriptions; the fallback returns the raw enum name, staying forward-compatible if upstream adds descriptions later.
  • StatusDetail() appends actionable numeric values per failure code:
    • Success: saved offsets (x/y/z) + fitness
    • FAILED_OFFSETS: offsets + COMPASS_OFFS_MAX limit
    • FAILED_RESIDUALS_HIGH: fitness value
    • FAILED_ORIENTATION: orientation confidence + hardcoded firmware minimum (0.40)
    • All other codes: no extra detail
  • All numeric values use fixed decimal format (F0/F1/F2) — no unbounded float strings
  • Retry attempt counter shown on the progress row when attempt >= 2
  • Partial-save guidance shown when some compasses autosaved while others are still retrying
  • Reboot button changes to "Reboot Now ⚠" with tooltip when autosave has occurred; flag only clears when reboot succeeds
  • On page navigation away from an active calibration, sends DO_CANCEL_MAG_CAL and prompts for reboot if changes were saved

GCSViews/InitialSetup.cs — unchanged from upstream: firmware with COMPASS_PRIO1_ID gets ConfigHWCompass2, others get ConfigHWCompass.

MissionPlannerTests/GCSViews/MagCalStatusTests.cs — new unit tests (see Tests section).

Notes on Mavlink.cs

ExtLibs/Mavlink/Mavlink.cs is not changed in this PR — it is auto-generated from the upstream mavlink XML. The named enum members (FAILED_OFFSETS, FAILED_DIAG_SCALING, FAILED_RESIDUALS_HIGH, FAILED_ORIENTATION, FAILED_RADIUS) land in Mission Planner via #3750, which must merge first.

Tests

MissionPlannerTests/GCSViews/MagCalStatusTests.cs covers:

  1. Wire values (6–10) pinned as regression guards — if upstream renumbers a member or Mavlink.cs is regenerated against a diverged XML, these fail loudly
  2. Full enum snapshot (0–7) pinned — the > MAG_CAL_SUCCESS partition must remain correct
  3. Failure guard — all codes 5–10 are > MAG_CAL_SUCCESS; running/waiting/success states are not
  4. Named ToString() — locks that MAG_CAL_FAILED and MAG_CAL_FAILED_RADIUS names are stable (used as fallback display text)
  5. Upstream [Description] content — each specific failure code (6–10) carries a non-empty description containing its key diagnostic term ("orientation", "radius", "offset", "scaling", "fitness"); if upstream ever removes a description, the UI fallback is the raw enum name and the test fails loudly

All 12 tests pass (verified locally with dotnet vstest).

Testing this PR

To verify the legacy UI (ConfigHWCompass) with a firmware that has COMPASS_PRIO1_ID, temporarily show both pages side by side by replacing the gated block in GCSViews/InitialSetup.cs:

// TEMPORARY — revert before merging
AddBackstageViewPage(typeof(ConfigHWCompass2), rm.GetString("backstageViewPagecompass.Text") + " (New)",
        isConnected && gotAllParams, mand);
AddBackstageViewPage(typeof(ConfigHWCompass), rm.GetString("backstageViewPagecompass.Text") + " (Legacy)",
        isConnected && gotAllParams, mand);

Depends on

@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
@christianpetri
christianpetri force-pushed the mag-cal-bad-fit-status-codes branch from 72f778d to 7e5607a Compare July 11, 2026 16:20
@christianpetri christianpetri changed the title ConfigHWCompass: surface MAG_CAL_BAD_OFFSETS/BAD_DIAG_SCALING/BAD_FITNESS failure codes ConfigHWCompass: surface MAG_CAL_FAILED_OFFSETS / FAILED_DIAG_SCALING / FAILED_RESIDUALS_HIGH failure codes Jul 11, 2026
Rename BAD_ORIENTATION/BAD_RADIUS to FAILED_ORIENTATION/FAILED_RADIUS and
add three new failure codes introduced by the upstream PR:
  - MAG_CAL_FAILED_OFFSETS     (value 8)
  - MAG_CAL_FAILED_DIAG_SCALING (value 9)
  - MAG_CAL_FAILED_RESIDUALS_HIGH (value 10)

Changes: common.xml + regenerated Mavlink.cs enum block only.
…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.
- Adjusted layout of picture boxes and progress bars in ConfigHWCompass2.Designer.cs for better alignment.
- Updated size and location properties for UI elements to enhance usability.
- Improved handling of calibration state in ConfigHWCompass2.cs, including better management of progress and report packets.
- Introduced new methods for processing calibration results and rendering UI state.
- Enhanced unit tests for MAG_CAL_STATUS to ensure robustness against future changes in MAVLink definitions.
- Added checks for specific failure reasons in calibration process, improving user feedback on calibration status.
Streamline compass calibration by removing the Accept button; users are now prompted to reboot after calibration to apply changes. Refactor reboot logic and button state handling, use MAVLink status descriptions directly, and enhance UI feedback for partial saves and failures. Resize key buttons and improve UI consistency. Minor cleanups and improved prompts included.
Refactored StatusText to use upstream MAVLink descriptions when available, with a dictionary-based fallback for MAG_CAL_SUCCESS and MAG_CAL_FAILED to keep the UI readable and forward-compatible. Removed previous hardcoded status checks.
@christianpetri
christianpetri force-pushed the mag-cal-bad-fit-status-codes branch from 8e56c05 to 05ebef6 Compare July 14, 2026 16:15
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