How to program a Fanuc robot
Home > Fanuc > Programming > How To Program a Fanuc Robot
Table of Contents
- Introduction
- Basic Teach Pendant Programming
- Motion Commands
- Registers and Position Registers
- Logic and Control Structures
- I/O and Signal Handling
- Palletizing Example
- Pick and Place Example
- Error Handling and Debugging
- Advanced Functions and Tips
- Best Practices
1. Introduction
Fanuc robots are programmed using the Teach Pendant and TP (Teach Pendant) language. This manual provides step-by-step examples to program a Fanuc robot for various industrial applications. The examples cover basic motion, palletizing, pick-and-place, logic structures, error handling, and advanced functions.
2. Basic Teach Pendant Programming
Creating a New Program
- Press [SELECT] to open the program list.
- Press [F1] (TYPE) → [CREATE].
- Enter a name (e.g.,
PALLET
) and press Enter. - Start adding motion and logic commands.
Jogging the Robot
- Set the pendant to Teach Mode (T1).
- Hold [SHIFT] and use the jog keys to move the robot.
- Adjust the coordinate system using [COORD] to switch between Joint, World, Tool, and User frames.
Recording a Position
- Move the robot to the desired position.
- Press [SHIFT] + [F5] (Touch Up) to save the position.
- The saved positions can be used in motion commands.
3. Motion Commands
Joint Move (J)
J P[1] 100% FINE
- Moves the robot in joint mode (fast but less precise).
Linear Move (L)
L P[2] 500mm/sec CNT50
- Moves the robot in a straight line.
- CNT50 allows continuous motion with 50% blending.
Circular Move (C)
C P[3] P[4] 300mm/sec CNT50
- Moves in a circular path between P[3] and P[4].
Override Speed
OVERRIDE 50%
- Adjusts movement speed dynamically.
4. Registers and Position Registers
Registers [R]
Registers (R) store numerical values for calculations, loops, and conditions.
Example: Using Registers for Counting
R[1] = 0 ; Initialize counter
LBL[1]
R[1] = R[1] + 1 ; Increment counter
IF R[1] < 10, JMP LBL[1] ; Loop until R[1] reaches 10
Position Registers [PR]
Position Registers (PR) store coordinates that can be modified during runtime.
Example: Dynamic Positioning with PR
PR[1] = P[1] ; Copy P[1] to PR[1]
PR[1,1] = PR[1,1] + 100 ; Shift X position by 100mm
L PR[1] 500mm/sec FINE ; Move to the new position
5. Logic and Control Structures
Conditional Execution
IF DI[5]=ON THEN JMP LBL[1]
- Jumps to label LBL[1] if digital input DI[5] is active.
Loops
LBL[1]
R[1] = R[1] + 1
IF R[1] < 10, JMP LBL[1]
- Repeats 10 times.
6. I/O and Signal Handling
Wait for Input
WAIT DI[3]=ON
- Pauses execution until digital input DI[3] is ON.
Set Output Signal
DO[2]=ON
- Turns on digital output DO[2] (e.g., activating a gripper).
7. Palletizing Example
J P[10] 100% FINE ; Move to home
LBL[1]
L P[2] 500mm/sec FINE ; Move to pick location
DO[1]=ON ; Activate gripper
WAIT 0.5 sec
L P[3] 500mm/sec CNT50 ; Move to pallet position
DO[1]=OFF ; Release box
WAIT 0.5 sec
R[1]=R[1]+1
IF R[1]<12, JMP LBL[1] ; Repeat until 12 boxes placed
END
8. Pick and Place Example
J P[10] 100% FINE ; Home position
LBL[1]
L P[5] 300mm/sec FINE ; Move to pickup
DO[1]=ON ; Grasp object
WAIT 0.5 sec
L P[6] 300mm/sec FINE ; Move to destination
DO[1]=OFF ; Release object
WAIT 0.5 sec
J P[10] 100% CNT50 ; Return to home
JMP LBL[1] ; Repeat process
9. Error Handling and Debugging
Error Handling Example
LBL[100]
IF DI[7]=OFF THEN JMP LBL[101] ; Check for part presence
DO[4]=ON ; Signal error condition
WAIT 1.0 sec
DO[4]=OFF
JMP LBL[100]
LBL[101]
10. Advanced Functions and Tips
Using Macros
CALL MACRO1 ; Calls a predefined macro for repetitive tasks
Using Timers
TIMER[1]=0 ; Reset timer
WAIT TIMER[1] > 5.0 ; Wait for 5 seconds
11. Best Practices
- Use CNT blending to smooth transitions between points.
- Use Position Registers (PR) for dynamic locations.
- Backup programs before making modifications.
- Optimize motion paths to reduce cycle time.
- Label important code sections for better readability.