Fanuc example user frame program
This article describes the Fanuc user frame program commonly used in surface treatment and dispensing applications. More information about the logic of this program can be found in the robot-independent surface treatment and dispensing article.
User frames in Fanuc
This example program uses the concept of a user frame.
In Fanuc, user frames are used to define the working space for the robot. When the working space of the robot is changed, the program may still work if the corresponding user frame is updated.
In surface treatment and dispensing applications, the robot trajectory is based on the location of a user frame. This means that trajectory following programs can be reused quickly following changes in the pose of the part. When the part is shifted, only the user frame has to be updated.
In this example program, the user frame is defined based on a pick point sent from Pickit (updated based on a detection).
Teaching
The program PICKIT_RG_TEACHING is shown below. This program follows the generic trajectory teaching logic.
First check if Pickit is in Robot mode.
If so, the robot moves to its detect pose and a detection is triggered.
If an object is found, User Frame 1 is updated based on the object pose. Then the user can stop the program and teach the desired trajectory poses
PR[10],PR[11],PR[12],PR[13]
w.r.t this user frame. Run the program one more time whithout moving the object to check if the trajectory poses are saved correctly.If the ROI is empty or no object is found, the program stops.
This program can be found in Select.
Note
For R-J3iB controllers, a program called EX_RG_TE.TP is provided where all macro names are adapted to shorter names.
1: !Teaching program ;
2: !Fill in settings below ;
3: UFRAME_NUM=0 ;
4: UTOOL_NUM=1 ;
5: R[1:setup id]=99 ;
6: R[2:product id]=99 ;
7: R[3:max detect]=5 ;
8: ;
9: ;
10: !Init ;
11: CALL PI_OPEN_COMMUNICATION ;
12: CALL PI_RUN ;
13: IF R[151:pi status]<>0,JMP LBL[3] ;
14: CALL PI_CONFIGURE(R[1:setup id],R[2:product id]) ;
15: ;
16: !Detect workpiece ;
17:J P[1:detect] 100% FINE ;
18: CALL PI_DETECTION_WITH_RETRIES(R[3:max detect]) ;
19: CALL PI_GET_RESULT ;
20: ;
21: LBL[1] ;
22: !Object found ;
23: IF R[150:pi obj status]=20,JMP LBL[4] ;
24: !Empty ROI ;
25: IF R[150:pi obj status]=23,JMP LBL[5] ;
26: !Else no object found ;
27: JMP LBL[6] ;
28: ;
29: !Object found ;
30: LBL[4] ;
31: !set the pickit detected pose as ;
32: !the user frame ;
33: UFRAME[1]=PR[51:pi pick pose] ;
34: UFRAME_NUM=1 ;
35: !Teach the desired positions ;
36: !relative to UFRAME[1] ;
37: !then run this program once ;
38: !while worpkiece still in place ;
39:L PR[10] 100mm/sec FINE ;
40:L PR[11] 100mm/sec FINE ;
41:L PR[12] 100mm/sec FINE ;
42:L PR[13] 100mm/sec FINE ;
43: MESSAGE[Teaching successful] ;
44: JMP LBL[999] ;
45: ;
46: !Not in robot mode ;
47: LBL[3] ;
48: MESSAGE[Not in robot mode] ;
49: JMP LBL[999] ;
50: ;
51: !Empty ROI ;
52: LBL[5] ;
53: MESSAGE[ROI is empty] ;
54: JMP LBL[999] ;
55: ;
56: !No object found ;
57: LBL[6] ;
58: MESSAGE[No object found] ;
59: JMP LBL[999] ;
60: ;
61: !Exit ;
62: LBL[999] ;
63: END ;
See Pickit macros for more information about the Pickit macros available.
Execution
The program PICKIT_RG_EXECUTION is shown below. This program follows the generic trajectory execution logic.
First check if Pickit is in Robot mode.
If so, the robot moves to its detect pose and a detection is triggered.
If an object is found, User Frame 1 is updated based on the new object pose. Then, the macro PI_RG_REAC is used to check if the trajectory poses are still reachable w.r.t the updated user frame.
If the trajectory poses are reachable, the robot follows the trajectory and goes back to the second step.
If the trajectory poses are unreachable, the program stops.
If the ROI is empty or no object is found, the program stops.
This program can be found in Select.
Note
For R-J3iB controllers, a program called EX_RG_EX.TP is provided where all macro names are adapted to shorter names.
1: !Execution ;
2: !You can run this program after ;
3: !running PICKIT_RG_TEACHING ;
4: ;
5: !Fill in settings below ;
6: UFRAME_NUM=0 ;
7: UTOOL_NUM=1 ;
8: R[1:setup id]=99 ;
9: R[2:product id]=99 ;
10: R[3:max detect]=5 ;
11: ;
12: ;
13: !Init ;
14: CALL PI_OPEN_COMMUNICATION ;
15: CALL PI_RUN ;
16: IF R[151:pi status]<>0,JMP LBL[3] ;
17: CALL PI_CONFIGURE(R[1:setup id],R[2:product id]) ;
18: ;
19: !Main Loop ;
20: LBL[1] ;
21: UFRAME_NUM=0 ;
22: !Detect workpiece ;
23:J P[1:detect] 100% FINE ;
24: CALL PI_DETECTION_WITH_RETRIES(R[3:max detect]) ;
25: CALL PI_GET_RESULT ;
26: ;
27: !Object found ;
28: IF R[150:pi obj status]=20,JMP LBL[4] ;
29: !Empty ROI ;
30: IF R[150:pi obj status]=23,JMP LBL[5] ;
31: !Else no object found ;
32: JMP LBL[6] ;
33: ;
34: !Object found ;
35: LBL[4] ;
36: !Update uframe with detected pose ;
37: UFRAME[1:UFrame1]=PR[51:pi pick pose] ;
38: UFRAME_NUM=1 ;
39: !Check if the taught positions ;
40: !are still reachable ;
41: R[160:pi reach status]=99 ;
42: CALL PI_RG_REAC ;
43: !Object reachable ;
44: IF (R[160:pi reach status]=0),JMP LBL[11] ;
45: !Else object unreachable ;
46: JMP LBL[12] ;
47: ;
48: !Object reachable ;
49: LBL[11] ;
50: !Move to taught trajectory ;
51: !Relative to user frame ;
52:L PR[10] 100mm/sec FINE ;
53:L PR[11] 100mm/sec FINE ;
54:L PR[12] 100mm/sec FINE ;
55:L PR[13] 100mm/sec FINE ;
56: JMP LBL[1] ;
57: ;
58: !Not in robot mode ;
59: LBL[3] ;
60: MESSAGE[Not in robot mode] ;
61: JMP LBL[999] ;
62: ;
63: !Empty ROI ;
64: LBL[5] ;
65: MESSAGE[ROI is empty] ;
66: JMP LBL[999] ;
67: ;
68: !No object found ;
69: LBL[6] ;
70: MESSAGE[No object found] ;
71: JMP LBL[999] ;
72: ;
73: !Object unreachable ;
74: LBL[12] ;
75: MESSAGE[Positions unreachable] ;
76: JMP LBL[999] ;
77: ;
78: !Exit ;
79: LBL[999] ;
80: END ;
See Pickit macros for more information about the Pickit macros available.
Before running the program
The example programs require Pickit to be installed and set up with your robot. For installation instructions, please refer to the Fanuc installation and setup article.
Make sure that Calibration is done. This can be done by running the Fanuc calibration program.
Define the user frame
Make sure that User Frame 1 can be used before running the example program. Note that teaching the user frame is not necessary since it will take the value of the object pose when running the programs.
Adapt the registers used
Below you find an overview of the registers used in the example programs. They should be adapted according the changes you want to apply to this example program.
Note
The Pickit registers, in the 140-160 range, and the Pickit pose registers, in the 50 range, can’t be changed by the user. An overview of these can be found in the Fanuc Pickit interface article.
Variable |
Field name |
Comment |
---|---|---|
R[1] |
Setup |
Requested Pickit setup ID |
R[2] |
Product |
Requested Pickit product ID |
R[3] |
Retries |
Maximum number of detection retries |
P[1] |
Detect pose |
Position not blocking the field of view of the camera |
PR[10] |
Trajectory pose 1 |
Pose in the trajectory of the application |
PR[11] |
Trajectory pose 2 |
Pose in the trajectory of the application |
PR[12] |
Trajectory pose 3 |
Pose in the trajectory of the application |
PR[13] |
Trajectory pose 4 |
Pose in the trajectory of the application |
Note
This program uses four trajectory poses as an example, but more trajectory poses can be added if needed. If a trajectory pose is added, make sure that the macro PI_RG_REAC is updated accordingly.
Collision recovery
To avoid production downtime, it is recommended to add a collision recovery in the robot program. That way, if a collision is detected by the robot while trying to follow a trajectory, the robot does not raise an error requiring an operator intervention. Instead, the robot goes back to the detection and try to process another workpiece.
In Fanuc, this is done using the Skip instruction. If a condition is met, the motion is interupted. By using a condition of a joint torque being above a certain threshold, one can catch collision before the raise an alarm.
From R30iB, touch skip option [A05B-2600-J921] is required.
Note
The variable $MISC_MSTR.$HPD_ENB must be set to 1 to use the feature. The robot motion is typically slowed down for the function to detect correctly collisions.
An example using touch skip is shown below.
//$MISC_MSTR.$HPD_ENB=1 ;
CALL SETSKCOL(1,1) ;
CALL CLSKP_G1 ;
L P[2] 100mm/sec FINE Skip,LBL[1],PR[180]=LPOS ;
LBL[2: touch detected] ;
LBL[1: no touch detected] ;
It is also possible to directly set the thresholds in the tp program as shown below.
//$MISC_MSTR.$HPD_ENB=1 ;
SKIP CONDITION $MISC[1].$HPD_TRQ[2]<(-3.1) OR $MISC[1].$HPD_TRQ[2]>2.1 ;
L P[2] 100mm/sec FINE Skip,LBL[1],PR[180]=LPOS ;
LBL[2: touch detected] ;
LBL[1: no touch detected] ;
Refer to Fanuc documentation for more details.