Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calibrate course based on heading changes #2340

Open
1ec5 opened this issue Feb 18, 2020 · 2 comments
Open

Calibrate course based on heading changes #2340

1ec5 opened this issue Feb 18, 2020 · 2 comments

Comments

@1ec5
Copy link
Contributor

1ec5 commented Feb 18, 2020

We currently use only the course from GPS location updates, ignoring the heading from the magnetometer, because the phone doesn’t necessarily face the same direction that the user is headed. For example, it could be sitting in a cupholder rotated to the side to face the driver, in which case the heading is constantly offset.

Unfortunately, the course is just as noisy as any other component in a GPS location update, typically noisier than headings. The map can end up rotating back and forth even as the user travels in a straight line, potentially wasting energy as the map performs unnecessary symbol placement (see mapbox/mapbox-gl-native#9031).

We should ignore changes in course that aren’t accompanied by changes in heading. The assumption is that any real change in course would require the phone to face a different direction, whether it’s in a car cupholder or in a pedestrian’s hand. (However, #2215 would switch to headings for walking directions, ignoring the course outright.)

RouteController currently passes the course to MBNavigator verbatim and never uses the heading:

locations.forEach { navigator.updateLocation(for: MBFixLocation($0)) }
bearing: location.course >= 0 ? location.course as NSNumber : nil,

LegacyRouteController only disqualifies a course if the device doesn’t support course readings at all (such as in an iPhone simulator). It doesn’t even use the heading for the so-called heading-based turn completion heuristic:

// If there is no snapped location, and the rawLocation course is unqualified, use the user's heading as long as it is accurate.
if snappedLocation == nil,
let heading = heading,
let loc = rawLocation,
!loc.course.isQualified,
heading.trueHeading.isQualified {
return CLLocation(coordinate: loc.coordinate, altitude: loc.altitude, horizontalAccuracy: loc.horizontalAccuracy, verticalAccuracy: loc.verticalAccuracy, course: heading.trueHeading, speed: loc.speed, timestamp: loc.timestamp)
}
} else if location.course.isQualified {
let userHeadingNormalized = location.course.wrap(min: 0, max: 360)
courseMatchesManeuverFinalHeading = finalHeadingNormalized.difference(from: userHeadingNormalized) <= RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion
}
var isQualified: Bool {
return self > -1
}

NavigationMapView uses the course verbatim and doesn’t use the heading for anything, though #2215 would switch to heading for walking directions:

let newCamera = camera ?? MGLMapCamera(lookingAtCenter: location.coordinate, altitude: altitude, pitch: 45, heading: location.course)

/ref #2046
/cc @mapbox/navigation-ios @avi-c @d-prukop @mapbox/navnative

@1ec5 1ec5 added feature New feature request. topic: location labels Feb 18, 2020
@1ec5 1ec5 added this to the v1.0.0 milestone Feb 18, 2020
@1ec5 1ec5 changed the title Calibrate course based on heading Calibrate course based on heading changes Feb 18, 2020
@1ec5
Copy link
Contributor Author

1ec5 commented Feb 20, 2020

@Aurora-Boreal pointed out this paper, which is focused on Android APIs but could provide some insights on the right heuristics to use when using both course and heading.

@a-kosak-mbx
Copy link

We currently use only the course from GPS location updates, ignoring the heading from the magnetometer, because the phone doesn’t necessarily face the same direction that the user is headed.

We are currently working on algorithm that couples car and phone coordinate systems even if they are relatevely floating. If phone is in cupholder it's easy enough to translate magnetometer data into car coordinate systems and fuse it with gyroscopes for higher stability and reliablility.

@1ec5 1ec5 removed this from the v1.0.0 milestone Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants