matlab - Math behind some quaternion code and gimbal lock -


i have following matlab code gives rotation matrix quaternion. person did said used library , rotation matrix rotation matrix quaternion

the rotation matrix according code looks like

rot matrix according code

the diagonal elements , signs changed. can someonw explain me math or conditions disparity between two.

q0 = quat(1); q1 = quat(2); q2 = quat(3); q3 = quat(4);  %% set f2q 2*q0 , calculate products f2q = 2 * q0; f2q0q0 = f2q * q0; f2q0q1 = f2q * q1; f2q0q2 = f2q * q2; f2q0q3 = f2q * q3;   %% set f2q 2*q1 , calculate products  f2q = 2 * q1;  f2q1q1 = f2q * q1;  f2q1q2 = f2q * q2;  f2q1q3 = f2q * q3;   %% set f2q 2*q2 , calculate products  f2q = 2 * q2;  f2q2q2 = f2q * q2;  f2q2q3 = f2q * q3;  f2q3q3 = 2 * q3 * q3;   %% calculate rotation matrix assuming quaternion normalized  r(1, 1) = f2q0q0 + f2q1q1 - 1;  r(1, 2) = f2q1q2 + f2q0q3;  r(1, 3) = f2q1q3 - f2q0q2;  r(2, 1) = f2q1q2 - f2q0q3;  r(2, 2) = f2q0q0 + f2q2q2 - 1;  r(2, 3) = f2q2q3 + f2q0q1;  r(3, 1) = f2q1q3 + f2q0q2;  r(3, 2) = f2q2q3 - f2q0q1;  r(3, 3) = f2q0q0 + f2q3q3 - 1; 

also...

the rotation matrix used find euler angles deals gimbal lock

 %%calculate pitch angle -90.0 <= theta <= 90.0 deg         pitchdeg = asin(-r(1, 3)) * (180 / pi);          %% calculate roll angle range -180.0 <= phi < 180.0 deg         rolldeg = atan2(r(2, 3), r(3, 3)) * (180 / pi);          %% map +180 roll onto functionally equivalent -180 deg roll         if (rolldeg == 180)              rolldeg = -180;         end          %% calculate yaw (compass) angle 0.0 <= psi < 360.0 deg         if (pitchdeg == 90)              %% vertical upwards gimbal lock case             yawdeg = (atan2(r(3, 2), r(2, 2)) * (180 / pi)) + rolldeg;         elseif (pitchdeg == -90)              %% vertical downwards gimbal lock case             yawdeg = (math.atan2(-r(3, 2), r(2, 2)) * (180 / pi)) - rolldeg;          else              %% general case             yawdeg = atan2(r(1, 2), r(1, 1)) * (180 / pi);         end          %% map yaw angle psi onto range 0.0 <= psi < 360.0 deg         if (yawdeg < 0)              yawdeg = yawdeg + 360;         end          %% check rounding errors mapping small negative angle 360 deg         if (yawdeg >= 360)              yawdeg = 0;         end          euler.roll = rolldeg;         euler.pitch = pitchdeg;         euler.yaw = yawdeg; 

googling formula convert quaternion euler angles gave me formula not attach because dont have enough reputation can find in wiki conversion_between_quaternions_and_euler_angles

the terms different comparing diagonal of rotation matrix. also, there math behind compensation gimbal lock?

the imu uses north-east-down system

i using euler angles visualize gyro. kind of guidance appreciable


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -