Open eah13 opened 7 years ago
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: https://github.com/trinketapp/skulpt/pull/38/commits/ad8c30b1838e8acaba2f722f793e8528b2cace90
Hope that helps!
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 !
@TweetPete correct. The tilt compensation translates the magnetometer's readings into the horizontal plane.
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.get_compass()
should return 180 since the sense hat is pointing South, yet the compass still returns the yaw value, 0First noted in https://github.com/trinketapp/3D-testing/issues/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.