来源
机器人运动学计算时,有个角度 pi/2,求出来 cos(pi/2) = 6.1232e-17
。这个问题 导致 传递矩阵中包含这个指数,不方便看,也没法转换成 latex 格式。
方法
cos(sym(pi/2))
代码
T_3_4(1:3,1:3) = double(Rx(sym(pi/2))) * Rz(-1*theta_4);
% 旋转矩阵 函数,如果输入是 数值,需要转换成 符号函数,两个矩阵进行符号运算后再用 double 函数进行数值还原。
function A = Rx(tmp)
syms theta real;
theta = tmp;
A = [
1 0 0 ;
0 cos(theta) -sin(theta) ;
0 sin(theta) cos(theta) ;
];
end
function A = Ry(tmp)
syms theta real;
theta = tmp;
A = [
cos(theta) 0 sin(theta) ;
0 1 0;
-sin(theta) 0 cos(theta) ;
];
end
function A = Rz(tmp)
syms theta real;
theta = tmp;
A = [
cos(theta) -sin(theta) 0;
sin(theta) cos(theta) 0;
0 0 1;
];
end