Correct the compass with the error measured against the GPS course - #104
Open
rodrigohpalmeirim wants to merge 1 commit into
Open
Correct the compass with the error measured against the GPS course#104rodrigohpalmeirim wants to merge 1 commit into
rodrigohpalmeirim wants to merge 1 commit into
Conversation
The compass is often off by tens of degrees, sometimes reversed, so the heading it provided at stops was frequently wrong. While riding, pair each gps course with the steady compass reading of the previous two seconds and keep a short-memory circular mean of the difference; apply it when the compass takes over after the course goes stale. The estimate is only used once a few samples agree, and is dropped whenever the screen visibility changes, since a dark screen mid-trip means the phone went into a pocket.
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.
The compass takes over the heading when we stop, but it's often off by tens of degrees and sometimes reversed outright (uncalibrated magnetometer, steel of the bike and mount). While riding we have a trusted heading from the GPS course, so this measures the compass error along the current leg and takes it out when the compass has the say.
Offset estimator (
src/lib/compass-offset.ts)course − compass, using the compass average over the stability window to shed jittervisibilitychange: the screen is kept awake during a trip, so it going dark means the phone was pocketed, where it points anywhere but forward. What was learned before doesn't hold in there, and what's learned in there doesn't hold once it's outWiring (
location.ts,compass.ts)headingis used as a calibration reference, never the anchor-derived bearing between fixescurrentHeadingreceives the corrected value, which also lands close to the last GPS course so the marker no longer snaps at the handoverTest plan
npm run check, eslint on touched files,vitest run(9 new tests for the estimator; full suite passes)