• codesys 6轴机器人正解程序


    ——————————————————————————————————————

    标准DH方法

    ——————————————————————————————————————

    1. FUNCTION FUN_standard_DH_method : ARRAY[0..3,0..3] OF LREAL
    2. VAR_INPUT
    3. theta:LREAL;
    4. d:LREAL;
    5. a:LREAL;
    6. alpha:LREAL;
    7. END_VAR
    8. VAR
    9. END_VAR
    1. FUN_standard_DH_method[0,0]:=COS(theta);
    2. FUN_standard_DH_method[0,1]:=-SIN(theta) * COS(alpha);
    3. FUN_standard_DH_method[0,2]:=SIN(theta) * SIN(alpha);
    4. FUN_standard_DH_method[0,3]:=a * COS(theta);
    5. FUN_standard_DH_method[1,0]:=SIN(theta);
    6. FUN_standard_DH_method[1,1]:=COS(theta) * COS(alpha);
    7. FUN_standard_DH_method[1,2]:=-COS(theta) * SIN(alpha);
    8. FUN_standard_DH_method[1,3]:=a * SIN(theta);
    9. FUN_standard_DH_method[2,0]:=0;
    10. FUN_standard_DH_method[2,1]:=SIN(alpha);
    11. FUN_standard_DH_method[2,2]:=COS(alpha);
    12. FUN_standard_DH_method[2,3]:=d;
    13. FUN_standard_DH_method[3,0]:=0;
    14. FUN_standard_DH_method[3,1]:=0;
    15. FUN_standard_DH_method[3,2]:=0;
    16. FUN_standard_DH_method[3,3]:=1;

    ——————————————————————————————————————

    矩阵相乘

    ——————————————————————————————————————

    1. FUNCTION FUN_matrix_44_MUL : ARRAY[0..3,0..3] OF LREAL
    2. VAR_INPUT
    3. matrix1:ARRAY[0..3,0..3] OF LREAL;
    4. matrix2:ARRAY[0..3,0..3] OF LREAL;
    5. END_VAR
    6. VAR
    7. i:INT;
    8. j:INT;
    9. END_VAR
    1. FOR i:=0 TO 3 BY 1 DO
    2. FOR j:=0 TO 3 BY 1 DO
    3. FUN_matrix_44_MUL[i,j]:=matrix1[i,0] * matrix2[0,j] +
    4. matrix1[i,1] * matrix2[1,j] +
    5. matrix1[i,2] * matrix2[2,j] +
    6. matrix1[i,3] * matrix2[3,j];
    7. END_FOR
    8. END_FOR

    ——————————————————————————————————————

    旋转矩阵变换RPY角

    ——————————————————————————————————————

    1. FUNCTION FUN_matrix_33_to_RPY : BOOL
    2. VAR_INPUT
    3. matrix:ARRAY[0..3,0..3] OF LREAL;
    4. END_VAR
    5. VAR_IN_OUT
    6. alpha:LREAL;
    7. bata:LREAL;
    8. gama:LREAL;
    9. END_VAR
    10. VAR
    11. END_VAR

    1. bata:=SM3M.SMC_atan2(SQRT(EXPT(matrix[2,0],2) + EXPT(matrix[2,1],2)), matrix[2,2]);
    2. alpha:=SM3M.SMC_atan2(matrix[1,2] / SIN(bata), matrix[0,2] / SIN(bata));
    3. gama:=SM3M.SMC_atan2(matrix[2,1] / SIN(bata), -matrix[2,0] / SIN(bata));

    ——————————————————————————————————————

    程序

    ——————————————————————————————————————

    1. VAR_GLOBAL
    2. theta:ARRAY[1..6] OF LREAL;
    3. d:ARRAY[1..6] OF LREAL;
    4. a:ARRAY[1..6] OF LREAL;
    5. alpha:ARRAY[1..6] OF LREAL;
    6. offset:ARRAY[1..6] OF LREAL;
    7. matrix:ARRAY [1..6] OF ARRAY [0..3,0..3] OF LREAL;
    8. endMatrix:ARRAY [0..3,0..3] OF LREAL;
    9. END_VAR
    1. PROGRAM PLC_PRG
    2. VAR
    3. i:INT;
    4. x:LREAL;
    5. y:LREAL;
    6. z:LREAL;
    7. rx:LREAL;
    8. ry:LREAL;
    9. rz:LREAL;
    10. END_VAR
    1. P_axisGroup();
    2. theta[1]:=0+SM_Drive_Virtual_1.fActPosition/180*SM3M.SMC_PI;
    3. theta[2]:=SM3M.SMC_PI/2+SM_Drive_Virtual_2.fActPosition/180*SM3M.SMC_PI;
    4. theta[3]:=0+SM_Drive_Virtual_3.fActPosition/180*SM3M.SMC_PI;
    5. theta[4]:=0+SM_Drive_Virtual_4.fActPosition/180*SM3M.SMC_PI;
    6. theta[5]:=0+SM_Drive_Virtual_5.fActPosition/180*SM3M.SMC_PI;
    7. theta[6]:=0+SM_Drive_Virtual_6.fActPosition/180*SM3M.SMC_PI;
    8. alpha[1]:=SM3M.SMC_PI/2;
    9. alpha[2]:=0;
    10. alpha[3]:=SM3M.SMC_PI/2;
    11. alpha[4]:=SM3M.SMC_PI/2;
    12. alpha[5]:=-SM3M.SMC_PI/2;
    13. alpha[6]:=0;
    14. d[1]:=80;
    15. d[2]:=0;
    16. d[3]:=20;
    17. d[4]:=70;
    18. d[5]:=0;
    19. d[6]:=10;
    20. a[1]:=10;
    21. a[2]:=100;
    22. a[3]:=30;
    23. a[4]:=0;
    24. a[5]:=0;
    25. a[6]:=0;
    26. FOR i:=1 TO 6 BY 1 DO
    27. matrix[i]:=FUN_standard_DH_method(theta:=theta[i] ,d:=d[i] ,a:=a[i] ,alpha:=alpha[i]);
    28. END_FOR
    29. endMatrix:=matrix[1];
    30. FOR i:=2 TO 6 BY 1 DO
    31. endMatrix:=FUN_matrix_44_MUL(endMatrix,matrix[i]);
    32. END_FOR
    33. x:=endMatrix[0,3];
    34. y:=endMatrix[1,3];
    35. z:=endMatrix[2,3];
    36. FUN_matrix_33_to_RPY(matrix:=endMatrix , alpha:=rx , bata:=ry , gama:=rz );
    37. rx:=rx/SM3M.SMC_PI*180;
    38. ry:=ry/SM3M.SMC_PI*180;
    39. rz:=rz/SM3M.SMC_PI*180;

    ——————————————————————————————————————

    机器人轴组程序查看之前的文章

    ——————————————————————————————————————

  • 相关阅读:
    easyui-sidemenu 菜单 后台加载
    常见web安全及防护原理
    【1314. 矩阵区域和】
    【数据结构与算法】--二叉树OJ题
    前后端分离项目-基于springboot+vue的图书馆管理系统的设计与实现(内含代码+文档+报告)
    Spring的注解@Qualifier用法与简析
    花了一周时间,更新了下软考云题库Web版
    加法器与减法器verilog
    Oracle19c安装,基本配置教程(超详细)
    温度敏感/PH敏感/电场敏感/温度/pH双重敏感/磁场敏感型水凝胶的制备
  • 原文地址:https://blog.csdn.net/weixin_58619062/article/details/133810412