样例程序14:MM_S14_Vis_GetUserData
程序解读
以下为MM_S14_Vis_GetUserData样例程序的代码及相关解释说明。
与MM_S1_Vis_Basic样例相比,本样例仅修改了如下加粗部分的代码。因此,下文不再重复解释与MM_S1_Vis_Basic样例相同部分的代码(详情请参考MM_S1_Vis_Basic样例说明)。 |
DEF MM_S14_Vis_GetUserData ( )
;---------------------------------------------------
; FUNCTION: trigger Mech-Vision project and get
; vision result and custom data using command 110
; Mech-Mind, 2023-12-25
;---------------------------------------------------
;set current tool no. to 1
BAS(#TOOL,1)
;set current base no. to 0
BAS(#BASE,0)
;move to robot home position
PTP HOME Vel=100 % DEFAULT
;initialize communication parameters (initialization is required only once)
MM_Init_Socket("XML_Kuka_MMIND",873,871,60)
;move to image-capturing position
LIN camera_capture Vel=1 m/s CPDAT1 Tool[1] Base[0]
;trigger NO.1 Mech-Vision project
MM_Start_Vis(1,0,2,init_jps)
;get vision result from NO.1 Mech-Vision project
MM_Get_Dy_Data(1,pos_num,status)
;check whether vision result has been got from Mech-Vision successfully
IF status<> 1100 THEN
;add error handling logic here according to different error codes
;e.g.: status=1003 means no point cloud in ROI
;e.g.: status=1002 means no vision result
halt
ENDIF
;save first vision point data to local variables
MM_Get_DyPose(1,Xpick_point,label)
;save received custom data
offset_x=MM_UserData[1]
offset_y=MM_UserData[2]
offset_z=MM_UserData[3]
;calculate pick approach point based on pick point
tool_offset={X 0,Y 0,Z -100,A 0,B 0,C 0}
Xpick_app=Xpick_point:tool_offset
;move to intermediate waypoint of picking
PTP pick_waypoint CONT Vel=50 % PDAT1 Tool[1] Base[0]
;move to approach waypoint of picking
LIN pick_app Vel=1 m/s CPDAT2 Tool[1] Base[0]
;move to picking waypoint
LIN pick_point Vel=0.3 m/s CPDAT3 Tool[1] Base[0]
;add object grasping logic here, such as "$OUT[1]=TRUE"
halt
;move to departure waypoint of picking
LIN pick_app Vel=1 m/s CPDAT2 Tool[1] Base[0]
;move to intermediate waypoint of placing
PTP drop_waypoint CONT Vel=100 % PDAT2 Tool[1] Base[0]
;move to approach waypoint of placing
LIN drop_app Vel=1 m/s CPDAT4 Tool[1] Base[0]
;move to placing waypoint
LIN drop Vel=0.3 m/s CPDAT5 Tool[1] Base[0]
;add object releasing logic here, such as "$OUT[1]=FALSE"
halt
;move to departure waypoint of placing
LIN drop_app Vel=1 m/s CPDAT4 Tool[1] Base[0]
;move back to robot home position
PTP HOME Vel=100 % DEFAULT
END
上述样例程序代码对应的流程如下图所示。

下表是对加粗代码的逻辑解读。用户单击指令名称的超链接便可查看该指令的详细说明。
流程 | 代码及说明 | ||||
---|---|---|---|---|---|
获取视觉结果(包含自定义数据) |
因此,整条指令表示机器人获取Mech-Vision工程1返回的视觉结果(其中包含自定义数据)。
|
||||
转存视觉结果(包含自定义数据) |
因此,整条指令表示将第一个视觉点的工具位姿、标签和自定义数据分别转存至指定变量。
上述代码表示,将视觉点(抓取点)的三个自定义数据MM_UserData[1]、MM_UserData[2]和MM_UserData[3]分别赋值给offset_x、offset_y和offset_z。
|