quat2angle / atan2 strange quadrant change when calculating angle
11 views (last 30 days)
Show older comments
Hi,
I'm working with IMU systems and calculating rotation angles from quaternions using the quat2angle function. I encountered a problem I believe in the atan2 function. As you can see in the first figure below the computed angle becomes negative.
In Fig1, you can see three lines:
- In blu, the angle was computed using the quat2angle function with the rotation sequence 'YZX', (it is the first output).
- In orange, the angle was computed with an Android app (Dart language).
- In dashed yellow, the angle was computed with my Dart algorithm translated into Matlab code.
I think the problem is in the atan2 function because it is used to compute the angle in my algorithm.
This behavior doesn't always happen. I have recordings where the angle computation is fine, like here:
Do you know what the reason is, and do you have a solution for it?
I have attached the files containing the quaternions of the two recordings
2 Comments
David Goodmanson
on 23 Feb 2024
Hi Matteo,
How do you know that your dart calculation in Matlab is the one that's incorrect? It always agrees with quat2angle so if anything the data seems to imply that the dart calculation in red is the one with the problem..
Answers (1)
James Tursa
on 4 Mar 2024
You don't show us your code, but in general I would note that angle changes like this are sometimes the result of whole quaternion sign flips. I.e., q and -q represent the same orientation, but depending on the algorithm you use when you extract angles you can get different sign flipped results. In these cases, you can sometimes fix things by ensuring that the largest magnitude element of the quaternion doesn't change sign from one sample to the next. That is, at each step beyond the first step, find the largest magnitude element and compare it to the same element in the previous quaternion. If the sign has changed, then flip the signs of all the elements of the current quaternion. Do this one step at a time to your entire stream.
See Also
Categories
Find more on Array Geometries and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!