Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 10 months ago.
How to Get Pitch,Roll,Yaw from Quaternion
Hi , Thanks for your guide, I unable to make pitch , Roll , and Yaw parameters form Quaternion. if possible to you send me a part of code that i can make this parameters, I use this code to get Pitch , Roll and Yaw, but it's not true.
q1.getEulerAngles(); Yaw = asin(-2*(q1.v.x*q1.v.z - q1.w*q1.v.y)); Pitch = -asin(2*q1.w*q1.v.y - 2*q1.v.x*q1.v.z); Roll = -atan2(2*q1.v.y*q1.v.z + 2*q1.w*q1.v.x, -(q1.w)*q1.w + q1.v.x*q1.v.x + q1.v.y*q1.v.y - q1.v.z*q1.v.z); debug.printf("$ Yaw = %f,Pitch = %f,Roll = %f #\r\n", Yaw, Pitch, Roll);
Thanks,
Question relating to:
1 Answer
9 years, 10 months ago.
Not sure what the question is, the Quaternion class supplies the getEulerAngles() method for this purpose, it returns to you a Vector3 containing the 3 axis rotations.
Vector3 euler = q1.getEulerAngles(); debug.printf("$ Yaw = %f,Pitch = %f,Roll = %f #\r\n", euler.z, euler.y, euler.x);
The code is all in the header files supplied by the library, the conversion to Euler angles has not been thoroughly tested