-
Notifications
You must be signed in to change notification settings - Fork 224
Fix numerical precision issues in quaternion to RPY conversion #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rolling
Are you sure you want to change the base?
Conversation
Addresses numerical precision errors that occur during quaternion-to-matrix conversion, particularly near gimbal lock singularities. When matrix elements contain small numerical errors (around 1e-12), the atan2 function can return incorrect angles, such as 45° instead of 0° for roll values. Changes: - Add epsilon thresholding (1e-10) to matrix elements before RPY computation - Improve singularity detection to handle near-singular cases - Add safety checks to prevent division by near-zero cosine values - Protect atan2 calls when both arguments are very small - Apply fixes to both Matrix3x3::getEulerYPR() and tf2::impl utilities - Update .gitignore with comprehensive build and temporary file patterns This resolves issues where tf2_echo and other tf2 tools would report incorrect RPY angles due to floating-point precision limitations.
Changes the epsilon threshold from 1e-10 to 1e-8 to be more conservative and avoid interfering with legitimate small values in normal quaternion conversions. The 1e-8 threshold still effectively catches the numerical precision errors that cause incorrect RPY results while ensuring existing tests continue to pass. Analysis showed that quaternion-to-matrix conversion preserves error magnitude, so a threshold of 1e-8 provides adequate safety margin above typical floating-point precision errors without affecting normal operations.
- Reorder headers to follow cpplint convention (C++ system headers first) - Remove trailing whitespace from empty lines - Addresses cpplint and uncrustify test failures
Signed-off-by: Roman Wu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me, but I would like to see some tests added around this singularity case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more change here, but I think we are good.
Signed-off-by: Roman Wu <[email protected]>
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
Pulls: #811 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singularityGimbalLock
is failing
Description
Fixes #796
Addresses numerical precision errors that occur during quaternion-to-matrix conversion, particularly near gimbal lock singularities. When matrix elements contain small numerical errors (around 1e-12), the atan2 function can return incorrect angles, such as 45° instead of 0° for roll values.
Changes:
This resolves issues where tf2_echo and other tf2 tools would report incorrect RPY angles due to floating-point precision limitations.
Is this user-facing behavior change?
precision issues
- Before: RPY (degree) [45.000, -90.000, 0.000] (incorrect)
- After: RPY (degree) [0.000, -90.000, 0.000] (correct)
- Near gimbal lock singularities
- When quaternions come from tf2 lookupTransform operations
- When dealing with transformations that should have zero roll/yaw but show small numerical errors
Did you use Generative AI?
No.
Additional Information