工控机主控通讯协议 ========================================== 协议格式 +++++++++++++++++++++++++++++++++ “指令(数据)+分隔符+数据+分隔符+数据+分隔符+…+数据+分隔符+结束符” 发送和接收的数据格式如上所示,数据之间通过分隔符划分,最后以一个结束符来结尾。分隔符可以是英文逗号(',')或者空格(' '),结束符可以使'#'或者'\\n'。分隔符和结束符根据机械臂的特性可以灵活调整。 指令 ++++++++++++++++++++++++++ 1. 获取机械臂程序版本号(GetVersion) +------------+--------------------------+-----------------------------------------------------+ | 工控机发送 | “100,#” | 100: 为获取机械臂程序版本指令号 | +------------+--------------------------+-----------------------------------------------------+ | 工控机接收 | “100,error_code,version” | version: 机械臂程序版本号,三位点分十进制字符串表示 | | | +-----------------------------------------------------+ | | | eg: “1.0.0“ | +------------+--------------------------+-----------------------------------------------------+ 2. 发送速度数据(SetSpeed) +------------+--------------------+-------------------------------+ | 工控机发送 | “101,spd1,spd2,#” | 101: 为设置机械臂速度指令号 | | | +-------------------------------+ | | | spd1: 第一个速度参数(linear) | | | +-------------------------------+ | | | spd2: 第二个速度参数(angular) | +------------+--------------------+-------------------------------+ | 工控机接收 | “101,error_code,#” | | +------------+--------------------+-------------------------------+ 注:速度取值范围为(0, 100],百分比形式 3. 发送加速度数据(SetAcc) +------------+--------------------+-------------------------------+ | 工控机发送 | “102,acc1,acc2,#“ | 102: 设置机械臂加速度指令号 | | | +-------------------------------+ | | | acc1: 第一个加速度参数(accel) | | | +-------------------------------+ | | | acc2: 第二个加速度参数(decel) | +------------+--------------------+-------------------------------+ | 工控机接收 | “102,error_code,#“ | | +------------+--------------------+-------------------------------+ 注:加速度取值范围为(0, 100],百分比形式 4. 发送圆滑过渡参数(SetZone) +------------+--------------------+-----------------------------------+ | 工控机发送 | “103,blend,#” | 103: 设置机械臂圆滑过渡参数指令号 | | | +-----------------------------------+ | | | blend: 圆滑过渡参数 | +------------+--------------------+-----------------------------------+ | 工控机接收 | “103,error_code,#“ | | +------------+--------------------+-----------------------------------+ 注:圆滑过渡参数取值范围为[0, 100],百分比形式 5. 发送工具坐标系(TCP)参数(SetTool) +------------+-----------------------+---------------------------------+ | 工控机发送 | “104,x,y,z,a,b,c,d,#“ | 104: 设置机械臂工具坐标系指令号 | +------------+-----------------------+---------------------------------+ | 工控机接收 | “104,error_code,#“ | | +------------+-----------------------+---------------------------------+ 注:Cartesian姿态数据,如果机械臂是欧拉角数据那么a,b,c中会存储数据,如果四元数数据那么a,b,c,d均有数据。发送数据的单位均已转换成机械臂所需要的形式 6. 设置数字量输出 +------------+--------------------+--------------------------------------------+ | 上位机发送 | “105,port,state,#“ | 105:设置机器人数字量输出指令 | | | +--------------------------------------------+ | | | port:机器人数字量端口号 | | | +--------------------------------------------+ | | | state: DO要设置成的状态, 0 on OFF, 1 on ON | +------------+--------------------+--------------------------------------------+ | 上位机接收 | “105,error_code,#“ | | +------------+--------------------+--------------------------------------------+ 7. 设置目标关节位置,机械臂执行movej(SetJointsMovej) +------------+---------------------------------+--------------------------------------------------------+ | 工控机发送 | “106,j1,j2,j3,j4,j5,j6,j7,j8,#” | 106: SetJointsMovej指令 | | | +--------------------------------------------------------+ | | | j1~j8: 为机械臂目标关节角 | | | +--------------------------------------------------------+ | | | 如果机械臂为6轴机械臂,则j1~j6表示目标位置,j7,j8为零 | | | +--------------------------------------------------------+ | | | 四轴机械臂以实际机械臂适配为准 | +------------+---------------------------------+--------------------------------------------------------+ | 工控机接收 | “106,error_code,#“ | | +------------+---------------------------------+--------------------------------------------------------+ 8. 设置目标Cartesian位置,机械臂执行movel(SetCartMovel) +------------+-----------------------+----------------------------------+ | 工控机发送 | “107,x,y,z,a,b,c,d,#” | 107: SetCartMovel指令 | +------------+-----------------------+----------------------------------+ | 工控机接收 | “107,error_code,#“ | x: 目标Cartesian的x轴位置 | | | +----------------------------------+ | | | y: 目标Cartesian的y轴位置 | | | +----------------------------------+ | | | z: 目标Cartesian的z轴位置 | | | +----------------------------------+ | | | a: 目标Cartesian姿态数据的第一位 | | | +----------------------------------+ | | | b: 目标Cartesian姿态数据的第二位 | | | +----------------------------------+ | | | c: 目标Cartesian姿态数据的第三位 | | | +----------------------------------+ | | | d: 目标Cartesian姿态数据的第四位 | +------------+-----------------------+----------------------------------+ 注:Cartesian姿态数据,如果机械臂是欧拉角数据那么a,b,c中会存储数据,如果四元数数据那么a,b,c,d均有数据。发送数据的单位均已转换成机械臂所需要的形式 9. 设置目标关节位置,机械臂执行movel(SetJointsMovel) +------------+-----------------------------+-------------------------------------------+ | 工控机发送 | “108,data1,data2,…,datan,#” | 108: SetJointsMovel指令号 | | | +-------------------------------------------+ | | | datax: 不同机械臂根据机需求的数据来发送。 | +------------+-----------------------------+-------------------------------------------+ | 工控机接收 | “108,error_code,#“ | | +------------+-----------------------------+-------------------------------------------+ 10. 设置目标Cartesian位置,机械臂执行movej(SetCartMovej) +------------+-----------------------------+-------------------------------------------+ | 工控机发送 | “109,data1,data2,…,datan,#“ | 109: SetCartMovej指令号 | | | +-------------------------------------------+ | | | datax: 不同机械臂根据机需求的数据来发送。 | +------------+-----------------------------+-------------------------------------------+ | 工控机接收 | “109,error_code,#” | | +------------+-----------------------------+-------------------------------------------+ 11. (MovejSequence) +------------+-------------------------------------------+--------------------------------+ | 工控机发送 | “110,num,j11,j12,j13,j14,j15,j16,j17,j18, | 110: MovejSequence 指令号 | | | spd1,acc1,zone1,j21,j22,j23,…,#” +--------------------------------+ | | | num: 表示共有几组关节位置数据 | | | +--------------------------------+ | | | jnx: 第n组关节数据,每8个一组 | | | +--------------------------------+ | | | spdn: 第n组关节对应的速度 | | | +--------------------------------+ | | | accn: 第n组关节对应的加速度 | | | +--------------------------------+ | | | zonen: 第n组关节对应的圆滑过渡 | +------------+-------------------------------------------+--------------------------------+ | 工控机接收 | “110,error_code,#” | | +------------+-------------------------------------------+--------------------------------+ 12. (MovelSequence) +------------+------------------------------------------------+--------------------------------+ | 工控机发送 | “111,num,x1,y1,z1,a1,b1,c1,d1,spd1,acc1,zone1, | 111: MovelSequence指令号 | | | x2,y2,z2,a2,b2,c2,d2,spd2,acc2,zone2,…,#” +--------------------------------+ | | | num: 表示共有几组Cartesian数据 | | | +--------------------------------+ | | | Cartesian数据每7个一组 | | | +--------------------------------+ | | | spdn: 第n组位姿对应的速度 | | | +--------------------------------+ | | | accn: 第n组位姿对应的加速度 | | | +--------------------------------+ | | | zonen: 第n组位姿对应的圆滑过渡 | +------------+------------------------------------------------+--------------------------------+ | 工控机接收 | “111,error_code,#” | | +------------+------------------------------------------------+--------------------------------+ 13. (SetJointsMovejDo) +------------+--------------------------------------------+-----------------------------+ | 工控机发送 | “112,j1,j2,j3,j4,j5,j6,j7,j8,port,state,#“ | 112: SetJointsMovejDo指令号 | | | +-----------------------------+ | | | jx: 八个关节数据 | | | +-----------------------------+ | | | port:机械臂数字量端口号 | | | +-----------------------------+ | | | state: DO要设置成的状态 | +------------+--------------------------------------------+-----------------------------+ | 工控机接收 | “112,error_code,#” | | +------------+--------------------------------------------+-----------------------------+ 14. SetCartMovelDo +------------+----------------------------------+---------------------------------------+ | 工控机发送 | “113,data1,…,datan,port,state,#“ | 113: SetCartMovelDo指令号 | | | +---------------------------------------+ | | | datax: 实现SetCartMovelDo所必须的数据 | | | +---------------------------------------+ | | | port:机械臂数字量端口号 | | | +---------------------------------------+ | | | state: DO要设置成的状态 | +------------+----------------------------------+---------------------------------------+ | 工控机接收 | “113,error_code,#” | | +------------+----------------------------------+---------------------------------------+ 15. SetJointsMovelDo +------------+----------------------------------+-----------------------------------------+ | 工控机发送 | “114,data1,…,datan,port,state,#” | 114: SetJointsMovelDo指令号 | | | +-----------------------------------------+ | | | datax: 实现SetJointsMovelDo所必须的数据 | | | +-----------------------------------------+ | | | port:机械臂数字量端口号 | | | +-----------------------------------------+ | | | state: DO要设置成的状态 | +------------+----------------------------------+-----------------------------------------+ | 工控机接收 | “114,error_code,#” | | +------------+----------------------------------+-----------------------------------------+ 16. SetJointsMovejGroupDo +------------+----------------------------+----------------------------------------------+ | 工控机发送 | “115,data1,…,datan,gval,#” | 115: SetJointsMovejGroupDo指令号 | | | +----------------------------------------------+ | | | datax: 实现SetJointsMovejGroupDo所必须的数据 | | | +----------------------------------------------+ | | | gval:组信号 | +------------+----------------------------+----------------------------------------------+ | 工控机接收 | “115,error_code,#“ | | +------------+----------------------------+----------------------------------------------+ 17. SetCartMovelGroupDo +------------+----------------------------+--------------------------------------------+ | 工控机发送 | “116,data1,…,datan,gval,#“ | 116: SetCartMovelGroupDo指令号 | | | +--------------------------------------------+ | | | datax: 实现SetCartMovelGroupDo所必须的数据 | | | +--------------------------------------------+ | | | gval:组信号 | +------------+----------------------------+--------------------------------------------+ | 工控机接收 | “116,error_code,#“ | | +------------+----------------------------+--------------------------------------------+ 18. SetJointsMovelGroupDo +------------+----------------------------+----------------------------------------------+ | 工控机发送 | “117,data1,…,datan,gval,#“ | 117: SetJointsMovelGroupDo指令号 | | | +----------------------------------------------+ | | | datax: 实现SetJointsMovelGroupDo所必须的数据 | | | +----------------------------------------------+ | | | gval:组信号 | +------------+----------------------------+----------------------------------------------+ | 工控机接收 | “117,error_code,#“ | | +------------+----------------------------+----------------------------------------------+ 19. MovelUntil +------------+----------------------------+-----------------------------------+ | 工控机发送 | “118,data1,…,datan,port,#” | 118: MovelUntil指令号 | | | +-----------------------------------+ | | | datax: 实现MovelUntil所必须的数据 | | | +-----------------------------------+ | | | port:数字量输入端口号 | +------------+----------------------------+-----------------------------------+ | 工控机接收 | “118,error_code,#” | | +------------+----------------------------+-----------------------------------+ 120. 获取数字量输入状态(GetDigitalInput) +------------+--------------------------+-----------------------------------+ | 工控机发送 | “119,port,#“ | 119: GetDigitalInput指令号 | | | +-----------------------------------+ | | | datax: 实现MovelUntil所必须的数据 | | | +-----------------------------------+ | | | port:数字量输入端口号 | +------------+--------------------------+-----------------------------------+ | 工控机接收 | “119,error_code,state,#“ | state: 数字量输入端口号的状态 | | | | 0 on OFF, 1 on ON | +------------+--------------------------+-----------------------------------+ 21. 获取数字量输出状态(GetDigitalOutput) +------------+--------------------------+-----------------------------+ | 工控机发送 | “120,port,#“ | 120: GetDigitalOutput指令号 | +------------+--------------------------+-----------------------------+ | | | port: 数字量输出端口号 | +------------+--------------------------+-----------------------------+ | 工控机接收 | “120,error_code,state,#“ | state: 数字量输出口的状态 | | | | 0 on OFF, 1 on ON | +------------+--------------------------+-----------------------------+ 22. 获取模拟量输入口数值(GetAnalogInput) +------------+------------------------+---------------------------+ | 工控机发送 | “121,port,#” | 121: GetAnalogInput指令号 | +------------+------------------------+---------------------------+ | | | port: 模拟量输入端口号 | +------------+------------------------+---------------------------+ | 工控机接收 | “121,error_code,val,#“ | val: 模拟量输入口的值 | +------------+------------------------+---------------------------+ 23. 获取机械臂当前角度(GetJoints) +------------+--------------------------------------------+------------------------------------------+ | 工控机发送 | “122,#“ | 122: GetJoints指令号 | +------------+--------------------------------------------+------------------------------------------+ | 工控机接收 | “122,error_code,j1,j2,j3,j4,j5,j6,j7,j8,#“ | j1~j8: 机械臂当前的角度值 | | | +------------------------------------------+ | | | 六轴机械臂前六个数为有效值,后两个数为零 | | | +------------------------------------------+ | | | 四轴机械臂以实际机械臂适配为准 | +------------+--------------------------------------------+------------------------------------------+ 24. 获取机械臂当前位姿(GetCartPose) +------------+----------------------------------+----------------------------------+ | 工控机发送 | “123,#“ | 122: GetJoints指令号 | +------------+----------------------------------+----------------------------------+ | 工控机接收 | “123,error_code,x,y,z,a,b,c,d,#“ | x: 当前Cartesian的x轴位置 | | | +----------------------------------+ | | | y: 当前Cartesian的y轴位置 | | | +----------------------------------+ | | | z: 当前Cartesian的z轴位置 | | | +----------------------------------+ | | | a: 当前Cartesian姿态数据的第一位 | | | +----------------------------------+ | | | b: 当前Cartesian姿态数据的第二位 | | | +----------------------------------+ | | | c: 当前Cartesian姿态数据的第三位 | | | +----------------------------------+ | | | d: 当前Cartesian姿态数据的第四位 | +------------+----------------------------------+----------------------------------+ 注:机械臂返回的参数的单位均为机械臂本身自己的单位,单位的转换和姿态数据的统一在工控机实现 25. 机械臂后台发送状态 +------------+----------------------------------------------+---------------------------------------------------------------------------+ | 机械臂发送 | “200, 201,j1,…,j8,202,x,…,d,203,di1,…,din,#“ | 200: 后台发送数据指令号 | | | +---------------------------------------------------------------------------+ | | | 201: 关节角数据标志,其后8位数据j1到j8表示机械臂当前关节角度。 | | | +---------------------------------------------------------------------------+ | | | 202: 位姿标志位,其后的 7位数据表示机械臂当前位姿 | | | +---------------------------------------------------------------------------+ | | | 203:数字量输入标志位(可选),其后的位数不同机械臂不同,与工控机解析相统一 | +------------+----------------------------------------------+---------------------------------------------------------------------------+ | 机械臂接收 | “200,0,#“ | | +------------+----------------------------------------------+---------------------------------------------------------------------------+