Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid Gimbal lock when converting from Quaternion to Roll Pitch Yaw

I have a IMU sensor that gives me orientation in terms of Quaternion and I would like to change it to readable RPY angles.

I found the formula to convert them intrinsically from Wiki

for a quaternion q= qr+qi+qj+qk

roll=atan2(2(qr*qi+qj*qk),1-2(qi^2+qj^2))
pitch=arcsin(2(qr*qj-qk*qi))
yaw=atan2(2(qr*qk+qi*qj),1-2(qj^2+qk^2))

I understand there can be gimbal lock problem when representing in RPY. How could I avoid this when pitch approaches +/- 90 degrees

P.S. I am coding in LabVIEW

like image 687
user3763570 Avatar asked Sep 13 '25 01:09

user3763570


1 Answers

Nekomatic is right, the gimbal lock is a fundemental problem with Euler angles. Either stick with Quaternions (which I would advise), a free downloadable LabView library can be found here: https://www.winemantech.com/blog/quaternions-for-rotations-in-native-labview, the labview robotics toolbox also supports quaternions but is paid.

Otherwise keep track of when you approach a singularity (gimbal lock). In the singularity angles may flip instantaneously from 90 to -90 degrees, since in the real world you know this cannot happen you can code around it. Examples how to do this can be found here: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/

like image 138
D.J. Klomp Avatar answered Sep 16 '25 10:09

D.J. Klomp