Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get pitch, yaw, roll from a CMRotationMatrix

I have a CMRotationMatrix *rot and i would like to get the pitch, yaw, roll from the matrix. Any ideas how i could do that?

Thanks

like image 268
Jonas Schnelli Avatar asked Feb 28 '12 08:02

Jonas Schnelli


People also ask

How do you calculate roll pitch yaw?

magx = magnetometer[0]*cos(pitch)+magnetometer[1]*sin(roll)*sin(pitch) + magnetometer[2]*sin(pitch)*cos(roll); magy = -magnetometer[1]*cos(roll) + magnetometer[2]*sin(roll); yaw = atan2(-magy,magx)*180/M_PI; I'm getting incorrect yaw data but I'm not sure about the equations which I found on the internet.

How do I find my yaw?

Yaw velocity can be measured by measuring the ground velocity at two geometrically separated points on the body, or by a gyroscope, or it can be synthesized from accelerometers and the like. It is the primary measure of how drivers sense a car's turning visually.

What is roll pitch yaw for Euler angles?

XYZ Roll-Pitch-Yaw Angles in Robotics In the previous lesson, we learned about Euler angles, and we saw that Euler angles refer to the angles in a sequence of rotations in a body-fixed frame. On the other hand, the roll-pitch-yaw angles are a sequence of rotations about axes of the space frame.


2 Answers

Its better to use the Quaternion than Euler angles.... The roll, pitch and yaw values can be derived from quaternion using these formulae:

roll  = atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z)
pitch = atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z)
yaw   =  asin(2*x*y + 2*z*w)

It can be implemented as:

CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion;
myRoll = radiansToDegrees(atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z)) ;
myPitch = radiansToDegrees(atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z));
myYaw = radiansToDegrees(asin(2*quat.x*quat.y + 2*quat.w*quat.z));

where the radianstoDegrees is a preprocessor directive implemented as:

#define radiansToDegrees(x) (180/M_PI)*x

This is done to convert the radian values given by the formulae, to degrees.

More information about the conversion can be found here: tinkerforge and here:Conversion between Quaternions and Euler angles.

like image 125
iSeeker Avatar answered Oct 02 '22 23:10

iSeeker


pitch, yaw, roll from the matrix. Any ideas how i could do that?

In which order? Pitch, yaw and roll, commonly called Euler angles, don't represent rotations unambigously. Depending on the order you carry out the individual sub-rotations you end up with completely different rotation matrices.

My personal recommendation: Don't use Euler angles at all, they just call for (numerical) trouble. Use a matrix (you already do) or a quaternion.

like image 39
datenwolf Avatar answered Oct 02 '22 23:10

datenwolf