Robotics-Documents/matlab/myIK.m

41 lines
971 B
Mathematica
Raw Permalink Normal View History

T05 = myFk(0.001,-0.653+pi/2,-0.22,0.001,pi/2);
L1=0.151;L3=0.350; L4=0.139;
Pe = T05(1:3,4);
Ze = T05(1:3,3);
%W
Pw = Pe - L4*Ze;
%theta1
theta_1 = atan2(Pw(2),Pw(1));
%theta2
%L1^2 + L3^2 - 2*L1*L3*cos_th2 = norm(Pw)^2
cos_th2 = (L1^2 + L3^2 - norm(Pw)^2)/(2*L1*L3);
theta_2 = acos(cos_th2);
%T02
T01 = dh2Tmat(theta_1,L1,0,pi/2); %1
T12 = dh2Tmat(theta_2,0,0,pi/2); %2
T02 = T01*T12;
%T25 T05 = T02 * T25
T = inv(T02) * T05;
%T25_f = dh2Tmat(0,0.5,0,-pi/2)*dh2Tmat(pi/4,0,0,pi/2)*dh2Tmat(0,0.3,0,0);
%(theta_5)
theta_3 = atan2(T(2,3),T(1,3));
theta_4 = atan2(sqrt(T(1,3)^2+T(2,3)^2),T(3,3));
theta_5 = atan2(T(3,2),-T(3,1));
%(theta_5)
theta_33 = atan2(-T(2,3),-T(1,3));
theta_44 = atan2(-sqrt(T(1,3)^2+T(2,3)^2),T(3,3));
theta_55 = atan2(-T(3,2),T(3,1));
theta = [theta_1,theta_2,theta_3,theta_4,theta_5;
theta_1,theta_2,theta_33,theta_44,theta_55;]