Advertisement
Guest User

DRR cv3

a guest
Nov 29th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 5.12 KB | None | 0 0
  1. function R = myinvd(robot,J,dJ,ddJ,cnf)
  2. %
  3. % myinvd(robot,J,dJ,ddJ,cnf) - inverse dynamic
  4. %
  5. % Input parameters:
  6. %   robot: struct  ... description of the manipulator. You can ignore and
  7. %                      use description and parameters from your variant.
  8. %   J: [2 x n]     ... joint coordinates. Each column J(:,i) contains
  9. %                      2 joint coordinates (angles and or displacements).
  10. %   dJ: [2 x n]    ... joint velocities. Each column dJ(:,i) contains
  11. %                      2 joint velocities (angular velocity).
  12. %   ddJ: [2 x n]   ... joint accelerations. Each column dJ(:,i) contains
  13. %                      2 joint accelerations (angular acceleration).
  14. %   cnf: [1 x n]   ... robot configuration sign. Configuration of final two
  15. %                      links is defined by position of end point in
  16. %                      relation to line defined by their oposit ends.
  17. %
  18. % Output parameters:       
  19. %   R: [2 x n]     ... torques and forces provided by drives for each input
  20. %                      configuration which is defined by J and cnf. Each
  21. %                      column of R must contain torques for corresponding
  22. %                      input configuration. If there is no solution for
  23. %                      input configuration, the output value for the
  24. %                      configuration should be NaN.
  25. %
  26. % All angles are in radians !
  27.  
  28. % preallocation
  29. R = zeros(2, size(J,2));
  30. R(:) = NaN;
  31. for i = 1:size(J,2)
  32.     R(:,i) = my_myinvd(robot,J(:,i),dJ(:,i),ddJ(:,i),cnf(i));
  33. end
  34.  
  35. % R(:,4:end)=NaN;
  36. % R(:,1:2)=NaN;
  37. end
  38.  
  39. function output = my_myinvd(robot,J,dJ,ddJ,cnf)
  40. %% SET CONSTANTS %%
  41. phi4 = robot.rotations(1);
  42. P1 = [robot.origins(1);
  43.       robot.origins(2)]/10;
  44. P2 = [robot.origins(3);
  45.       robot.origins(4)]/10;
  46. P1x = P1(1);
  47. P1y = P1(2);
  48. P2x = P2(1);
  49. P2y = P2(2);
  50.  
  51. L1 = robot.links(1,2)/20;
  52. L2 = robot.links(2,2)/20;
  53. L3 = robot.links(2,1)/20;
  54.  
  55. C=mydkt(robot, J);
  56. C1=C{1};
  57. C2=C{2};
  58.  
  59. d=J(1)/10;
  60. dd = dJ(1)/10;
  61. ddd = ddJ(1)/10;
  62.  
  63. phi1 = J(2);
  64. phi1d = dJ(2);
  65. phi1dd = ddJ(2);
  66.  
  67. Ax=d*cos(phi4)+P1x;
  68. Ay=d*sin(phi4)+P1y;
  69. Bx=L1*2*cos(phi1)+P2x;
  70. By=L1*2*sin(phi1)+P2y;
  71.  
  72. %% DECIDE SOLUTION %%
  73.  
  74. Wx1=C1(1)/10;
  75. Wy1=C1(2)/10;
  76. Wx2=C2(1)/10;
  77. Wy2=C2(2)/10;
  78.  
  79. K=(By-Ay)*Wx1-(Bx-Ax)*Wy1 +Ay*(Bx-Ax)-Ax*(By-Ay)
  80.  
  81. if (abs(sign(K)-cnf) > 1e-3)
  82.     Wx=Wx2;
  83.     Wy=Wy2;
  84. else
  85.     Wx=Wx1;
  86.     Wy=Wy1;
  87. end
  88.  
  89. if isnan(Wx) || isnan(Wy)
  90.     output = [NaN;NaN];
  91.     return
  92. end
  93.  
  94. %% VECTOR METHOD %%
  95.  
  96. phi2 = atan2(Wy-By, Wx-Bx);
  97. phi3 = atan2(Ay-Wy, Ax-Wx);
  98.  
  99. qd = [dd; phi1d];
  100. qdd = [ddd; phi1dd];
  101.  
  102. Jq = [-0.5*cos(phi4) -L1*sin(phi1);-0.5*sin(phi4) L1*cos(phi1)];
  103. Jz = [-L2*sin(phi2) -L3*sin(phi3); L2*cos(phi2) L3*cos(phi3)];
  104.  
  105. zd = -(Jz\Jq)*qd;
  106. phi2d = zd(1);
  107. phi3d = zd(2);
  108.  
  109. Jqd = [0 -L1*cos(phi1)*phi1d; 0 -L1*sin(phi1)*phi1d];
  110. Jzd = [-L2*cos(phi2)*phi2d -L3*cos(phi3)*phi3d; -L2*sin(phi2)*phi2d -L3*sin(phi3)*phi3d];
  111. zdd = -inv(Jz)*(Jq*qdd + Jzd*zd + Jqd*qd);
  112. phi2dd = zdd(1);
  113. phi3dd = zdd(2);
  114.  
  115. %% WORLD COORDINATES %%
  116.  
  117. Axdd = ddd*cos(phi4);
  118. Aydd = ddd*sin(phi4);
  119.  
  120. S1xdd = -L1*(cos(phi1)*phi1d^2 + sin(phi1)*phi1dd);
  121. S1ydd = L1*(-sin(phi1)*phi1d^2 + cos(phi1)*phi1dd);
  122. S2xdd = 2*S1xdd - L2*(cos(phi2)*phi2d^2 + sin(phi2)*phi2dd);
  123. S2ydd = 2*S1ydd + L2*(-sin(phi2)*phi2d^2 + cos(phi2)*phi2dd);
  124. S3xdd = Axdd + L3*(cos(phi3)*phi3d^2 + sin(phi3)*phi3dd);
  125. S3ydd = Aydd - L3*(-sin(phi3)*phi3d^2 + cos(phi3)*phi3dd);
  126.  
  127. f1= [           -1             0              1             0             0             0              0             0 0 0];
  128. f2= [            0            -1              0             1             0             0              0             0 0 0];
  129. f3= [-L1*sin(phi1)  L1*cos(phi1)  -L1*sin(phi1)  L1*cos(phi1)             0             0              0             0 0 1];
  130. f4= [            0             0             -1             0             1             0              0             0 0 0];
  131. f5= [            0             0              0            -1             0             1              0             0 0 0];
  132. f6= [            0             0  -L2*sin(phi2)  L2*cos(phi2) -L2*sin(phi2)  L2*cos(phi2)              0             0 0 0];
  133. f7= [            0             0              0             0            -1             0              1             0 0 0];
  134. f8= [            0             0              0             0             0            -1              0             1 0 0];
  135. f9= [            0             0              0             0 -L3*sin(phi3)  L3*cos(phi3)  -L3*sin(phi3)  L3*cos(phi3) 0 0];
  136. f10=[            0             0              0             0             0             0     -cos(phi4)    -sin(phi4) 1 0];
  137.  
  138. D = [f1;f2;f3;f4;f5;f6;f7;f8;f9;f10]';
  139.  
  140.  
  141. %% INVERZNI DYNAMICKA ULOHA &&
  142. ro = 2;
  143. ma = 0.6;
  144. m1 = L1*ro*2;
  145. m2 = L2*ro*2;
  146. m3 = L3*ro*2;
  147. I1 = m1*4*L1^2/12;
  148. I2 = m2*4*L2^2/12;
  149. I3 = m3*4*L3^2/12;
  150.  
  151. M = diag([m1 m1 I1 m2 m2 I2 m3 m3 I3 ma]);
  152. % Q =      [0  0  ma 0  0  0  0  0  0  cos(phi4)*F  sin(phi4)*F  0];
  153. a = [S1xdd S1ydd phi1dd S2xdd S2ydd phi2dd S3xdd S3ydd phi3dd ddd]';
  154. R = D'\(M*a);
  155. % lambda = R(1:10);
  156. Moment = R(9);
  157. F = R(10);
  158. output = [Moment; F];
  159. end
  160.  
  161.  
  162.  
  163. % here assign values to R for each input configuration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement