Example Program 7: MM_S7_Viz_SwitchTCP
Program Introduction
Description |
The robot starts the Mech-Viz project, obtains the path planning result, and then changes the tool according to the tool ID of the picking waypoint to perform picking and placing. |
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_S7_Viz_SwitchTCP example program.
The only difference between the MM_S7_Viz_SwitchTCP example program and the MM_S2_Viz_Basic example program is that MM_S7_Viz_SwitchTCP can change the tool according to the tool ID(this code of this feature is bolded). As such, only the feature of handling errors based on the different error codes is described in the following part. For information about the parts of MM_S6_Viz_ErrorHandle 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 and get planned path, ;
4: !switch TCP according to ;
5: !the tool NO.;
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: !move to image-capturing position ;
20:L P[2] 1000mm/sec FINE ;
21: !trigger Mech-Viz project ;
22: CALL MM_START_VIZ(2,10) ;
23: !get planned path, 1st argument ;
24: !(2) means getting pose in TCP ;
25: CALL MM_GET_VIZ(2,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 waypoints of the planned ;
31: !path to local variables one ;
32: !by one ;
33: CALL MM_GET_POS(1,60,70,80) ;
34: CALL MM_GET_POS(2,61,71,81) ;
35: CALL MM_GET_POS(3,62,72,82) ;
36: !switch TCP according to the ;
37: !received tool NO. ;
38: IF R[81]=1,JMP LBL[1] ;
39: IF R[81]=2,JMP LBL[2] ;
40: JMP LBL[999] ;
41: ;
42: LBL[1:use tool NO.1] ;
43: !set current tool NO. to 1 ;
44: UTOOL_NUM=1 ;
45: !reset tool signal ;
46: !DO[1]=OFF ;
47: !set a Flag ;
48: F[1]=(ON) ;
49: JMP LBL[3] ;
50: ;
51: LBL[2:use tool NO.2] ;
52: !set current tool NO. to 2 ;
53: UTOOL_NUM=2 ;
54: !reset tool signal ;
55: !DO[2]=OFF ;
56: !set a Flag ;
57: F[2]=(ON) ;
58: JMP LBL[3] ;
59: ;
60: LBL[3:pick path] ;
61: !follow the planned path to pick ;
62: !move to approach waypoint ;
63: !of picking ;
64:L PR[60] 1000mm/sec FINE ;
65: !move to picking waypoint ;
66:L PR[61] 300mm/sec FINE ;
67: !add object grasping logic here, ;
68: !IF (F[1]),DO[1]=(ON) ;
69: !IF (F[2]),DO[2]=(ON) ;
70: PAUSE ;
71: !move to departure waypoint ;
72: !of picking ;
73:L PR[62] 1000mm/sec FINE ;
74: !move to intermediate waypoint ;
75: !of placing ;
76:J P[3] 50% CNT100 ;
77: !move to approach waypoint ;
78: !of placing ;
79:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
80: !move to placing waypoint ;
81:L P[4] 300mm/sec FINE ;
82: !add object releasing logic here, ;
83: !IF (F[1]),DO[1]=(OFF) ;
84: !IF (F[2]),DO[2]=(OFF) ;
85: PAUSE ;
86: !move to departure waypoint ;
87: !of placing ;
88:L P[4] 1000mm/sec FINE Tool_Offset,PR[2] ;
89: !move back to robot home position ;
90:J P[1] 100% FINE ;
91: !reset the Flags ;
92: F[1]=(OFF) ;
93: F[2]=(OFF) ;
94: END ;
95: ;
96: LBL[99:vision error] ;
97: !add error handling logic here ;
98: !according to different ;
99: !error codes ;
100: !e.g.: status=2038 means no ;
101: !point cloud in ROI ;
102: PAUSE ;
103: ;
104: LBL[999:label error] ;
105: !add handling logic here if the ;
106: !label is invalid ;
107: PAUSE ;
The workflow corresponding to the above example program code is shown in the figure below.
The table below describes the bolded code.
Feature | Code and description | ||
---|---|---|---|
Obtain the planned path |
The entire statement indicates that the robot obtains the planned path from the Mech-Viz project.
|
||
Store the planned path |
The entire command “CALL MM_GET_JPS(1,60,70,80)” stores the TCP, label, and tool ID of the first waypoint in the specified registers.
|
||
Change the tool based on the tool ID |
You can determine the tool to be used when the robot moves to the picking waypoint based on the value set in the R[81] register. The description of the above code is shown below.
If the robot controls tool 1 with the DO[1] signal and tool 2 with the DO[2] signal, the program must also establish their relationships using flags F[1] and F[2] respectively.
In the following example, No.1 tool ID is used to describe the pick-and-place operation.
The process for using No.2 tool ID is similar to the above, and will not be repeated here. |