样例程序6:MM_S6_Viz_ErrorHandle
程序解读
以下为MM_S6_Viz_ErrorHandle样例程序的代码及相关解释说明。
| 与MM_S2_Viz_Basic样例相比,本样例仅新增了对不同错误状态码进行处理的功能(加粗部分的代码)。因此,下文不再重复解释与MM_S2_Viz_Basic样例相同部分的代码(详情请参考MM_S2_Viz_Basic样例说明)。 |
1: !-------------------------------- ;
2: !FUNCTION: trigger Mech-Viz ;
3: !project and get planned path, ;
4: !handle errors according to ;
5: !status codes (if no point cloud ;
6: !in ROI, retry several times ;
7: !before exit loop) ;
8: !Mech-Mind, 2023-12-25 ;
9: !-------------------------------- ;
10: ;
11: !set current uframe NO. to 0 ;
12: UFRAME_NUM=0 ;
13: !set current tool NO. to 1 ;
14: UTOOL_NUM=1 ;
15: !reset counter ;
16: R[99]=0 ;
17: !move to robot home position ;
18:J P[1] 100% FINE ;
19: !initialize communication ;
20: !parameters(initialization is ;
21: !required only once) ;
22: CALL MM_INIT_SKT('8','127.0.0.1',30000,5) ;
23: !move to image-capturing position ;
24:L P[2] 1000mm/sec FINE ;
25: LBL[1:vision] ;
26: !trigger Mech-Viz project ;
27: CALL MM_START_VIZ(2,10,53) ;
28: !check whether viz project has ;
29: !been triggered successfully ;
30: IF (R[53]<>2103),JMP LBL[99] ;
31: !get planned path, 1st argument ;
32: !(1) means getting pose in JPs ;
33: CALL MM_GET_VIZ(1,51,52,53) ;
34: !check whether planned path has ;
35: !been got from Mech-Viz ;
36: !successfully ;
37: IF R[53]<>2100,JMP LBL[99] ;
38: !save waypoints of the planned ;
39: !path to local variables one ;
40: !by one ;
41: CALL MM_GET_JPS(1,60,70,80) ;
42: CALL MM_GET_JPS(2,61,71,81) ;
43: CALL MM_GET_JPS(3,62,72,82) ;
44: !follow the planned path to pick ;
45: !move to approach waypoint ;
46: !of picking ;
47:J PR[60] 50% FINE ;
48: !move to picking waypoint ;
49:J PR[61] 10% FINE ;
50: !add object grasping logic here, ;
51: !such as "DO[1]=ON" ;
52: PAUSE ;
53: !move to departure waypoint ;
54: !of picking ;
55:J PR[62] 50% FINE ;
56: !move to intermediate waypoint ;
57: !of placing ;
58:J P[3] 50% CNT100 ;
59: !move to approach waypoint ;
60: !of placing ;
61:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
62: !move to placing waypoint ;
63:L P[4] 300mm/sec FINE ;
64: !add object releasing logic here, ;
65: !such as "DO[1]=OFF" ;
66: PAUSE ;
67: !move to departure waypoint ;
68: !of placing ;
69:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
70: !move back to robot home position ;
71:J P[1] 100% FINE ;
72: END ;
73: ;
74: LBL[99:vision error] ;
75: !add error handling logic here ;
76: !according to different ;
77: !error codes ;
78: !e.g.: mm_status=2038 means no ;
79: !point cloud in ROI ;
80: !e.g.: mm_status=3099 means ;
81: !failed to open socket ;
82: IF R[53]=2038,JMP LBL[2] ;
83: JMP LBL[999] ;
84: ;
85: LBL[2] ;
86: !no point cloud in ROI, add ;
87: !handling logic here ;
88: !self-adding then check retry ;
89: !counter ;
90: R[99]=R[99]+1 ;
91: !jump back to vision retry label ;
92: !if the number of retry times is ;
93: !less than 3 ;
94: IF R[99]<3,JMP LBL[1] ;
95: !reset counter and exit loop if ;
96: !the number of retry times has ;
97: !reached 3 ;
98: R[99]=0 ;
99: JMP LBL[999] ;
100: ;
101: LBL[999:other error] ;
102: !add other error handling logic ;
103: !here ;
104: PAUSE ;
上述样例程序代码对应的流程如下图所示。
下表为处理不同状态码的逻辑解读。
| 流程 | 代码及说明 | ||
|---|---|---|---|
处理不同状态码 |
机器人在执行MM_GET_VIZ指令后,会将指令执行的状态码保存至R[53]寄存器。用户可根据具体状态码做相应的处理,如本例中的处理逻辑。
|