样例程序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',30000,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,53) ;
22: !check whether vision project has ;
23: !been triggered successfully ;
24: IF (R[53]<>1102),JMP LBL[99] ;
25: !get vision result from NO.1 ;
26: !Mech-Vision project ;
27: CALL MM_GET_VIS(1,51,53) ;
28: !check whether vision result has ;
29: !been got from Mech-Vision ;
30: !successfully ;
31: IF R[53]<>1100,JMP LBL[99] ;
32: !save first vision point data to ;
33: !local variables ;
34: CALL MM_GET_POS(1,60,70,80) ;
35: !parse label info received from ;
36: !Mech-Vision, eg. "R[70]=56" ;
37: !will decompose into 5 and 6 ;
38: R[30]=R[70] DIV 10 ;
39: R[31]=R[70] MOD 10 ;
40: !add handling logic according to ;
41: !decomposed label value ;
42: IF (R[30]=5) THEN ;
43: !add handling logic a ;
44: PAUSE ;
45: ELSE ;
46: !add handling logic b ;
47: PAUSE ;
48: ENDIF ;
49: !move to intermediate waypoint ;
50: !of picking ;
51:J P[3] 50% CNT100 ;
52: !move to approach waypoint ;
53: !of picking ;
54:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1] ;
55: !move to picking waypoint ;
56:L PR[60] 300mm/sec FINE ;
57: !add object grasping logic here, ;
58: !such as "DO[1]=ON" ;
59: PAUSE ;
60: !move to departure waypoint ;
61: !of picking ;
62:L PR[60] 1000mm/sec FINE Tool_Offset,PR[1] ;
63: !move to intermediate waypoint ;
64: !of placing ;
65:J P[4] 50% CNT100 ;
66: !move to approach waypoint ;
67: !of placing ;
68:L P[5] 1000mm/sec FINE Tool_Offset,PR[2] ;
69: !move to placing waypoint ;
70:L P[5] 300mm/sec FINE ;
71: !add object releasing logic here, ;
72: !such as "DO[1]=OFF" ;
73: PAUSE ;
74: !move to departure waypoint ;
75: !of placing ;
76:L P[5] 1000mm/sec FINE Tool_Offset,PR[2] ;
77: !move back to robot home position ;
78:J P[1] 100% FINE ;
79: END ;
80: ;
81: LBL[99:vision error] ;
82: !add error handling logic here ;
83: !according to different ;
84: !error codes ;
85: !e.g.: status=1003 means no ;
86: !point cloud in ROI ;
87: !e.g.: status=1002 means no ;
88: !vision results ;
89: !e.g.: mm_status=3099 means ;
90: !failed to open socket ;
91: 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。用户可根据具体业务场景,针对不同的标签值,添加不同的处理逻辑。 |