数学等式 : R_measure*Rz*Ry*Rx=R_desire
R_measure为当前测量的姿态矩阵 ; Rz表示绕z旋转矩阵 ; Ry绕y旋转矩阵 ; Rx绕x旋转矩阵 ;R_desire期望的姿态矩阵;绕动坐标旋转所以右乘。
clc;
clear;
syms nx ny nz ox oy oz ax ay az
syms r11 r12 r13 r21 r22 r23 r31 r32 r33
syms alfaz betay gamax
R_measure=[nx ox ax;
ny oy ay;
nz oz az]
R_desire=[r11 r12 r13;
r21 r22 r23;
r31 r32 r33]
% R_measure=[1.732/2 0 -0.5;
% 0 1 0;
% 0.5 0 1.732/2]
% R_desire=[1 0 0;
% 0 1 0;
% 0 0 1]
% R_measure*R
Rz=RatoryZ(alfaz)
Ry=RatoryY(betay)
Rx=RatoryX(gamax)
% R_measure*Rz*Ry*Rx=R_desire 表达式
left=Rz*Ry*Rx
right=R_measure'*R_desire
right2=inv(R_measure)*R_desire
alfaz=atan2(right2(2,1),right2(1,1))
betay=atan2(-right2(3,1),sqrt(right2(1,1)^2+right2(2,1)^2))
gamax=atan2(right2(3,2),right2(3,3))
function [R]=RatoryZ(theta)
R=[cos(theta), -sin(theta), 0;
sin(theta), cos(theta), 0;
0 , 0, 1];
end
%%
function [R]=RatoryY(theta)
R=[cos(theta), 0, sin(theta);
0, 1, 0;
-sin(theta) , 0, cos(theta)];
end
function [R]=RatoryX(theta)
R=[ 1, 0, 0;
0, cos(theta), -sin(theta);
0 , sin(theta), cos(theta)];
end