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

Compass readings when pitch and roll are modified #17

Open
eah13 opened this issue Apr 7, 2017 · 3 comments
Open

Compass readings when pitch and roll are modified #17

eah13 opened this issue Apr 7, 2017 · 3 comments

Comments

@eah13
Copy link

eah13 commented Apr 7, 2017

Thanks for a great project!

Currently, the compass reading simply returns the yaw value (as in the sense_hat module, but see below for why this won't work for emulators). This can lead to incorrect values any time roll and pitch aren't set to zero.

  • set roll and pitch to 180
  • get_compass() should return 180 since the sense hat is pointing South, yet the compass still returns the yaw value, 0

First noted in trinketapp/3D-testing#11

I believe the root of this that the sense_hat module reads the yaw from the magnetometer only, and in the underlying RTIMU library this solution uses quaternions to normalize the magnetometer's yaw based on the device's pose, producing the correct output for all poses. You don't use quaternions internally (I think - and neither do we), so might be a tough fix.

I believe there is a non-quaternion calculation that could achieve the same effect of normalizing the magnetometer's readings but it's beyond my mathematical skills to derive it. If I've diagnosed this correctly and you can determine how to correctly read the compass when pitch and roll are set, we'd definitely piggy back on your code to fix this in our emulator. Likewise, if we can produce a solution I'll leave a note here.

@eah13
Copy link
Author

eah13 commented Apr 8, 2017

I found a formula that seems to correctly derive the heading, given the accelerometer's tilt. We're probably going with this as a fix as it seems to produce the expected values. The math was totally lifted though :)

https://github.com/trinketapp/skulpt/pull/38/files?w=1#diff-91b04424786e96fdd31847054a33059fR269

Edit: that math wasn't quite right. After much banging of the head against trigonometric walls, this should be the correct code:
trinketapp/skulpt@ad8c30b

Hope that helps!

@TweetPete
Copy link

So you needed to transform the raw magnetometer values into the proper plane, I guess? I'm kinda doing the same algorithms in my thesis project so the sense-hat-emulator is a interesting application for me. really cool !

@eah13
Copy link
Author

eah13 commented Apr 11, 2017

@TweetPete correct. The tilt compensation translates the magnetometer's readings into the horizontal plane.

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

2 participants