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

iOS alpha drift #3

Open
RGARawleCurtis opened this issue Oct 22, 2014 · 4 comments
Open

iOS alpha drift #3

RGARawleCurtis opened this issue Oct 22, 2014 · 4 comments

Comments

@RGARawleCurtis
Copy link

On iOS the alpha value can drift pretty dramatically. This seems to be less a function of time, and more a function of how much the phone is moved while listening to the device orientation event i.e. the more that the phone is moved, the more the alpha drifts and not the more time passes the more the alpha drifts.

This happens on both Safari and Chrome for iOS.

Since the raw values are affected by the same problem, it seems to be an issue with the underlying deviceorientation event on iOS browsers, but perhaps there is a way to compensate for it during the normalization process.

@richtr
Copy link
Contributor

richtr commented Oct 23, 2014

This is an interesting problem and this drift is certainly being introduced in to the data at the platform level.

To compensate for this drift we actually need more data. What we could try to do is to periodically 'reset' the alpha with a offset value derived from webkitCompassHeading every X seconds. I haven't got around to doing this yet but it should help to fix the drift you are seeing.

Performing this drift compensation may make the orientation data jerky as we 'snap' the orientation to the correct heading. Thus, it may also make sense to establish what the drift is and then use e.g. a low-pass filter to smoothly apply that drift compensation over a short time period to avoid this 'snap'.

Not trivial but this idea may have potential. Pull requests welcome of course :)

@DBraun
Copy link

DBraun commented Feb 19, 2016

That low-pass filter may be simple to implement, although I've had some difficulty adding it to this repo.

http://stackoverflow.com/questions/491738/how-do-you-calculate-the-average-of-a-set-of-angles

What has been confusing me is that webkitCompassHeading isn't what I expect when my device isn't flat on a table. I think I need to convert webkitCompassHeading to another number before I use this filtering process from stack overflow.

@austinmayer
Copy link

+1 on accounting for iOS compass drift

@jasan-s
Copy link

jasan-s commented Oct 29, 2016

would something like this work?

let tilt = {
  alpha: 0,
  beta: 0,
  gamma: 0
}

function lowPass (prev, curr, co) {
  return prev * co + curr * (1 - co)
}

 const alpha = data.do.alpha
  tilt.alpha = lowPass(tilt.alpha, alpha, 0.8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants