Skip to content

MAGFit: option to use earth field along the flight track - #374

Open
j-w9 wants to merge 6 commits into
ArduPilot:mainfrom
j-w9:magfit-position-track
Open

j-w9 wants to merge 6 commits into
ArduPilot:mainfrom
j-w9:magfit-position-track

Conversation

@j-w9

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

Copy link
Copy Markdown
Contributor

"Use position throughout flight rather than just using a single origin" from #81. Built on #373 (its commit is included), so that should go first.

When the log has POS, the earth field is evaluated along the track (at most one point per second, skipping 0,0 before a fix) and interpolated to each attitude/compass sample time for the body frame expected field. A "Use position along flight" checkbox in the Location box controls this. It is ticked by default when there is a track and disabled when there is none. The single Location is still used for intensity and declination in the plots, and when the box is unticked.

With the WMM the field changes by roughly 1 mGauss per 10 km and 7 to 10 mGauss per 100 km (1.4 to 1.7%) at the locations I checked, so this mainly matters for long range flights. On two short logs, fitted offsets move by about 0.005 mGauss. With the box unticked, results are identical to #373, and the interpolated field matches direct evaluation at the track points.

Location box

@tridge tridge added the AIReview label Nov 9, 2026
@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 c343ceac47.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/webtools/374/1.html#prWebTools-374

WMM2025 model, altitude/date inputs and track interpolation check out (coefficients match NOAA, field values match pygeomag); two nonblocking items remain.

Should fix

  • MAGFit/magfit.js:818 With "Use position along flight" ticked, get_yaw still uses the single-location earth_field.declination (magfit.js:894) and the field-length reference is a flat earth_field.intensity line (magfit.js:416). On long routes a correct compass shows a fake yaw drift, about 8° over 60N 110W to 100W. Derive the declination per sample from atan2(y, x) of the interpolated track vector, and plot the track vector's magnitude over time.

Minor

  • MAGFit/magfit.js:1762 get_log_date returns undefined for pre-instance GPS logs, so they get today's date. log.extractStartTime() || new Date() already handles both formats, and AirspeedFit/LogFinder use it.

@j-w9
j-w9 force-pushed the magfit-position-track branch from c343cea to 24b5876 Compare November 9, 2026 04:12
@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 24b5876371.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/webtools/374/2.html#prWebTools-374

The WMM2025 model still matches the published coefficients (all 90 coefficients identical, and field values agree with pygeomag), but both items from the last review are still open.

Since then, only the Location tooltip changed (the 2025-2030 validity note); there was no code change and no reply.

Should fix

  • MAGFit/magfit.js:818 Track yaw diagnostics (still open): with "Use position along flight" on, get_yaw still uses the single earth_field.declination (magfit.js:894) and the field-length reference is flat (magfit.js:416), so a perfect compass shows about 8° of false yaw drift between 110W and 100W at 60N. Take the declination per sample from atan2(y, x) of the interpolated track vector, and plot the track magnitude.
Minor (1)
  • MAGFit/magfit.js:1762 Log date (still open, narrower than first stated): get_log_date ignores non-instanced GPS. Because load already rejects non-instanced MAG, this only affects logs from dev builds between 2 and 19 November 2020 (instanced MAG, plain GPS), which get today's date. log.extractStartTime() || new Date() handles both layouts.

Not fully reviewed: no end-to-end browser run with real logs, so on-page rendering and long-log performance are untested.

j-w9 added 3 commits November 9, 2026 07:28
With Use position along flight, the compass yaw uses the declination at
each sample and the field length plot shows the expected field along the
track.
@j-w9
j-w9 force-pushed the magfit-position-track branch from 24b5876 to 1e389b5 Compare November 9, 2026 12:32
@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 1e389b5e85.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/webtools/374/3.html#prWebTools-374

Both items from the last review are fixed and the rest of the change still checks out. One optional plot nit remains.

Since 24b5876 the branch was rebased to 1e389b5. Yaw now uses the declination along the flight track, and the field-length plot follows the track's field strength, so a perfect compass on a 60N 110W to 100W route no longer shows 8° of false drift. A blank altitude now means sea level, and the log date is also read from GPS logs without instances.

Minor (1)
  • MAGFit/magfit.js:418 With "Use position along flight" on, the expected field-length line only spans the POS track, from the first GPS fix to the last POS sample. The fit clamps compass samples outside that span to the track's end values, so samples logged before the fix have no reference line. You could extend the line to MAG_Data.start_time/end_time using the end values. The fitted parameters are not affected.

Not fully reviewed: there was no browser run with real logs, so plot rendering and long-log performance are untested.

@AP-Review

Copy link
Copy Markdown

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

Reviewed at head 9ad8c7ce4a.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/webtools/374/4.html#prWebTools-374

No open issues remain at 9ad8c7c. The change looks ready to merge.

Since 1e389b5 there is one new commit. It extends the expected field-length line to the whole log, held at the track end values (MAGFit/magfit.js:420). That fixes the last minor item: the line now matches what the fit uses, and compass samples from before the first GPS fix have a reference line.

Not fully reviewed: performance on multi-hour logs and a real long-range flight were not tested, only a short real log and synthetic routes.

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.

3 participants