Linear acceleration showing big measurements when device is upside down - getGravityFromOrientation issue
herbertvuijk opened this issue · 3 comments
Finding your sensor fusion algorithm was a great relieve. Since I don't want to have my product dependent on gravity and/or linear sensor algorithms that are manufacturer or android version dependent.
It works very well and intuitive, I'm only experiencing one bug. After a day of debugging and also trying to understand what quaternions are (pfft ;)) I finally debugged where things are going wrong.
When the device is in a static face up position the accelero values are for example:
- Accelero: -0.04, 2.12, 9.51 (xyz)
- GetGravity: -0.04, 2.13, 9.57
- Lin Acc: +-0, +-0, +-0
My phone is not totally flat but almost flat on a surface.
Now when I turn my phone upside down I get this:
- Accelero: -0.38, 2.03, -9.65.
- GetGravity(): 0.38, -2.02, -9.58. (note the difference with accelero positive vs negative numbers)
- Lin x, y, z are now calculated as: -0.7, 4.05, +-0
linx = -0.38 - 0.38 = -0.7
liny = 2.03 - -2.02 = 4.05
linz = -9.65 - -9.58 = 0
So linx and liny are both reporting acceleration which clearly not exists but is caused by an error in the sum op.
The error is in the GetGravity() values since that should have been: -0.38, 2.02, -9.58, that is also what the standard TYPE_GRAVITY (built in) is reporting.
I guess it has something to do with this note of you:
"Assumes a positive, counter-clockwise, right-handed rotation" on top of the getGravityFromOrientation function.
I've been debugging and testing all day now, but I don't want to implement a hacky fix to support upside down positions of the sensors. I really would prefer to fix this the right way. Can you point me in the right direction on how to fix this? Than I can open a PR and fix it on the repo as well.
@herbertvuijk
I believe I can reproduce this. Looks like something to do with the Y-axis. Looking at it now....
Great, thank you, I'm very curious :).. Had another deep dive in your code and understanding the sensor fusion quite well now, but making the changes myself is a bit over my head at the moment because of the hard to understand Quaternions .. Tried to write a basic algo myself to understand it with Euler angles but weird enough run into a similar issues, probably because I was reusing the getGravity() function.
I found your GyroScope explorer in the play store and it also does a weird flip of values when turning the phone upside. Might be something different or might be related, I was just noticing it.
I believe I have isolated the issue to the order of rotations when converting from a Quaternion to a Euler angle. I should have a new build ready to go by tomorrow.