样例程序17:MM_S17_Vis_ParseLabel
程序解读
以下为MM_S17_Vis_ParseLabel样例程序的代码及相关解释说明。
与MM_S1_Vis_Basic样例相比,本样例仅新增了解析标签的功能(加粗部分的代码)。因此,下文不再重复解释与MM_S1_Vis_Basic样例相同部分的代码(详情请参考MM_S1_Vis_Basic样例说明)。 |
1: !-------------------------------- ;
2: !FUNCTION: trigger Mech-Vision ;
3: !project and get vision result, ;
4: !then parse the label info ;
5: !Mech-Mind, 2023-12-25 ;
6: !-------------------------------- ;
7: ;
8: !set current uframe NO. to 0 ;
9: UFRAME_NUM=0 ;
10: !set current tool NO. to 1 ;
11: UTOOL_NUM=1 ;
12: !move to robot home position ;
13:J P[1] 100% FINE ;
14: !initialize communication ;
15: !parameters(initialization is ;
16: !required only once) ;
17: CALL MM_INIT_SKT('8','127.0.0.1',50000,5) ;
18: !move to image-capturing position ;
19:L P[2] 1000mm/sec FINE ;
20: !trigger NO.1 Mech-Vision project ;
21: CALL MM_START_VIS(1,0,2,10) ;
22: !get vision result from NO.1 ;
23: !Mech-Vision project ;
24: CALL MM_GET_VIS(1,51,53) ;
25: !check whether vision result has ;
26: !been got from Mech-Vision ;
27: !successfully ;
28: IF R[53]<>1100,JMP LBL[99] ;
29: !save first vision point data to ;
30: !local variables ;
31: CALL MM_GET_POS(1,60,70,80) ;
32: !parse label info received from ;
33: !Mech-Vision, eg. "R[70]=56" ;
34: !will decompose into 5 and 6 ;
35: R[30]=R[70] DIV 10 ;
36: R[31]=R[70] MOD 10 ;
37: !add handling logic according to ;
38: !decomposed label value ;
39: IF (R[30]=5) THEN ;
40: !add handling logic a ;
41: PAUSE ;
42: ELSE ;
43: !add handling logic b ;
44: PAUSE ;
45: ENDIF ;
46: !move to intermediate waypoint ;
47: !of picking ;
48:J P[3] 50% CNT100 ;
49: !move to approach waypoint ;
50: !of picking ;
51:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1] ;
52: !move to picking waypoint ;
53:L PR[60] 300mm/sec FINE ;
54: !add object grasping logic here, ;
55: !such as "DO[1]=ON" ;
56: PAUSE ;
57: !move to departure waypoint ;
58: !of picking ;
59:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1] ;
60: !move to intermediate waypoint ;
61: !of placing ;
62:J P[4] 50% CNT100 ;
63: !move to approach waypoint ;
64: !of placing ;
65:L P[5] 1000mm/sec FINE Tool_Offset,PR[2] ;
66: !move to placing waypoint ;
67:L P[5] 300mm/sec FINE ;
68: !add object releasing logic here, ;
69: !such as "DO[1]=OFF" ;
70: PAUSE ;
71: !move to departure waypoint ;
72: !of placing ;
73:L P[5] 1000mm/sec FINE Tool_Offset,PR[2] ;
74: !move back to robot home position ;
75:J P[1] 100% FINE ;
76: END ;
77: ;
78: LBL[99:vision error] ;
79: !add error handling logic here ;
80: !according to different ;
81: !error codes ;
82: !e.g.: status=1003 means no ;
83: !point cloud in ROI ;
84: !e.g.: status=1002 means no ;
85: !vision results ;
86: PAUSE ;
上述样例程序代码对应的流程如下图所示。
下表为解析标签的逻辑解读。用户单击指令名称的超链接便可查看该指令的详细说明。
流程 | 代码及说明 |
---|---|
将标签解析为R[30]、R[31] |
MM_GET_POS指令可以将某个视觉点的工具位姿、标签和末端工具编号分别转存至PR[60]、R[70]、R[80]中。本样例假设R[70]的值为56,“R[70] DIV 10”表示56整除10的商(即为5),“R[70] MOD 10”表示56整除10的余数(即为6),如此便将56解析成5和6。 |
根据解析后的标签值添加处理逻辑 |
上述代码表示,如果R[30]为5,则执行处理逻辑a;否则,执行处理逻辑b。用户可根据具体业务场景,针对不同的标签值,添加不同的处理逻辑。 |