1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| GD = [1 0 0 9 0 1 0 0 0 0 1 0 0 0 0 1];
syms L1 L2 L3 theta1 theta2 theta3 x y c1 s1;
L(1) = Link([theta1 0 0 0 0],'modified'); L(2) = Link([theta2 0 4 0 0],'modified'); L(3) = Link([theta3 0 3 0 0],'modified'); L(4) = Link([0 0 2 0 1],'modified');
L1=4;L2=3;L3=2;
TH3 = [1 0 0 2 0 1 0 0 0 0 1 0 0 0 0 1];
if ~isequal(size(GD), [4,4]) msg ='Wrong input format, must be a 4x4 matrix'; error(msg); end gd = GD*(TH3^-1);
x = gd(1,4); y = gd(2,4); c1 = gd(1,1); s1 = gd(2,1); c2 = (x^2 + y^2 - 4^2 - 3^2)/(2*4*3);
if c2<-1||c2>1 msg ='the target exceeds the limit'; error(msg); end s2P = sqrt(1-c2^2); s2N = -sqrt(1-c2^2); theta2P = atan2(s2P,c2); theta2N = atan2(s2N,c2);
k1P = 4 + 3 * cos(theta2P); k2P = 4 * sin(theta2P); theta1P = atan2(y,x) - atan2(k2P,k1P);
k1N = 4 + (3 * cos(theta2N)); k2N = 4 * sin(theta2N); theta1N = atan2(y,x) - atan2(k2N,k1N);
theta3P = atan2(s1,c1) - theta2P - theta1P; theta3N = atan2(s1,c1) - theta2N - theta1N;
K1P = theta1P*180/pi; K2P = theta2P*180/pi; K3P = theta3P*180/pi; K1N = theta1N*180/pi; K2N = theta2N*180/pi; K3N = theta3N*180/pi; result1 = [K1P,K2P,K3P,0] result2 = [K1N,K2N,K3N,0]
digits(4); T1 = L(1).A(theta1P)*L(2).A(theta2P)*L(3).A(theta3P)*L(4).A(0) T2 = L(1).A(theta1N)*L(2).A(theta2N)*L(3).A(theta3N)*L(4).A(0) A1 = vpa(T1) A2 = vpa(T2)
|