当前位置:   article > 正文

KUKA_kr16机器人建模正逆解及轨迹规划——matlab机器人工具箱_机器人工具箱轨迹规划动画保存

机器人工具箱轨迹规划动画保存

1.KUKA_kr16机器人本体结构

2.建立DH坐标系

 

3.matlab机器人建模

3.1设置初始姿态

对Link函数里面的offset参数进行设定,对各关节进行关节偏移量的设定,来使模型的初始姿态与我们设想的一样。

偏移值为DH参数表中的theta项

matlab代码如下:

  1. clear
  2. clc
  3. %theta      d         a        alpha
  4. %标准DH建模
  5. L(1)=Link('d',0,'a',0.260,'alpha',-pi/2);
  6. L(2)=Link('d',0,'a',0.680,'alpha',0);
  7. L(3)=Link('d',0,'a',0.035,'alpha',pi/2);
  8. L(4)=Link('d',0.670,'a',0,'alpha',pi/2);
  9. L(5)=Link('d',0,'a',0,'alpha',pi/2);
  10. L(6)=Link('d',0.158,'a',0,'alpha',0);
  11. robot=SerialLink(L,'name','kr16');
  12. %定义关节两偏移量 
  13. robot.base=transl(0,0,0.675);
  14. L(2).offset=-pi/2;
  15. L(3).offset=pi;
  16. L(4).offset=pi;
  17. L(5).offset=pi;
  18. L(6).offset=pi/2;
  19. %定义关节变量范围
  20. L(1).qlim=[deg2rad(-185) deg2rad(185)];
  21. L(2).qlim=[deg2rad(-155) deg2rad(35)];
  22. L(3).qlim=[deg2rad(-130) deg2rad(154)];
  23. L(4).qlim=[deg2rad(-350) deg2rad(350)];
  24. L(5).qlim=[deg2rad(-130) deg2rad(130)];
  25. L(6).qlim=[deg2rad(-350) deg2rad(350)];
  26. %调整坐标轴即视野
  27. set(gca,'XLim',[-1,1.5]);  %将X轴范围设定为[-1.000,1.500]
  28. set(gca,'YLim',[-1,1.5]);  %将X轴范围设定为[-1.000,1.500]
  29. set(gca,'ZLim',[-1,1.5]);  %将Z轴范围设定为[-1.000,1.500]
  30. % set(gca,'XDir','reverse');    %将x轴方向设置为反向
  31. % set(gca,'YDir','reverse');    %将Y轴方向设置为反向
  32. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  33. robot.display;
  34. robot.teach;

4.运动学正解

matlab代码如下:

 

  1. % % 正运动学求解
  2. theta_0=[0,0,0,0,0,0];
  3. theta_1=[pi/3,0,pi/6,0,pi/4,0];
  4. T0=robot.fkine(theta_0);
  5. T1=robot.fkine(theta_1);
  6. figure (2)
  7. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  8. robot.plot(theta_0);
  9. hold on
  10. figure (3)
  11. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  12. robot.plot(theta_1);

5.运动学逆解

matlab代码如下:

  1. %逆运动学求解
  2. itheta_0=robot.ikine(T0);
  3. itheta_1=robot.ikine(T1);

6.轨迹规划

  1. %首先我们先规划之前得到的两个位姿之间的轨迹
  2. t=[0:0.05:4];%设定步数
  3. p=mtraj(@tpoly, itheta_0, itheta_1, 100);
  4. p1=mtraj(@lspb, itheta_0, itheta_1, 100);
  5. [q,dq,ddq]=mtraj(@tpoly, itheta_0, itheta_1, 100); 
  6. [q2,dq2,ddq2]=mtraj(@lspb, itheta_0, itheta_1, 100);
  7.  
  8. subplot(6,3,[1 4 7  2 5 8 10 13 16  11 14 17])
  9. robot.plot([0 0 0 0 0 0])
  10. robot.plot(p)
  11. robot.plot(p1)
  12.  
  13. %绘制角度,速度,加速度曲线
  14. subplot(6,3,3)
  15. plot(q)
  16. subplot(6,3,6)
  17. plot(dq)
  18. subplot(6,3,9)
  19. plot(ddq)
  20. subplot(6,3,12)
  21. plot(q2)
  22. subplot(6,3,15)
  23. plot(dq2)
  24. subplot(6,3,18)
  25. plot(ddq2)
  26. 7.保存动画
  27. figure(4)
  28. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  29. %将轨迹创建生成视频
  30. out=VideoWriter('robot.avi');
  31. out.FrameRate=10;    %设定每秒10
  32. open(out);
  33. robot.plot([0 0 0 0 0 0])
  34. for K=1:100
  35.     robot.plot(p(K,:))
  36.     F=getframe(gcf);
  37.     writeVideo(out,F);
  38. end
  39. close(out);

