Z-axis orientation gets different values depends on height angle of device.
NasserTahani opened this issue · 2 comments
I've used your awesome sensor fusion to get device orientation around 3 axes. The problem is that the z-axis orientation has two values when the device is pointed towards the ground and the same situation when the device is pointed upward. The image can demonstrate the problem to be better understand.
As the figure shows, the absolute combination of two angles results in 180 degrees. I've used accelerometer and magnetometer to calculate orientation which gives me the correct z-axis independent of device hight angle.
I've changed this line of code of method getOrientationVectorFromAccelerationMagnetic in Rotation.Util to the second oreder and it gives the desired result.
default:
Rotation rotation = new Rotation(RotationOrder.XYZ, RotationConvention.VECTOR_OPERATOR, (double)rv[1], (double)(-rv[2]), (double)rv[0]);
edited:
Rotation rotation = new Rotation(RotationOrder.XYZ, RotationConvention.VECTOR_OPERATOR, (double) rv[0], (double) (rv[1]), (double) rv[2]);
Does it the right thing to change without any bad effect on fusion orientations?
I have double checked on a couple of my devices and the default calculations seem to work. It may be that you have a device with a sensor that happens to be oriented differently. I think your changes should be fine, but double check them if you use a different device. If you are confident your changes work on all devices, please open a PR.