Skip to content

MAGFit: use full WMM2025 model with date and altitude - #373

Open
j-w9 wants to merge 3 commits into
ArduPilot:mainfrom
j-w9:magfit-wmm
Open

j-w9 wants to merge 3 commits into
ArduPilot:mainfrom
j-w9:magfit-wmm

Conversation

@j-w9

@j-w9 j-w9 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #226.

"Use full WMM with date and altitude" from #81.

wmm.js now evaluates the WMM2025 spherical harmonic model (degree 12, with secular variation) instead of interpolating the 10 deg declination/inclination/intensity tables. The coefficients are embedded from NOAA's WMM2025.COF, which is public domain. The implementation was checked against both published test sets: the 12 points in WMM2025_TEST_VALUES.txt match to the 0.1 nT rounding, and the 100 points in the .COF zip's WMM2025_TestValues.txt (lat -87 to 89, 2025.0 to 2029.5, 0 to 100 km) match to within 0.001 nT.

  • The Location box gains Altitude and Date. Altitude comes from the same source as the location (ORGN, POS or AHRS_ORIGIN_ALT). The date comes from the first GPS week/time in the log, or is the current date if there is none. All can be edited.
  • expected_earth_field() returns the same fields as before (vector in mGauss NED, intensity, declination, inclination), so the fit code is unchanged.

Compared with the tables on three logs, the expected field differs by about 2 mGauss (0.4%) and declination by 0.1 to 0.25 deg, so fitted offsets move by 1 to 2 mGauss. This also moves MAGFit away from the firmware's AP_Declination tables. Logs from before 2025 use the model extrapolated backwards.

Position throughout the flight (the next item on the list) will follow separately on top of this.

Location box

@AP-Review

AP-Review commented Nov 9, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-11-09)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 174b1fd8fa.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/webtools/373/1.html#prWebTools-373

The WMM2025 implementation checks out: coefficients match NOAA's file, the field matches a reference implementation to within 0.001 nT, units, altitude sources and UTC dates are right, and nothing blocks merging.

Minor (2)
  • MAGFit/wmm.js:185 WMM2025 is only valid for 2025-2030, but any date is extrapolated silently; older log dates differ from their epoch model by up to about 0.5 deg declination. Consider stating the range in the Location tooltip or warning when the date is outside it.
  • MAGFit/magfit.js:1722 get_log_date() ignores GPS logged without instances and falls back to today's date. Only November 2020 dev builds produce such logs alongside instanced MAG, so a log.get("GPS", ...) fallback is optional; don't switch to extractStartTime(), which needs a 3D fix and would drop valid time.

@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: COMMENT

Reviewed at head 3d8e5fcd22.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/webtools/373/2.html#prWebTools-373

Re-reviewed at the new head 3d8e5fc; the WMM2025 model, units and date handling still check out and nothing blocks merging.
Since the last review, the Location tooltip now states the 2025-2030 WMM2025 validity range, which resolves that earlier note.

Minor (2)
  • MAGFit/magfit.js:797 If the Altitude box is cleared, Alt is NaN, so earth_field.Alt === Alt never matches and every Calculate redoes the body-frame rotation over the whole log; the result is the same as 0 m. Default a NaN Alt to 0 before comparing and storing it.
  • MAGFit/magfit.js:1722 Non-instanced GPS date (still open).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAGFit: new WMM2025 model

3 participants