完整源码如下:

  1. clear
  2. clc
  3. %theta      d         a        alpha
  4. %标准DH建模
  5. L(1)=Link('d',0,'a',0.260,'alpha',-pi/2);
  6. L(2)=Link('d',0,'a',0.680,'alpha',0);
  7. L(3)=Link('d',0,'a',0.035,'alpha',pi/2);
  8. L(4)=Link('d',0.670,'a',0,'alpha',pi/2);
  9. L(5)=Link('d',0,'a',0,'alpha',pi/2);
  10. L(6)=Link('d',0.158,'a',0,'alpha',0);
  11. robot=SerialLink(L,'name','kr16');
  12. %定义关节两偏移量 
  13. robot.base=transl(0,0,0.675);
  14. L(2).offset=-pi/2;
  15. L(3).offset=pi;
  16. L(4).offset=pi;
  17. L(5).offset=pi;
  18. L(6).offset=pi/2;
  19. %定义关节变量范围
  20. L(1).qlim=[deg2rad(-185) deg2rad(185)];
  21. L(2).qlim=[deg2rad(-155) deg2rad(35)];
  22. L(3).qlim=[deg2rad(-130) deg2rad(154)];
  23. L(4).qlim=[deg2rad(-350) deg2rad(350)];
  24. L(5).qlim=[deg2rad(-130) deg2rad(130)];
  25. L(6).qlim=[deg2rad(-350) deg2rad(350)];
  26. %调整坐标轴即视野
  27. set(gca,'XLim',[-1,1.5]);  %将X轴范围设定为[-1.000,1.500]
  28. set(gca,'YLim',[-1,1.5]);  %将X轴范围设定为[-1.000,1.500]
  29. set(gca,'ZLim',[-1,1.5]);  %将Z轴范围设定为[-1.000,1.500]
  30. % set(gca,'XDir','reverse');    %将x轴方向设置为反向
  31. % set(gca,'YDir','reverse');    %将Y轴方向设置为反向
  32. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  33. robot.display;
  34. robot.teach;
  35. % % 正运动学求解
  36. theta_0=[0,0,0,0,0,0];
  37. theta_1=[pi/3,0,pi/6,0,pi/4,0];
  38. T0=robot.fkine(theta_0);
  39. T1=robot.fkine(theta_1);
  40. figure (2)
  41. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  42. robot.plot(theta_0);
  43. hold on
  44. figure (3)
  45. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  46. robot.plot(theta_1);
  47. %逆运动学求解
  48. itheta_0=robot.ikine(T0);
  49. itheta_1=robot.ikine(T1);
  50. % 轨迹规划
  51. %首先我们先规划之前得到的两个位姿之间的轨迹
  52. t=[0:0.05:4];%设定步数
  53. p=mtraj(@tpoly, itheta_0, itheta_1, 100);
  54. p1=mtraj(@lspb, itheta_0, itheta_1, 100);
  55. [q,dq,ddq]=mtraj(@tpoly, itheta_0, itheta_1, 100); 
  56. [q2,dq2,ddq2]=mtraj(@lspb, itheta_0, itheta_1, 100);
  57.  
  58. subplot(6,3,[1 4 7  2 5 8 10 13 16  11 14 17])
  59. robot.plot([0 0 0 0 0 0])
  60. robot.plot(p)
  61. robot.plot(p1)
  62.  
  63. %绘制角度,速度,加速度曲线
  64. subplot(6,3,3)
  65. plot(q)
  66. subplot(6,3,6)
  67. plot(dq)
  68. subplot(6,3,9)
  69. plot(ddq)
  70. subplot(6,3,12)
  71. plot(q2)
  72. subplot(6,3,15)
  73. plot(dq2)
  74. subplot(6,3,18)
  75. plot(ddq2)
  76. figure(4)
  77. set(gca,'View',[50,20]);     %设定视野方向角和俯仰角
  78. %将轨迹创建生成视频
  79. out=VideoWriter('robot.avi');
  80. out.FrameRate=10;    %设定每秒10
  81. open(out);
  82. robot.plot([0 0 0 0 0 0])
  83. for K=1:100
  84.     robot.plot(p(K,:))
  85.     F=getframe(gcf);
  86.     writeVideo(out,F);
  87. end
  88. close(out);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/534985
推荐阅读
相关标签
  

闽ICP备14008679号