Example Program 8: MM_S8_Viz_Subtask
Program Introduction
Description |
This example program consists of two programs: a main program and a sub program. The sub program (background program) triggers the Mech-Viz project to run to obtain the planned path. The main program (the foreground program) moves the robot based on the planned path. Then, the main program triggers the sub program to run when the robot performs placing to obtain the next planned path, shortening the cycle time.
|
||
File path |
Sub program: You can navigate to the installation directory of Mech-Vision and Mech-Viz and find the file by using the Main program: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
The following part describes the sub program.
Similar to the MM_S2_Viz_Basic example program, the sub program triggers the Mech-Viz project to run and obtains the planned path. As such, the features of the sub program that are consistent with those of MM_S2_Viz_Basic are not described in this part. For more information about these features, see Example Program 2: MM_S2_Viz_Basic. |
1: !-------------------------------- ;
2: !FUNCTION: run Mech-Viz project ;
3: !and get planned path in subtask ;
4: !(run together with ;
5: !MM_S8_Viz_Subtask) ;
6: !Mech-Mind, 2023-12-25 ;
7: !-------------------------------- ;
8: ;
9: F[10]=(ON) ;
10: !trigger Mech-Viz project ;
11: CALL MM_START_VIZ(2,10) ;
12: !get planned path, 1st argument ;
13: !(1) means getting pose in JPs ;
14: CALL MM_GET_VIZ(1,51,52,53) ;
15: !check whether planned path has ;
16: !been got from Mech-Viz ;
17: !successfully ;
18: IF (R[53]=2100) THEN ;
19: !save waypoints of the planned ;
20: !path to local variables one ;
21: !by one ;
22: CALL MM_GET_JPS(1,60,70,80) ;
23: CALL MM_GET_JPS(2,61,71,81) ;
24: CALL MM_GET_JPS(3,62,72,82) ;
25: ENDIF ;
26: F[10]=(OFF) ;
The above code indicates that if the sub program is running, the following operations are performed.
-
Set F[10] to ON.
-
Run the Mech-Viz project.
-
Obtain the planned path.
-
Store the planned path.
-
Set F[10] to OFF.
As such, you can determine if the sub program finishes running based on the F[10] value.
The following part describes the main program.
Similar to the MM_S2_Viz_Basic example program, the main program performs picking and placing based on the planned path. As such, the features of the main program that are consistent with those of MM_S2_Viz_Basic are not described in this part. For more information about these features, see Example Program 2: MM_S2_Viz_Basic. |
1: !-------------------------------- ;
2: !FUNCTION: run Mech-Viz project ;
3: !and get planned path in subtask ;
4: !(run together with ;
5: !MM_S8_Sub) ;
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: !initialize communication ;
14: !parameters(initialization is ;
15: !required only once) ;
16: CALL MM_INIT_SKT('8','127.0.0.1',50000,5) ;
17: !move to robot home position ;
18:J P[1] 100% FINE ;
19: RUN MM_S8_SUB ;
20: LBL[1:LOOP] ;
21: !move to wait position for ;
22: !picking ;
23:L P[2] 1000mm/sec FINE ;
24: !wait until subtask program ;
25: !finished ;
26: WAIT (F[10]=OFF) ;
27: !check whether planned path has ;
28: !been got from Mech-Viz ;
29: !successfully ;
30: IF R[53]<>2100,JMP LBL[99] ;
31: !follow the planned path to pick ;
32: !move to approach waypoint ;
33: !of picking ;
34:J PR[60] 50% FINE ;
35: !move to picking waypoint ;
36:J PR[61] 10% FINE ;
37: !add object grasping logic here, ;
38: !such as "DO[1]=ON" ;
39: PAUSE ;
40: !move to departure waypoint ;
41: !of picking ;
42:J PR[62] 50% FINE ;
43: !move to intermediate waypoint ;
44: !of placing ;
45:J P[3] 50% CNT100 ;
46: !move to approach waypoint ;
47: !of placing ;
48:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
49: !trigger Mech-Viz project and get ;
50: !planned path in advance ;
51: RUN MM_S8_SUB ;
52: !move to placing waypoint ;
53:L P[4] 300mm/sec FINE ;
54: !add object releasing logic here, ;
55: !such as "DO[1]=OFF" ;
56: PAUSE ;
57: !move to departure waypoint ;
58: !of placing ;
59:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
60: !move back to robot home position ;
61:J P[1] 100% FINE ;
62: JMP LBL[1] ;
63: END ;
64: ;
65: LBL[99:vision error] ;
66: !add error handling logic here ;
67: !according to different ;
68: !error codes ;
69: !e.g.: status=2038 means no ;
70: !point cloud in ROI ;
71: PAUSE ;
The workflow corresponding to the above example program code is shown in the figure below.

The table below illustrates the core code of the main program.
Feature | Code and description | ||
---|---|---|---|
Trigger the Mech-Viz project to run and obtain the planned path |
The above code indicates that the main program calls the MM_S8_SUB sub program to trigger the Mech-Viz project to run and obtain the planned path.
|
||
Plan the next path in advance by looping (picking→triggering the next round of path planning→placing) |
The above code indicates that the main program repeatedly executes the code at LBL[1].
In the above code, the robot moves to a waiting waypoint before picking and waits for the sub program to finish running (i.e., F[10] changes from ON to OFF), thus ensuring that the planned path has been obtained and stored.
In the above code, the robot moves along the planned path to the approach waypoint of picking (PR[60]) and then to the picking waypoint (PR[61]), performs picking (for example, DO[1]=ON), and then moves to the departure waypoint of picking (PR[62]), the intermediate waypoint of placing (P[3]), and then the approach waypoint of placing (Tool_Offset,PR[2]).
The above code indicates that the main program calls the MM_S8_SUB sub program again to trigger the Mech-Viz project to run and obtain the planned path. Now that the robot resides in the area for placing, the robot can plan the next picking path in advance without waiting for the placing to complete and then planning the next picking path.
In the above example, the robot moves to the placing waypoint (P[4]), performs placing (for example, DO[1]=OFF), and then moves to the departure waypoint of placing (Tool_Offset,PR[2]) and then the home position. |