Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 4.38 KB | None | 0 0
  1.  
  2. clc,close all,clear all
  3.  
  4. % DH parameters
  5. %
  6. % L(1) = Link('revolute','d',0,'a',0,'alpha',pi/2,'m',0);
  7. % L(2) = Link('revolute','d',0,'a',5,'alpha',0,'m',2,'I',diag([0.1 0.1 0.1]));
  8. % L(3) = Link('revolute','d',0,'a',5,'alpha',0,'m',1,'I',diag([0.01 0.01 0.01]));
  9. %
  10. % Robot = SerialLink(L,'name','Anthr');
  11. %
  12. %
  13. % Robot.plot([0 0 0],'workspace',[-20 20 -20 20 -20 20]);
  14. % Robot.teach
  15.  
  16. %
  17. % q_config = [0 pi/10 pi/2];
  18. % q_config_d = [0 0 0];
  19. %
  20. % % Robot.plot(q_config);
  21. %
  22. % T = Robot.fkine(q_config);
  23. %
  24. % q = Robot.ikine(T,'mask',[1 1 1 0 0 0]);
  25. %
  26. % B = Robot.inertia(q_config);
  27. % C = Robot.coriolis([q_config q_config_d]);
  28. % g_vec = Robot.gravload(q_config);
  29. %
  30. % tic
  31. % [t,q,qd] = Robot.fdyn(10, [], q_config);
  32. % toc
  33. %
  34. % hold on
  35. %
  36. % t = [0:.05:1];
  37. %
  38. % q_0 = [0 0 0];
  39. % q_r1 = [0 -pi/10 0]
  40. % % Robot.plot(q_r1);
  41. % t = [0:.05:1];
  42. % q_r2 = [pi -pi/10 pi/3];
  43. % % Robot.plot(q_r2);
  44. %
  45. % [q,qd,qdd] = jtraj(q_0, q_r2, t); % compute joint coordinate trajectory
  46. % plot(t, qdd)
  47. % tau = Robot.rne(q, qd, qdd); % compute inverse dynamics
  48.  
  49. % B(q)qdd+C(q,qd)qd+g(q) = tao
  50. %
  51. % qdd = inv(B)(tao-g(q)-C(q,qd)qd)
  52.  
  53.  
  54.  
  55. %spherical arm
  56.  
  57. % L(1) = Link('revolute','d',0,'a',0,'alpha',-pi/2);
  58. % L(2) = Link('revolute','d',5,'a',0,'alpha',pi/2);
  59. % L(3) = Link('prismatic','theta',0,'a',0,'alpha',0);
  60. %
  61. % L(2).qlim = [-pi/100 pi/2];
  62. % L(3).qlim = [0.1 2]; %limit for prismaic joint
  63. %
  64. % Robot = SerialLink(L,'name','Spher');
  65. %
  66. %
  67. % Robot.plot([0 0 0]);
  68. % Robot.teach
  69.  
  70. L(1) = Link('prismatic','theta',0,'a',0,'alpha',pi/2,'m',0); %only to set first prismatic joint to Y direction
  71. L(2) = Link('prismatic','theta',0,'a',0,'alpha',-pi/2,'m',0);
  72. L(3) = Link('revolute','d',0,'a',0,'alpha',pi/2,'m',2);
  73. L(4) = Link('revolute','d',0,'a',5,'alpha',0,'m',2);
  74. L(5) = Link('revolute','d',0,'a',0,'alpha',pi/2,'m',1);
  75. L(6) = Link('revolute','d',3,'a',0,'alpha',-pi/2,'m',3);
  76. L(7) = Link('revolute','d',0,'a',0,'alpha',pi/2,'m',2);
  77. L(8) = Link('revolute','d',3,'a',0,'alpha',0,'m',1);
  78. L(1).qlim = [0.0 0.0];
  79. L(2).qlim = [0.0 20.0];
  80. Robot = SerialLink(L,'name','Suturing');
  81.  
  82. q0 = [0 1 0 0 0 0 0 2];
  83. qe = [0 5 -pi/2 0 0 pi/2 pi/4 2];
  84.  
  85. % L(1) = Link('revolute','d',0,'a',0,'alpha',pi/2,'m',0);
  86. % L(2) = Link('revolute','d',0,'a',5,'alpha',0,'m',2);
  87. % L(3) = Link('revolute','d',0,'a',0,'alpha',pi/2,'m',1);
  88. % L(4) = Link('revolute','d',3,'a',0,'alpha',-pi/2,'m',3);
  89. % L(5) = Link('revolute','d',0,'a',0,'alpha',pi/2,'m',2);
  90. % L(6) = Link('revolute','d',3,'a',0,'alpha',0,'m',1);
  91. % Robot = SerialLink(L,'name','Suturing');
  92. %
  93. % q0 = [0 0 0 0 0 2];
  94. % qe = [-pi/2 0 0 pi/2 pi/4 2];
  95.  
  96. T0 = Robot.fkine(q0);
  97. Te = Robot.fkine(qe);
  98.  
  99. t = [0:.056:2];     % generate a time vector
  100. q = jtraj(q0, qe, t); %joint trajectory /// cartesian traj ctraj
  101.  
  102.  
  103.  
  104. T = Robot.fkine(q);
  105.  
  106.  
  107. %plots position, velocities, accelerations XYZ TODO dynamics
  108. f1 = figure('Name','p,v,a XYZ','NumberTitle','off');
  109. p = T.transl;
  110. subplot(3,1,1)
  111. plot(t, p(:,1))
  112. xlabel('Time (s)');
  113. ylabel('X (m)')
  114. subplot(3,1,2)
  115. plot(t, p(:,2))
  116. xlabel('Time (s)');
  117. ylabel('Y (m)')
  118. subplot(3,1,3)
  119. plot(t, p(:,3))
  120. xlabel('Time (s)');
  121. ylabel('Z (m)')
  122.  
  123. %Plots position X relative to Z
  124. f2 = figure('Name','X relative to Z','NumberTitle','off');
  125. subplot(1,1,1)
  126. plot(p(:,1), p(:,3));
  127. xlabel('X (m)')
  128. ylabel('Z (m)')
  129. grid
  130.  
  131. %plot interactive bot
  132. f3 = figure('Name','Interactive plot','NumberTitle','off');
  133. Robot.teach
  134.  
  135. f4 = figure('Name','init pos','NumberTitle','off');
  136. init = SerialLink(Robot, 'name', 'init');
  137. init.plot(q0);
  138.  
  139. f5 = figure('Name','final position plot','NumberTitle','off');
  140. final = SerialLink(Robot, 'name', 'final');
  141. final.plot(qe);
  142.  
  143. % f6 = figure('Name','movement loop plot','NumberTitle','off');
  144. % loop = SerialLink(Robot, 'name', 'loop');
  145. % loop.plot(q, 'loop');
  146.  
  147.  
  148.  
  149.  
  150. %trajectory planning
  151. T1 = transl(5.0, -5.0,-6.0);
  152. T2 = transl(5.0, -8.0,-6.0);
  153.  
  154. T = ctraj(T1, T2, 2);
  155. q = Robot.ikine(T, 'pinv', 'tol', 1e-3);
  156.  
  157. % q0 = [0 0 0 0 0 2];
  158. % qe = [-pi/2 0 0 pi/2 pi/4 2];
  159. % T0 = Robot.fkine(q0);
  160. % Te = Robot.fkine(qe);
  161. % T = ctraj(T0, Te, 50);
  162. % q = Robot.ikine(T, 'pinv');
  163.  
  164.  
  165. f7 = figure('Name','trajectory TEST loop plot','NumberTitle','off');
  166. trajBot = SerialLink(Robot, 'name', 'trajBot');
  167. trajBot.plot(q, 'loop');
  168.  
  169. %%%%%note: can use STL files with plot3D !!!!!!!!!!!
  170.  
  171. %%%how to know if a point is reachable ??? No way to know except computing
  172. %%%but basic rules would be: point < radius sum(Ai)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement