Example Program 20: MM_S20_Viz_PlanAllVision
Program Introduction
Description |
The robot triggers the Mech-Viz project to run. Then, the robot uses for loops to obtain all planned paths and perform picking and placing. In this example, once the camera captures an image, Mech-Viz will plan picking paths for all vision results. This program is applicable to scenarios where one image is used to perform picking for multiple times. |
||
File path |
You can navigate to the installation directory of Mech-Vision and Mech-Viz and find the file by using the |
||
Project |
Mech-Vision and Mech-Viz projects
|
||
Prerequisites |
|
This example program is provided for reference only. Before using the program, please modify the program according to the actual scenario. |
Program Description
This part describes the MM_S20_Viz_PlanAllVision example program.
The only difference between the MM_S20_Viz_PlanAllVision example program and the MM_S2_Viz_Basic example program is that MM_S20_Viz_PlanAllVision can use for loops to obtain all planned paths and perform picking and placing (this code of this feature is bolded). As such, only the feature of using for loops to obtain all planned paths and perform picking and placing is described in the following part. For information about the parts of MM_S20_Viz_PlanAllVision that are consistent with those of MM_S2_Viz_Basic, see Example Program 2: MM_S2_Viz_Basic. |
1: !-------------------------------- ;
2: !FUNCTION: trigger Mech-Viz ;
3: !project, plan all vision results ;
4: !and get all planned results ;
5: !using command 210 ;
6: !Mech-Mind, 2023-12-25 ;
7: !-------------------------------- ;
8: ;
9: !set current uframe NO. to 0 ;
10: UFRAME_NUM=0 ;
11: !set current tool NO. to 1 ;
12: UTOOL_NUM=1 ;
13: !move to robot home position ;
14:J P[1] 100% FINE ;
15: !initialize communication ;
16: !parameters(initialization is ;
17: !required only once) ;
18: CALL MM_INIT_SKT('8','127.0.0.1',50000,5) ;
19: LBL[1:recap] ;
20: !move to image-capturing position ;
21:L P[2] 1000mm/sec FINE ;
22: !trigger Mech-Viz project ;
23: CALL MM_START_VIZ(2,10) ;
24: !get planned path ;
25: CALL MM_GET_PLNDT(0,3,51,52,53) ;
26: !check whether planned path has ;
27: !been got from Mech-Viz ;
28: !successfully ;
29: IF R[53]<>2100,JMP LBL[99] ;
30: !save all waypoint data to local ;
31: !variables using for-loop, a ;
32: !maximum of 50 points are support ;
33: !supported ;
34: FOR R[10]=1 TO R[51] ;
35: R[11]=59+R[10] ;
36: R[12]=R[10]*30 ;
37: R[13]=31+R[12] ;
38: R[14]=32+R[12] ;
39: R[15]=33+R[12] ;
40: R[16]=34+R[12] ;
41: R[17]=40+R[12] ;
42: CALL MM_GET_PLJOP(R[10],3,R[11],R[13],R[14],R[15],R[16],R[17]) ;
43: ENDFOR ;
44: !parse pick cycle count, here ;
45: !suppose 3 points per planned ;
46: !path ;
47: R[30]=R[51] DIV 3 ;
48: R[31]=R[51] MOD 3 ;
49: !check if parsed data is valid; ;
50: !if not, retry to get planned ;
51: !path or add some error handling ;
52: !logic ;
53: IF R[30]<1) OR (R[31]<>0 THEN ;
54: PAUSE ;
55: JMP LBL[1] ;
56: ENDIF ;
57: !repeatedly run pick-and-place ;
58: !cycle using for-loop ;
59: FOR R[10]=1 TO R[30] ;
60: R[20]=R[10]-1 ;
61: R[21]=R[20]*3 ;
62: R[31]=60+R[21] ;
63: R[32]=61+R[21] ;
64: R[33]=62+R[21] ;
65: !move to intermediate waypoint ;
66: !of picking ;
67:J P[3] 50% CNT100 ;
68: !follow the planned path to pick ;
69:J PR[R[31]] 50% FINE ;
70:J PR[R[32]] 10% FINE ;
71: !add object grasping logic here ;
72: PAUSE ;
73:J PR[R[33]] 50% FINE ;
74: !move to intermediate waypoint ;
75: !of placing ;
76:J P[4] 50% CNT100 ;
77: !move to approach waypoint ;
78: !of placing ;
79:L P[5] 1000mm/sec FINE Tool_Offset,PR[2] ;
80: !move to placing waypoint ;
81:L P[5] 300mm/sec FINE ;
82: !add object releasing logic here, ;
83: !such as "DO[1]=OFF" ;
84: PAUSE ;
85: !move to departure waypoint ;
86: !of placing ;
87:L P[5] 1000mm/sec FINE Tool_Offset,PR[2] ;
88: !move to intermediate waypoint ;
89: !of placing ;
90:J P[4] 50% CNT100 ;
91: ENDFOR ;
92: !finish pick-and-place cycle, and ;
93: !jump back to camera capturing ;
94: JMP LBL[1] ;
95: END ;
96: ;
97: LBL[99:vision error] ;
98: !add error handling logic here ;
99: !according to different ;
100: !error codes ;
101: !e.g.: status=2038 means no ;
102: !point cloud in ROI ;
103: PAUSE ;
The workflow corresponding to the above example program code is shown in the figure below.
The table below describes the feature of using for loops to obtain all planned paths and perform picking and placing. You can click the hyperlink to the command name to view its detailed description.
Feature | Code and description |
---|---|
Obtain the planned path |
|
Store the planned path by looping |
|
Calculate the values for R[30] and R[31] |
This example assumes that each planned picking path consists of 3 waypoints. “R[51] DIV 3” indicates the quotient when the value of R[51] is divided by 3, and “R[51] MOD 3” indicates the remainder when the value of R[51] is divided by 3. R[30] indicates the total number of picking times. If R[31] is not set to 0, the planned number of picking waypoints is less than 3 (i.e., an error has occurred during path planning and a re-planning operation is needed). |
Determine whether an error has occurred during path planning |
If the number of picking times (R[30]) is less than 1 or the value of R[31] is not 0, an error has occurred during path planning. You need to add processing code here, such as the code to restart the Mech-Viz project and then obtain the planned path. |
Perform picking and placing by looping |
The above code indicates that in the for loop, the robot moves to the 3 waypoints planned each time to complete the picking operation and then performs the placing operation. R[10] is used to control the number of iterations in the loop (i.e., the value of R[10] starts from 1 and increments by 1 after each loop iteration until it exceeds the value of R[30], at which point the loop ends. Each time the value of R[10] increases by 1, the value of R[21] is incremented by 3. The range 60+R[21] to 62+R[21] (i.e., R[31] to R[33]) corresponds to the register IDs where the 3 waypoints of each planned path will be stored. |