Take the yaw rate about the vertical and stamp fixes with their GNSS time
The phone's CAM and VAM used the gyroscope's z axis as the yaw rate. That is rotation about the screen's normal, so it only matched the bike's turning with the phone flat, screen up: tilted on a handlebar it read about 64 % at 50 degrees, upright close to nothing. The gyroscope is now projected onto gravity (TYPE_GRAVITY), which gives the rotation about the true vertical however the phone is held, averaged over 100 ms. Gyroscope and gravity run at SENSOR_DELAY_GAME for this; the yaw rate used to come from a single sample at SENSOR_DELAY_UI. Fixes now carry their own monotonic time (Location.getElapsedRealtimeNanos), speed and bearing accuracy and provider, and sensor samples their own SensorEvent.timestamp. What goes on air is the GNSS time of the fix itself, from its monotonic age (GnssTimeSource.atElapsedRealtime), so neither the phone's clock setting nor a step of it between the fix and transmission reaches the CAM or GN timestamps. The loop's own intervals (elevated rate, VAM generation rules) and the GNSS speed differencing for acceleration use the monotonic clock too, so a clock set back can no longer hold VAMs off. This is phase 0 of GNSS/IMU sensor fusion: YawRateEstimator is the first piece of domain/fusion. Unit-tested; the bench and ride checks are in TODO.
This commit is contained in:
@@ -58,6 +58,20 @@ object GnssTimeSource {
|
||||
return ItsTime.onGnssTime(systemMs, lastErrorMs?.let { systemNow + it }, systemNow)
|
||||
}
|
||||
|
||||
/**
|
||||
* GNSS time of an instant given on the monotonic `elapsedRealtimeNanos` base, such as a fix's
|
||||
* [GnssReading.elapsedRealtimeNanos]: GNSS time now, minus the instant's age.
|
||||
*
|
||||
* Prefer this to [correct] on a stored wall-clock stamp. The age comes from the monotonic
|
||||
* clock, and the wall clock is only read now, inside [correct], where its error cancels out.
|
||||
* A phone clock that is stepped between the fix and its transmission (automatic time catching
|
||||
* up, or someone setting it) therefore cannot move the result.
|
||||
*/
|
||||
fun atElapsedRealtime(elapsedRealtimeNanos: Long): Long {
|
||||
val ageMs = (SystemClock.elapsedRealtimeNanos() - elapsedRealtimeNanos) / 1_000_000L
|
||||
return correct(System.currentTimeMillis() - ageMs)
|
||||
}
|
||||
|
||||
private fun noteSource(gnssNow: Long?, systemNow: Long) {
|
||||
val usingGnss = gnssNow != null
|
||||
if (lastUsedGnss == usingGnss) return
|
||||
|
||||
Reference in New Issue
Block a user