样例程序19:MM_S19_Vis_PlanAllVision
程序简介
功能说明 |
机器人先触发Mech-Vision工程运行,然后通过循环获取所有规划路径,进而通过循环进行抓取与放置操作。在本样例中,相机拍照一次,Mech-Vision会规划出全部视觉结果的抓取路径。通常用于一拍多抓的场景。 |
文件路径 |
Mech-Vision和Mech-Viz软件安装目录下 |
所需工程 |
|
使用前提 |
| 此样例程序仅是示例程序。用户需根据实际情况在此基础上进行修改,请勿直接使用该程序。 |
程序解读
以下为MM_S19_Vis_PlanAllVision样例程序的代码及相关解释说明。
| 与MM_S3_Vis_Path样例相比,本样例仅新增了通过循环获取所有规划路径并进行抓取与放置的功能(加粗部分的代码)。因此,下文不再重复解释与MM_S3_Vis_Path样例相同部分的代码(详情请参考MM_S3_Vis_Path样例说明)。 |
1: !-------------------------------- ;
2: !FUNCTION: trigger Mech-Vision ;
3: !project, plan all vision results ;
4: !and get all planned paths ;
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: LBL[1:recap] ;
19: !move to image-capturing position ;
20:L P[2] 1000mm/sec FINE ;
21: !trigger NO.1 Mech-Vision project ;
22: CALL MM_START_VIS(1,0,2,10,53) ;
23: !check whether vision project has ;
24: !been triggered successfully ;
25: IF (R[53]<>1102),JMP LBL[99] ;
26: !get planned path from NO.1 ;
27: !Mech-Vision project; 2nd ;
28: !argument (1) means getting pose ;
29: !in JPs ;
30: CALL MM_GET_VISP(1,1,51,52,53) ;
31: !check whether planned path has ;
32: !been got from Mech-Vision ;
33: !successfully ;
34: IF R[53]<>1103,JMP LBL[99] ;
35: !save all waypoint data to local ;
36: !variables using for-loop, a ;
37: !maximum of 50 points are support ;
38: !supported ;
39: FOR R[10]=1 TO R[51] ;
40: R[11]=59+R[10] ;
41: R[12]=69+R[10] ;
42: R[13]=99+R[10] ;
43: CALL MM_GET_JPS(R[10],R[11],R[12],R[13]) ;
44: ENDFOR ;
45: !parse pick cycle count, here ;
46: !suppose 5 points per planned ;
47: !path ;
48: R[30]=R[51] DIV 5 ;
49: R[29]=R[51] MOD 5 ;
50: !check if parsed data is valid; ;
51: !if not, retry to get planned ;
52: !path or add some error handling ;
53: !logic ;
54: IF R[30]<1) OR (R[29]<>0 THEN ;
55: PAUSE ;
56: JMP LBL[1] ;
57: ENDIF ;
58: !repeatedly run pick-and-place ;
59: !cycle using for-loop ;
60: FOR R[10]=1 TO R[30] ;
61: R[20]=R[10]-1 ;
62: R[21]=R[20]*5 ;
63: R[31]=60+R[21] ;
64: R[32]=61+R[21] ;
65: R[33]=62+R[21] ;
66: R[34]=63+R[21] ;
67: R[35]=64+R[21] ;
68: !follow the planned path to pick ;
69:J PR[R[31]] 50% CNT100 ;
70:J PR[R[32]] 50% FINE ;
71:J PR[R[33]] 10% FINE ;
72: !add object grasping logic here, ;
73: !such as "DO[1]=ON" ;
74: PAUSE ;
75:J PR[R[34]] 50% FINE ;
76:J PR[R[35]] 50% CNT100 ;
77: !move to intermediate waypoint ;
78: !of placing ;
79:J P[3] 50% CNT100 ;
80: !move to approach waypoint ;
81: !of placing ;
82:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
83: !move to placing waypoint ;
84:L P[4] 300mm/sec FINE ;
85: !add object releasing logic here, ;
86: !such as "DO[1]=OFF" ;
87: PAUSE ;
88: !move to departure waypoint ;
89: !of placing ;
90:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
91: !move to intermediate waypoint ;
92: !of placing ;
93:J P[3] 50% CNT100 ;
94: ENDFOR ;
95: !finish pick-and-place cycle, and ;
96: !jump back to camera capturing ;
97: JMP LBL[1] ;
98: END ;
99: ;
100: LBL[99:vision error] ;
101: !add error handling logic here ;
102: !according to different ;
103: !error codes ;
104: !e.g.: status=1003 means no ;
105: !point cloud in ROI ;
106: !e.g.: status=1002 means no ;
107: !vision results ;
108: !e.g.: mm_status=3099 means ;
109: !failed to open socket ;
110: PAUSE ;
上述样例程序代码对应的流程如下图所示。
下表为新增功能的逻辑解读。用户单击指令名称的超链接便可查看该指令的详细说明。
| 流程 | 代码及说明 |
|---|---|
通过循环转存规划路径 |
|
计算R[30]和R[29] |
本样例假设每次规划的抓取路径包含5个路径点,“R[51] DIV 5”表示R[51]整除5的商,“R[51] MOD 5”表示R[51]整除5的余数。R[30]表示规划的总抓取次数。如果R[29]不为0,则表示某次规划的抓取路径点个数少于5,即路径规划出现异常,需重新进行规划。 |
判断规划路径是否出错 |
如果抓取次数R[30]小于1,或R[29]不为0,则表示路径规划出现异常,用户需在此处添加处理逻辑,例如重新触发Mech-Vision工程并获取规划路径。 |
通过循环进行抓取和放置 |
上述代码表示,在FOR循环中,机器人移动到每次规划的5个路径点,从而完成抓取操作,然后接着执行放置操作。R[10]用于控制循环的次数,即R[10]从1开始,每次循环后自增1,直到大于抓取次数R[30],结束循环。每当R[10]增加1,则R[21]增加5,60+R[21] ~ 64+R[21](即R[31] ~ R[35])表示每次规划的5个路径点将要存放的5个寄存器号码。 |