样例程序7:MM_S7_Viz_SwitchTCP
程序简介
功能说明 |
机器人触发Mech-Viz工程运行,并获取路径规划结果,然后根据抓取点的末端工具编号切换相应的末端工具,进而执行抓取和放置操作。 |
文件路径 |
Mech-Vision和Mech-Viz软件安装目录下 |
所需工程 |
Mech-Vision工程和Mech-Viz工程 |
使用前提 |
|
程序解读
以下为MM_S7_Viz_SwitchTCP样例程序的代码及相关解释说明。
与MM_S2_Viz_Basic样例相比,本样例新增了根据末端工具编号切换工具的功能(加粗部分的代码)。因此,下文不再重复解释与MM_S2_Viz_Basic样例相同部分的代码(详情请参考MM_S2_Viz_Basic样例说明)。 |
NOP
'--------------------------------
'FUNCTION: trigger Mech-Viz
'project and get planned path,
'switch TCP according to the
'toolId
'Mech-Mind, 2023-12-25
'--------------------------------
'clear I50 to I69
CLEAR I050 20
'initialize p variables
SUB P081 P081
SUB P082 P082
SUB P083 P083
'move to robot home position
MOVJ C00000 VJ=50.00
'initialize communication
'parameters (initialization is
'required only once)
CALL JOB:MM_INIT_SOCKET ARGF"192.168.10.40;50000;1"
'move to image-capturing position
MOVJ C00001 VJ=50.00 PL=0
'open socket connection
CALL JOB:MM_OPEN_SOCKET
'trigger Mech-Viz project
CALL JOB:MM_START_VIZ ARGF"2;30"
'get planned path, 1st argument
'(2) means getting pose in Pose
CALL JOB:MM_GET_VIZDATA ARGF"2;51;52;53"
'check whether planned path has
'been got from Mech-Viz
'successfully
IFTHENEXP I053<>2100
'add error handling logic here
'according to different error
'codes
'e.g.: I053=2038 means no
'point cloud in ROI
PAUSE
ENDIF
'close socket connection
CALL JOB:MM_CLOSE_SOCKET
'switch TCP according to the
'toolId
'save waypoints of the planned
'path to local variables one
'by one
CALL JOB:MM_GET_POSE ARGF"1;81;61;62"
CALL JOB:MM_GET_POSE ARGF"2;82;63;64"
CALL JOB:MM_GET_POSE ARGF"3;83;65;66"
'reset tool signals according
'to received toolid
SWITCH I064 CASE 1
'reset tool signal
'SETE P081 TL#(0)
'SETE P082 TL#(0)
'SETE P083 TL#(0)
PAUSE
CASE 2
'reset tool signal
'SETE P081 TL#(1)
'SETE P082 TL#(1)
'SETE P083 TL#(1)
PAUSE
DEFAULT
'reset tool signal
PAUSE
ENDSWITCH
'follow the planned path to pick
'move to approach waypoint of
'picking
MOVL P081 V=166.6 PL=0
'move to picking waypoint
MOVL P082 V=50.0 PL=0
'add object grasping logic here,
'such as DOUT OT#(1) ON
SWITCH I064 CASE 1
'open tool signal
PAUSE
CASE 2
'open tool signal
PAUSE
DEFAULT
'open tool signal
PAUSE
ENDSWITCH
'move to departure waypoint of
'picking
MOVL P083 V=166.6 PL=0
'move to intermediate waypoint of
'placing
MOVJ C00002 VJ=50.00
'move to approach waypoint of
'placing
MOVL C00003 V=166.6 PL=0
'move to placing waypoint
MOVL C00004 V=50.0 PL=0
'add object releasing logic here,
'such as DOUT OT#(1) OFF
'reset tool signals according
'to received toolid
SWITCH I064 CASE 1
'reset tool signal
PAUSE
CASE 2
'reset tool signal
PAUSE
DEFAULT
'reset tool signal
PAUSE
ENDSWITCH
'move to departure waypoint of
'placing
MOVL C00005 V=166.6 PL=0
'move back to robot home position
MOVJ C00006 VJ=50.00
END
上述样例程序代码对应的流程如下图所示。
下表为新增代码的逻辑解读。
流程 | 代码及说明 | ||
---|---|---|---|
获取规划路径 |
因此,整条指令表示机器人获取Mech-Viz工程返回的规划路径。
|
||
转存规划路径 |
因此,“CALL JOB:MM_GET_POSE ARGF"1;81;61;62"”整条指令表示将第一个路径点的工具位姿、标签和末端工具编号分别转存至指定变量。
|
||
根据末端工具编号切换末端工具 |
上述语句表示,用户可根据I064值,决定机器人移动到对应位姿(抓取点)时所使用的末端工具,即根据末端工具编号切换末端工具。 当机器人移动至抓取点时,用户可根据末端工具编号打开相应工具对应的DO信号,例如样例中如下代码。
当机器人移动至放置点时,用户可根据末端工具编号关闭并重置相应工具对应的DO信号,例如样例中如下代码。
|