xioTechnologies/Fusion

Allow configuring XYZ order in FusionQuaternionToEuler

Closed this issue · 3 comments

I found that what I consider "roll" was being applied second in Euler ordering when passing through the FusionQuaternionToEuler function, making for really funky gimbal-locking type behavior when rotating my device +/- 90 degrees. I had to actually create a copy of the function in my own repo and rewrite it to get the ordering I needed. The gimbal locking would still be there, but since it's moved to a different axis, it's not really going to be hit in my application after moving it. It would be nice if this function allowed for choosing the ordering.

XYZ and ZYX Euler angles are both subject to gimbal lock when the rotation around Y approaches ±90°. Use of XYZ Euler angles would therefore not achieve your solution you are suggesting. Furthermore, XYZ Euler angles are unconventional. Most applications use either ZXZ or ZYX. Are you able to share a link to demonstrate XYZ Euler angles being used, or a specific requirement for this sequence?

I suggest you avoid using Euler angles altogether and instead use either quaternions or rotation matrices to achieve the transformations and calculations required by your application.

Here is the rewrite of the function as I described it.

And here is the probably more relevant code that uses the Fusion library to get the quaternion orientation of the device.

You have implemented YZX Euler angles. This sequence will be subject to gimbal lock when the rotation around Z approaches ±90°. Is this not an issue for your application?

I believe that your description, "Fusion switches pitch and roll for us..." is incorrect. My understanding is that the angles are not switched in the sequence, they are just labelled differently. There are many different naming conventions but this doesn't change the underlying mathematics. An X rotation may be labelled pitch, roll, elevation, inclination, or bank depending on the application and axis assignments. If your application labels it pitch and Fusion labels it roll, then you only need to change the labels, not the maths.

I am currently unconvinced of the requirement to support non-standard Euler angle sequences. I expect that your current solution is a workaround and that the proper solution is to use a quaternion or rotation matrix representation.