MRPT / mrpt

:zap: The Mobile Robot Programming Toolkit (MRPT)
https://docs.mrpt.org/reference/latest/
BSD 3-Clause "New" or "Revised" License
1.94k stars 629 forks source link

gimbal lock condition computing jacobian from quaternion to rpy #1289

Closed giafranchini closed 1 year ago

giafranchini commented 1 year ago

In rpy_and_jacobian the implementation of the jacobian components when gimbal lock occurs appears to be wrong to me. For example, in the case of pitch=90°, if I symbolically derived the yaw expression yaw = -2 * atan2(x(), r()) wrt the 4 quaternion components, I obtain the following:

while the other two components should be zeros. Instead, in the current implementation I found:

and the other two components equal to zero. This leads to NaN results when trying to convert quaternions when x() goes to zero.

jlblancoc commented 1 year ago

Wow, can't find an explanation for it! Thanks a lot for investigating it and reporting. It's now covered by unit tests and fixed in #1290