样例程序17:MM_S17_Vis_ParseLabel
程序解读
以下为MM_S17_Vis_ParseLabel样例程序的代码及相关解释说明。
与MM_S1_Vis_Basic样例相比,本样例仅新增了解析标签的功能(加粗部分的代码)。因此,下文不再重复解释与MM_S1_Vis_Basic样例相同部分的代码(详情请参考MM_S1_Vis_Basic样例说明)。 |
DEF MM_S17_Vis_ParseLabel ( )
;---------------------------------------------------
; FUNCTION: trigger Mech-Vision project and get
; vision result, then parse the label info
; 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_VisData(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_Pose(1,Xpick_point,label,toolid)
;parse label info received from Mech-Vision, eg. "label=56" will decompose into 5 and 6
label_1=label / 10; !label_1=5
label_2=label - label_1*10; !label_2=6
;add handling logic according to decomposed label value
IF label_1==5 THEN
;add handling logic a
halt
ELSE
;add handling logic b
halt
ENDIF
;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
上述样例程序代码对应的流程如下图所示。

下表为解析标签的逻辑解读。用户单击指令名称的超链接便可查看该指令的详细说明。
流程 | 代码及说明 |
---|---|
将标签解析为label_1、label_2 |
MM_Get_Pose指令可以将某个视觉点的工具位姿、标签和末端工具编号分别转存至Xpick_point、label、toolid变量中。本样例假设label变量值为56,“label / 10”表示label整除10的商(即为5),“label - label_1*10”表示label整除10的余数(即为6),如此便将label解析成label_1和label_2(即56解析成5和6)。 |
根据解析后的标签值添加处理逻辑 |
上述代码表示,如果label_1为5,则执行处理逻辑a;否则,执行处理逻辑b。用户可根据具体业务场景,针对不同的标签值,添加不同的处理逻辑。 |