-
Notifications
You must be signed in to change notification settings - Fork 10
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
Quaternion: Euler angles math fix and documentation #19
base: master
Are you sure you want to change the base?
Conversation
When experimenting with different math, had combined two equations. Now fixed to be exactly from https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
@joslloand Could you elaborate? In the help documentation, I have included the terms yaw pitch and roll. In the referenced wiki page these are the terms used. I just translated them into rotate tilt and tumble, the terms used by the ATK. |
I've reread the original comment and I'm still not clear on what the open question is.
I agree that it would be more widely applicable to use the yaw, pitch, roll convention. I haven't encountered RTT outside of the ATK. Similarly, you might consider using the more widely adopted axis/direction conventions than ambisonics. You could then either write additional methods for specific conventions, or those methods could live in as an extension to this one in another library (like the ATK). A thought about adapting one convention to another—if this is used in DSP or high-refresh rate situations, you'll want to make the conversion as close to the quaternion conversion as possible. So rather than going quaternion > euler then adding confusing direction inversions to get to your convention, maybe 2 different conversions directly from the quaternion would be best. Some starting points would be to have a good idea of what intrinsic (rotations axes move with the rotation) vs. extrinsic ("lab fixed", rotation axes stay put while the object rotates) rotations are. The difference between Euler and Tait-Bryan angles are (which RTT more closely resembles), and how the order of rotations should be done to get the desired result. Offhand, I recall that basically to achieve a yaw-pitch-roll as we think of them in an airplane for example, with extrinsic rotations, you would apply the individual rotations in reverse order to achieve that end orientation. |
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.
If I understand correctly, there are still outstanding decisions about semantics.
I think this discussion went in a different direction than I had expected, but it cleared some things up for me. The only thing my pull request does is convert a quaternion into the three rotation angles, whether we call them yaw-pitch-roll, or rotate-tilt-tumble is only a naming convention as far as I can see. The math behind them is the same? If so, then I propose that the math is done with yaw-pitch-roll and we can have convenience methods called rotate, tilt and tumble that simply call the yaw pitch and roll methods. The discussion became one about how to apply these angles, which I think should be up to the user. All I have done here is return the Euler angles in radians from a given quaternion. I could see in the future how the quaternion class could apply a rotation matrix for the user, but that is not what I am proposing with this PR. |
ah good - so what do you think, @mtmccrea ? |
I'd like to pitch in here. I tested the updated math by using a different device that outputs quaternions and the calculations seems to yield expected result, i.e. yaw/pitch/roll consistent with Tait-Bryan angles or symmetry axes of a plane. Again, if I understand, these represent:
I'm fuzzy on these details... it would be great if this information is 1) confirmed by others and 2) make it to the documentation in this PR. I also agree that yaw/pitch/roll should be the primary methods. |
If I understand correctly, the only thing requested in this PR is clarification in the documentation. Is that right @mtmccrea @joslloand @dmartinp ? If so, is my comment above accurate and could it be used as a blueprint for the addition to the docs to be added to this PR? |
Seems fine to me. A Yaw, Pitch, Roll convention that matches expected results for an example hardware application, e.g., Myo armband, appears appropriate to me. AND, the single rotation names meets the ATK convention. ALSO, I've just had a quick look, and there are no ATK dependencies on Quaternion at the moment, so this change won't break the ATK. A comment from @mtmccrea :
The intrinsic vs extrinsic aspect has to do with the "fixed world" or "reference" nature of the rotations. My understanding is this becomes important with compound rotations. Comments from the ATK code (thanks @mtmccrea)...
AND...
IN my understanding, as @dmartinp's contributions are single rather than compound rotations, the intrinsic vs extrinsic problem doesn't come into play here. So... more reason for me to feel this PR is ready to go. IF a compound YPR rotation were to be implemented, then I'd say observe @mtmccrea's comment:
AND, test with the hardware in question. So.. after many words... it looks ready to go to me. |
@joslloand, I've done some more looking into it, and my takeaways are
1I made a gist performing the quaternion rotation on unit vectors and comparing the rotation matrices to the atk-FOA implementations, and found that the pitch/tumble cases differ ( 2Given the referenced source for the quaternion<>Euler conversion, I'd suggest adding a clarification to the comment in the code:
The following explanation could live in a The "Euler angles" returned here are, more specifically, Tait–Bryan angles. Whereas "proper/classic Euler angles" are defined by three rotations, of which the first and third are about the same axis (e.g. z-y-z), Tait–Bryan angles specify rotations about 3 distinct axes (e.g. x-y-z). Yaw, pitch and roll correspond to heading , pitch, bank of flight dynamics: The body's orientation can be achieved by successive intrinsic rotations, e.g. in order Z-Y-X (aka, yaw-pitch-roll, "Body 3-2-1"—capital letters denote axes moving with the body), or extrinsic rotations, e.g. about x-y-z (aka "lab 1-2-3"—lowercase letters denote axes fixed to the world frame). |
Regarding the behavior of the Myo, I'm not sure what coordinate system it uses, but your description sounds like a left-handed rule. In any case, it looks like the rotation matrices generated from Quaternion class, as done in the gist in my previous post, show consistent directions with the values returned with calling the added yaw, pitch, roll methods (right-handed, counter-clockwise rule). BTW, the quaternion-to-rotation-matrix method from my gist could be added to the Quaternion class in a separate PR. |
I realized I hadn't fully reverted the math correctly. I have tested this with Myo armband which transmits quaternion values and the math seems correct.
I have also included these methods in the help file.
There could be a discussion about the orientation of the math with the tilt method. The ambisonic convention is that positive Y points to the left and moving clockwise around the x-axis (tilt) should put positive Y straight up. With the euler angles however, this motion results in -0.5pi radians. So this means the quaternion data (at least from the Myo) uses the convention that positive Y points to the right? And so a counterclockwise rotation around the x-axis results in the Euler angle of 0.5pi radians. I am by no means an expert with quaternions (which was my motivation to get the Euler angles in the first place).