IMU Sensor quaternion output to local sensor axis angle

joa's icon

Hi,
i use an wireless IMU Sensor (from Yost Labs) to track movements in space.
I am a little bit confused how to calculate from the quaternion output of the sensor the actual angle of the sensor's axes relative to the calibrated orientation.
i want to work with just the roll, pitch and yaw angles from the sensors point of view, just as if a pilot sits on the sensor and navigates through space...
do i have to deal with the gimbal lock problem in this case?

too many years between now and my 3d-Matrix math lessons...

i am sure there are 3d experts here who deal with these 3d math formulas all day...

many thanks,
joa

personal_username's icon

Hey, would be interested in this, too!

jasch's icon

have a look at this

euler[0] = atan2( 2.0 * (quaternion[0]*quaternion[1] + quaternion[2]*quaternion[3]), 1.0f - 2.0 * ( quaternion[1]*quaternion[1] + quaternion[2]*quaternion[2] ) );

euler[1] = asin( 2.0 * (quaternion[0]*quaternion[2] - quaternion[3]*quaternion[1]) );

euler[2] = atan2( 2.0 * (quaternion[0]*quaternion[3] + quaternion[1]*quaternion[2]), 1.0f - 2.0 * ( quaternion[2]*quaternion[2] + quaternion[3]*quaternion[3] ) );

euler[2] *= -1.0f;

cheers

/*j

Max Patch
Copy patch and select New From Clipboard in Max.
jasch's icon

have a look at this

/*j

euler[0] = atan2( 2.0 * (quaternion[0]*quaternion[1] + quaternion[2]*quaternion[3]), 1.0f - 2.0 * ( quaternion[1]*quaternion[1] + quaternion[2]*quaternion[2] ) );
euler[1] = asin( 2.0 * (quaternion[0]*quaternion[2] - quaternion[3]*quaternion[1]) );
euler[2] = atan2( 2.0 * (quaternion[0]*quaternion[3] + quaternion[1]*quaternion[2]), 1.0f - 2.0 * ( quaternion[2]*quaternion[2] + quaternion[3]*quaternion[3] ) );
euler[2] *= -1.0f;

Max Patch
Copy patch and select New From Clipboard in Max.