当前位置:   article > 正文

【机器人学】2-1.六自由度机器人运动学逆解【附MATLAB机器人逆解代码】_6自由度机器人逆向运动学求解公式

6自由度机器人逆向运动学求解公式

        通过上一篇文章​​​​​​六自由度机器人正解已经获得了机器人各连杆间的转换关系。当知道各个连杆的转角\theta1、\theta2、\theta3、\theta4、\theta5、\theta6时可以求出末端执行器的位姿,这个过程称为正向运动学。这篇文章将讨论逆向运动学,即,给定末端执行器的位姿,求解各连杆的转角。在实际生活中逆向运动学更为实用。

现已知末端姿态矩阵和机器人的运动学模型,求解\theta1、\theta2、\theta3、\theta4、\theta5、\theta6。

已知六轴机器人的D-H参数如下所示:

如果不清楚何为改进的DH参数,可以看我的上一篇博客。【机器人学】1-1.六自由度机器人运动学正解 【附MATLAB代码】

关节1关节2关节3关节4关节5关节6
\alpha09000-9090
a0042539300
d160.700113.39993.6
\theta0900-9000
\beta000000

选用改进型的D-H参数,各矩阵分别如下所示:

        其中

        如果你的机械臂D-H参数结构和我的一致,以上解析解你可以直接使用,如果参数相差不大,可以跟着我的计算思路推导一下你自己的逆解方程,相信你也可以得到正确的结果。

        MATLAB仿真验证

  1. function R=AxisAngle_RotMat(Rxyz)
  2. theta=(Rxyz(1)^2+Rxyz(2)^2+Rxyz(3)^2)^0.5;
  3. if(abs(theta)<1e-8)
  4. R=eye(3);
  5. return;
  6. end
  7. r=Rxyz/theta;
  8. R=[r(1)^2*(1-cos(theta))+cos(theta) r(1)*r(2)*(1-cos(theta))-r(3)*sin(theta) r(1)*r(3)*(1-cos(theta))+r(2)*sin(theta)
  9. r(1)*r(2)*(1-cos(theta))+r(3)*sin(theta) r(2)^2*(1-cos(theta))+cos(theta) r(2)*r(3)*(1-cos(theta))-r(1)*sin(theta)
  10. r(1)*r(3)*(1-cos(theta))-r(2)*sin(theta) r(2)*r(3)*(1-cos(theta))+r(1)*sin(theta) r(3)^2*(1-cos(theta))+cos(theta)];
  11. end

 

  1. clc;clear;
  2. %带入机器人初始值
  3. d1 = 0.1607;
  4. d2 = 0;
  5. d3 = 0;
  6. d4 = 0.1133;
  7. d5 = 0.099;
  8. d6 = 0.0936;
  9. a1 = 0;
  10. a2 = 0;
  11. a3 = 0.425;
  12. a4 = 0.393;
  13. a5 = 0;
  14. a6 = 0;
  15. %testData1 测试数据
  16. px = 0.129;
  17. py = 0.157;
  18. pz = 0.858;
  19. rx = 38.05;
  20. ry = 42.96;
  21. rz = -179.77;
  22. posture = [rx/180*pi,ry/180*pi,rz/180*pi];
  23. %轴线表示转换为姿态矩阵转
  24. a = AxisAngle_RotMat(posture);
  25. %目标位置姿态矩阵
  26. nx=a(1,1);ox=a(1,2);ax=a(1,3);
  27. ny=a(2,1);oy=a(2,2);ay=a(2,3);
  28. nz=a(3,1);oz=a(3,2);az=a(3,3);
  29. % 求解关节角1
  30. t1 = (d6*a(1,3)-px);
  31. t2 = (d6*a(2,3)-py);
  32. theta1_1 = atan2(t2,t1) - atan2(d4, sqrt(t1^2+t2^2-d4^2)) ;
  33. theta1_2 = atan2(t2,t1) - atan2(d4, -sqrt(t1^2+t2^2-d4^2)) ;
  34. disp([theta1_1 theta1_2]*180/pi);
  35. % 求解关节角5
  36. theta5_1 = atan2(sqrt((ny*cos(theta1_1)-nx*sin(theta1_1))^2+(oy*cos(theta1_1)-ox*sin(theta1_1))^2), ax*sin(theta1_1)-ay*cos(theta1_1));
  37. theta5_2 = atan2(-sqrt((ny*cos(theta1_1)-nx*sin(theta1_1))^2+(oy*cos(theta1_1)-ox*sin(theta1_1))^2), ax*sin(theta1_1)-ay*cos(theta1_1));
  38. theta5_3 = atan2(sqrt((ny*cos(theta1_2)-nx*sin(theta1_2))^2+(oy*cos(theta1_2)-ox*sin(theta1_2))^2), ax*sin(theta1_2)-ay*cos(theta1_2));
  39. theta5_4 = atan2(-sqrt((ny*cos(theta1_2)-nx*sin(theta1_2))^2+(oy*cos(theta1_2)-ox*sin(theta1_2))^2), ax*sin(theta1_2)-ay*cos(theta1_2));
  40. disp([theta5_1 theta5_2 theta5_3 theta5_4]*180/pi);
  41. % 求解关节角6
  42. theta6_1 = atan2((ox*sin(theta1_1)-oy*cos(theta1_1))/sin(theta5_1), -(nx*sin(theta1_1)-ny*cos(theta1_1))/sin(theta5_1));
  43. theta6_2 = atan2((ox*sin(theta1_1)-oy*cos(theta1_1))/sin(theta5_2), -(nx*sin(theta1_1)-ny*cos(theta1_1))/sin(theta5_2));
  44. theta6_3 = atan2((ox*sin(theta1_2)-oy*cos(theta1_2))/sin(theta5_3), -(nx*sin(theta1_2)-ny*cos(theta1_2))/sin(theta5_3));
  45. theta6_4 = atan2((ox*sin(theta1_2)-oy*cos(theta1_2))/sin(theta5_4), -(nx*sin(theta1_2)-ny*cos(theta1_2))/sin(theta5_4));
  46. disp([theta6_1 theta6_2 theta6_3 theta6_4]*180/pi);
  47. % 求解关节角2,3,4
  48. q234_1 = atan2(az/sin(theta5_1), (ax*cos(theta1_1)+ay*sin(theta1_1))/sin(theta5_1));
  49. q234_2 = atan2(az/sin(theta5_2), (ax*cos(theta1_1)+ay*sin(theta1_1))/sin(theta5_2));
  50. q234_3 = atan2(az/sin(theta5_3), (ax*cos(theta1_2)+ay*sin(theta1_2))/sin(theta5_3));
  51. q234_4 = atan2(az/sin(theta5_4), (ax*cos(theta1_2)+ay*sin(theta1_2))/sin(theta5_4));
  52. disp([q234_1 q234_2 q234_3 q234_4]*180/pi);
  53. A_1 = d6*sin(theta5_1)*cos(q234_1)-d5*sin(q234_1)-px*cos(theta1_1)-py*sin(theta1_1);
  54. B_1 = pz-d1-d5*cos(q234_1)-d6*sin(theta5_1)*sin(q234_1);
  55. A_2 = -px*cos(theta1_1)-py*sin(theta1_1)-d5*sin(q234_2)+d6*sin(theta5_2)*cos(q234_2);
  56. B_2 = pz-d1-d5*cos(q234_2)-d6*sin(theta5_2)*sin(q234_2);
  57. A_3 = -px*cos(theta1_2)-py*sin(theta1_2)-d5*sin(q234_3)+d6*sin(theta5_3)*cos(q234_3);
  58. B_3 = pz-d1-d5*cos(q234_3)-d6*sin(theta5_3)*sin(q234_3);
  59. A_4 = -px*cos(theta1_2)-py*sin(theta1_2)-d5*sin(q234_4)+d6*sin(theta5_4)*cos(q234_4);
  60. B_4 = pz-d1-d5*cos(q234_4)-d6*sin(theta5_4)*sin(q234_4);
  61. % 关节2
  62. theta2_1 = atan2(A_1^2+B_1^2+a3^2-a4^2, sqrt(abs(4*a3^2*(A_1^2+B_1^2)-(A_1^2+B_1^2+a3^2-a4^2)^2)))-atan2(B_1, A_1);
  63. theta2_2 = atan2(A_1^2+B_1^2+a3^2-a4^2, -sqrt(abs(4*a3^2*(A_1^2+B_1^2)-(A_1^2+B_1^2+a3^2-a4^2)^2)))-atan2(B_1, A_1);
  64. theta2_3 = atan2(A_2^2+B_2^2+a3^2-a4^2, sqrt(abs(4*a3^2*(A_2^2+B_2^2)-(A_2^2+B_2^2+a3^2-a4^2)^2)))-atan2(B_2, A_2);
  65. theta2_4 = atan2(A_2^2+B_2^2+a3^2-a4^2, -sqrt(abs(4*a3^2*(A_2^2+B_2^2)-(A_2^2+B_2^2+a3^2-a4^2)^2)))-atan2(B_2, A_2);
  66. theta2_5 = atan2(A_3^2+B_3^2+a3^2-a4^2, sqrt(abs(4*a3^2*(A_3^2+B_3^2)-(A_3^2+B_3^2+a3^2-a4^2)^2)))-atan2(B_3, A_3);
  67. theta2_6 = atan2(A_3^2+B_3^2+a3^2-a4^2, -sqrt(abs(4*a3^2*(A_3^2+B_3^2)-(A_3^2+B_3^2+a3^2-a4^2)^2)))-atan2(B_3, A_3);
  68. theta2_7 = atan2(A_4^2+B_4^2+a3^2-a4^2, sqrt(abs(4*a3^2*(A_4^2+B_4^2)-(A_4^2+B_4^2+a3^2-a4^2)^2)))-atan2(B_4, A_4);
  69. theta2_8 = atan2(A_4^2+B_4^2+a3^2-a4^2, -sqrt(abs(4*a3^2*(A_4^2+B_4^2)-(A_4^2+B_4^2+a3^2-a4^2)^2)))-atan2(B_4, A_4);
  70. disp([theta2_1 theta2_2 theta2_3 theta2_4 theta2_5 theta2_6 theta2_7 theta2_8]*180/pi);
  71. q23_1 = atan2(-px*cos(theta1_1)-py*sin(theta1_1)-d5*sin(q234_1)+d6*sin(theta5_1)*cos(q234_1)-a3*sin(theta2_1),pz-d1-d5*cos(q234_1)-d6*sin(theta5_1)*sin(q234_1)-a3*cos(theta2_1));
  72. q23_2 = atan2(-px*cos(theta1_1)-py*sin(theta1_1)-d5*sin(q234_1)+d6*sin(theta5_1)*cos(q234_1)-a3*sin(theta2_2),pz-d1-d5*cos(q234_1)-d6*sin(theta5_1)*sin(q234_1)-a3*cos(theta2_2));
  73. q23_3 = atan2(-px*cos(theta1_1)-py*sin(theta1_1)-d5*sin(q234_2)+d6*sin(theta5_2)*cos(q234_2)-a3*sin(theta2_3),pz-d1-d5*cos(q234_2)-d6*sin(theta5_2)*sin(q234_2)-a3*cos(theta2_3));
  74. q23_4 = atan2(-px*cos(theta1_1)-py*sin(theta1_1)-d5*sin(q234_2)+d6*sin(theta5_2)*cos(q234_2)-a3*sin(theta2_4),pz-d1-d5*cos(q234_2)-d6*sin(theta5_2)*sin(q234_2)-a3*cos(theta2_4));
  75. q23_5 = atan2(-px*cos(theta1_2)-py*sin(theta1_2)-d5*sin(q234_3)+d6*sin(theta5_3)*cos(q234_3)-a3*sin(theta2_5),pz-d1-d5*cos(q234_3)-d6*sin(theta5_3)*sin(q234_3)-a3*cos(theta2_5));
  76. q23_6 = atan2(-px*cos(theta1_2)-py*sin(theta1_2)-d5*sin(q234_3)+d6*sin(theta5_3)*cos(q234_3)-a3*sin(theta2_6),pz-d1-d5*cos(q234_3)-d6*sin(theta5_3)*sin(q234_3)-a3*cos(theta2_6));
  77. q23_7 = atan2(-px*cos(theta1_2)-py*sin(theta1_2)-d5*sin(q234_4)+d6*sin(theta5_4)*cos(q234_4)-a3*sin(theta2_7),pz-d1-d5*cos(q234_4)-d6*sin(theta5_4)*sin(q234_4)-a3*cos(theta2_7));
  78. q23_8 = atan2(-px*cos(theta1_2)-py*sin(theta1_2)-d5*sin(q234_4)+d6*sin(theta5_4)*cos(q234_4)-a3*sin(theta2_8),pz-d1-d5*cos(q234_4)-d6*sin(theta5_4)*sin(q234_4)-a3*cos(theta2_8));
  79. % 关节3
  80. theta3_1 = q23_1 - theta2_1;
  81. theta3_2 = q23_2 - theta2_2;
  82. theta3_3 = q23_3 - theta2_3;
  83. theta3_4 = q23_4 - theta2_4;
  84. theta3_5 = q23_5 - theta2_5;
  85. theta3_6 = q23_6 - theta2_6;
  86. theta3_7 = q23_7 - theta2_7;
  87. theta3_8 = q23_8 - theta2_8;
  88. % 关节4
  89. theta4_1 = q234_1 - q23_1;
  90. theta4_2 = q234_1 - q23_2;
  91. theta4_3 = q234_2 - q23_3;
  92. theta4_4 = q234_2 - q23_4;
  93. theta4_5 = q234_3 - q23_5;
  94. theta4_6 = q234_3 - q23_6;
  95. theta4_7 = q234_4 - q23_7;
  96. theta4_8 = q234_4 - q23_8;
  97. theta_STD = [
  98. theta1_1,theta2_1,theta3_1,theta4_1,theta5_1,theta6_1;
  99. theta1_1,theta2_2,theta3_2,theta4_2,theta5_1,theta6_1;
  100. theta1_1,theta2_3,theta3_3,theta4_3,theta5_2,theta6_2;
  101. theta1_1,theta2_4,theta3_4,theta4_4,theta5_2,theta6_2;
  102. theta1_2,theta2_5,theta3_5,theta4_5,theta5_3,theta6_3;
  103. theta1_2,theta2_6,theta3_6,theta4_6,theta5_3,theta6_3;
  104. theta1_2,theta2_7,theta3_7,theta4_7,theta5_4,theta6_4;
  105. theta1_2,theta2_8,theta3_8,theta4_8,theta5_4,theta6_4;
  106. ]*180/pi

由于MATLAB中机器人工具箱对运动学逆解仿真度不够,为此用我自己的模拟机器人测试。没有仿真平台的同学,可以用其他机器人工具箱代替。或其它测试方法。

测试数据1:

图中左边6个参数代表机器人的末端姿态(输入参数),右边6个参数代表6个关节角度(结果)。

MATLAB计算结果1:

 测试数据2:

MATLAB计算结果2:

 测试数据3:

MATLAB计算结果3:

下一章:六自由度机器人的雅克比矩阵

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

闽ICP备14008679号