ConfigHWCompass: surface MAG_CAL_FAILED_OFFSETS / FAILED_DIAG_SCALING / FAILED_RESIDUALS_HIGH failure codes - #3722
Draft
christianpetri wants to merge 9 commits into
Draft
Conversation
christianpetri
marked this pull request as draft
May 11, 2026 23:25
4 tasks
christianpetri
force-pushed
the
mag-cal-bad-fit-status-codes
branch
from
July 11, 2026 16:20
72f778d to
7e5607a
Compare
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
force-pushed
the
mag-cal-bad-fit-status-codes
branch
from
July 14, 2026 16:15
8e56c05 to
05ebef6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion GCS change for ArduPilot/ardupilot#32757, which extends
CompassCalibrator::Statuswith specific failure reasons reported viaMAG_CAL_REPORT.cal_statuswhen calibration is rejected.Named enum members are present in
Mavlink.csfollowing the merge of mavlink/mavlink#2478 via ArduPilot/mavlink#506, and applied to Mission Planner's vendored copy in #3750.MAG_CAL_FAILEDMAG_CAL_FAILED_ORIENTATIONMAG_CAL_FAILED_RADIUSMAG_CAL_FAILED_OFFSETSCOMPASS_OFFS_MAXMAG_CAL_FAILED_DIAG_SCALINGMAG_CAL_FAILED_RESIDUALS_HIGHPreviously 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 whenCOMPASS_PRIO1_IDis absent):calStatus > MAG_CAL_SUCCESSas the failure guard — catches all current and future failure codes by designcompasscount == completecount, now uses autosaved count vs expected count)GCSViews/ConfigurationView/ConfigHWCompass2.cs— new compass priority dialog (shown whenCOMPASS_PRIO1_IDis 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) andMAG_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:FAILED_OFFSETS: offsets +COMPASS_OFFS_MAXlimitFAILED_RESIDUALS_HIGH: fitness valueFAILED_ORIENTATION: orientation confidence + hardcoded firmware minimum (0.40)"Reboot Now ⚠"with tooltip when autosave has occurred; flag only clears when reboot succeedsDO_CANCEL_MAG_CALand prompts for reboot if changes were savedGCSViews/InitialSetup.cs— unchanged from upstream: firmware withCOMPASS_PRIO1_IDgetsConfigHWCompass2, others getConfigHWCompass.MissionPlannerTests/GCSViews/MagCalStatusTests.cs— new unit tests (see Tests section).Notes on
Mavlink.csExtLibs/Mavlink/Mavlink.csis 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.cscovers:Mavlink.csis regenerated against a diverged XML, these fail loudly> MAG_CAL_SUCCESSpartition must remain correct> MAG_CAL_SUCCESS; running/waiting/success states are notToString()— locks thatMAG_CAL_FAILEDandMAG_CAL_FAILED_RADIUSnames are stable (used as fallback display text)[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 loudlyAll 12 tests pass (verified locally with
dotnet vstest).Testing this PR
To verify the legacy UI (
ConfigHWCompass) with a firmware that hasCOMPASS_PRIO1_ID, temporarily show both pages side by side by replacing the gated block inGCSViews/InitialSetup.cs:Depends on