FANUC Robot Programming Tutorial: Write Your First Program Step by Step
Learn FANUC robot programming from scratch — the teach pendant, TP vs Karel languages, motion commands, registers, I/O, and a complete annotated first program.
Introduction: Why FANUC Robot Programming Is a Valuable Skill
FANUC is one of the most widely deployed industrial robot platforms in the world, appearing across automotive assembly, electronics manufacturing, metal fabrication, and material handling. If you work in any of those industries — or aspire to — understanding how to program a FANUC robot is a career-defining skill.
This tutorial walks you through everything you need to write and run your first real FANUC program: the teach pendant interface, the two programming languages (TP and Karel), motion instructions, position and data registers, I/O wiring logic, and safety modes. It closes with a complete, annotated pick-and-place program you can adapt immediately.
If you're already a PLC programmer, you'll find the concepts familiar in structure but different in execution. Where a PLC runs a scan cycle reacting to I/O states, a robot controller executes a sequential list of motion and logic instructions that physically move hardware through space. The mental model shift is worth understanding before you write a single line — and we cover it directly in the section below.
For a broader view of how robots, PLCs, and SCADA systems integrate, see the industrial automation programming guide.
What Language Does a FANUC Robot Use?
FANUC robots support two onboard languages: FANUC TP (Teach Pendant) programming and Karel.
TP Programming
TP is the primary language for motion programs. It is a line-numbered, motion-centric language that you write and edit directly on the teach pendant. Every line in a TP program is either a motion instruction (telling the robot where to move and how fast) or a logic instruction (I/O commands, register operations, conditional jumps, waits). TP programs have the .TP file extension and are executed by the robot controller's motion interpreter.
TP is the language you will use for 90% of shop-floor programming work. It is intentionally constrained: no recursive calls, no complex data structures, no string formatting. Those constraints exist because the language runs in a hard-real-time motion environment where predictability matters more than expressiveness.
Karel
Karel is a Pascal-derived high-level language compiled and loaded onto the controller separately from TP programs. It has full string handling, file I/O, socket communication, and the ability to create and modify TP programs dynamically at runtime. Karel is used for:
- Building operator HMI overlays and custom setup screens
- Complex recipe management and data logging
- Generating robot paths algorithmically (e.g., from CAD data)
- Communicating with external systems via TCP/IP
Karel programs are compiled offline (or on a PC with ROBOGUIDE) and transferred to the controller. You generally do not write Karel directly on the teach pendant.
TP vs Karel: Which to Use When
| Situation | Use |
|---|---|
| Moving the robot through a fixed sequence of positions | TP |
| Pick-and-place, welding, assembly, palletizing | TP |
| Reading/writing files, building dynamic motion paths | Karel |
| Custom operator screens, data logging to CSV | Karel |
| Calling a utility subroutine from within a TP program | Either (TP calls Karel programs with CALL) |
| Learning robot programming for the first time | TP |
The majority of integrators never write a single line of Karel. Start with TP, move to Karel when you hit a task TP genuinely cannot do.
The Teach Pendant: Keys, Jogging, and Coordinate Frames
The teach pendant is the handheld device used to jog the robot, teach positions, write and edit programs, and control execution. Understanding its layout before writing code saves significant time.
Key Groups You Must Know
- DEADMAN switch — A three-position switch on the back of the pendant. You must hold it in the middle (partially squeezed) position for the robot to move in T1 or T2 mode. Release or squeeze fully and motion stops. This is a primary safety device.
- ENABLE/DISABLE — Enables teach mode; the pendant must be enabled (ON) before the robot responds to jog inputs.
- SHIFT — A modifier key. Many jog and pendant functions require SHIFT to be held simultaneously.
- JOG keys — Arrow-style keys for jogging individual axes or the TCP (tool center point) in Cartesian space.
- COORD — Cycles through coordinate frames for jogging.
- STEP / NEXT / PREV — Navigate program lines.
- FWD / BWD — Execute program forward or backward one step at a time during testing.
- RESET — Clears faults.
- SELECT — Opens the program list.
- EDIT — Opens a program for editing.
Coordinate Frames for Jogging
FANUC robots support several jogging frames:
- Joint — Each axis rotates or extends independently. Useful for getting the robot out of a singularity or a joint limit.
- World — The robot TCP moves along the global X, Y, Z axes of the robot's base coordinate system. The most intuitive frame for large Cartesian moves.
- Tool — The TCP moves along the axes of the tool (end-effector) frame. Useful for approach/retract motions aligned with the tool orientation.
- User — A custom frame defined relative to a fixture or conveyor. Once defined, the robot moves relative to that fixture rather than the robot base. Critical for programs that need to be re-taught when a fixture is repositioned.
Understanding frames is not optional. Teaching positions in the wrong frame is one of the most common sources of rework during commissioning.
Creating Your First FANUC TP Program: Step by Step
Step 1: Power On and Select T1 Mode
Switch the controller key to T1 (Teach 1) mode. T1 limits robot speed to a safe maximum (typically 250 mm/s TCP speed) regardless of what percentage you program. T1 is the only mode in which you should write and test new programs.
Step 2: Create a New Program
On the teach pendant:
- Press SELECT to open the program list.
- Press F2 (CREATE) or the equivalent softkey for your controller version.
- Enter a program name (alphanumeric, no spaces — for example
PICK_PLACE_01). - Confirm. The controller creates an empty TP program and opens it for editing.
Step 3: Jog to Your First Position and Teach It
- Hold the DEADMAN switch in the middle position.
- Use the JOG keys (in World or Joint frame) to move the robot to your desired starting position.
- With the cursor on an empty program line, press SHIFT + F1 (POINT) (or the record/teach softkey) to record the current TCP position as a motion instruction.
- The controller inserts a motion line with a new position register reference (for example
P[1]). - Repeat for each position in your sequence.
Step 4: Set Motion Types and Speed
After teaching positions, edit each motion line to specify:
- Motion type (J, L, or C — covered in the next section)
- Speed (percentage for Joint, mm/s or deg/s for Linear/Circular)
- Termination type (FINE or CNT — covered below)
Step 5: Add Logic Instructions
Between motion lines, insert I/O commands, waits, register operations, and conditional jumps using the F1 (INST) instruction insertion menu.
Step 6: Test in T1 Mode
With the program open, hold the DEADMAN switch and press SHIFT + FWD to step through the program one line at a time. Watch the robot move. Verify each position is correct before running more than one line at a time.
Motion Commands: J, L, and C Explained
Every motion line in a TP program follows this basic structure:
<motion type> <position> <speed> <termination>
Joint Motion (J)
J P[1] 100% FINE
Joint motion moves all robot axes simultaneously to reach the target position. The path through space is not a straight line — the axes interpolate together, taking whatever path is most efficient. Joint motion is the fastest motion type and is used for large repositioning moves where the path between points does not matter. Speed is specified as a percentage of maximum joint speed (1–100%).
Linear Motion (L)
L P[2] 500mm/sec FINE
Linear motion moves the TCP in a straight line between the current position and the target. The controller solves the inverse kinematics continuously to maintain a linear TCP path. Linear motion is used for approach moves, tool engagement, and any motion where the path matters (such as welding or dispensing). Speed is specified in mm/s (or in/min for imperial units).
Circular Motion (C)
C P[3] P[4] 300mm/sec FINE
Circular motion requires two points: a via point on the arc (P[3]) and the endpoint (P[4]). The TCP follows an arc through the via point to the endpoint. Used for seam-welding curved parts or dispensing along a radius.
Termination Types: FINE vs CNT
FINE — The robot decelerates completely to a stop at the taught position before executing the next instruction. Use FINE at every position where precise placement matters: picking, placing, tool engagement.
CNT (Continuous) — The robot blends through the position without stopping. A CNT value of 0–100 controls how closely the robot passes to the taught point. CNT 100 gives the widest blend (maximum speed, furthest from the point); CNT 0 is nearly indistinguishable from FINE. Use CNT for repositioning moves where cycle time matters and exact path is not critical.
Position Registers and Data Registers
Position Registers (PR)
A position register (PR[n]) stores a Cartesian (X, Y, Z, W, P, R) or joint position that can be modified at runtime. Unlike P[n] (which is a fixed taught point embedded in the program), a position register can be written by a Karel program, loaded from a recipe, or offset mathematically.
L PR[1] 200mm/sec FINE
Position registers are essential for palletizing (where each stack layer is an offset of a base position) and for any application where positions are computed rather than manually taught.
Numeric Registers (R)
Numeric registers (R[n]) hold integer or real values — counters, flags, recipe parameters, loop indices.
R[1] = R[1] + 1 ; increment a counter
Registers are shared across all programs on the controller and persist through power cycles (unless explicitly cleared). Use consistent register assignment documentation to avoid conflicts.
I/O: Digital Inputs and Outputs
FANUC uses several I/O namespaces:
- DI[n] / DO[n] — Standard digital inputs and outputs connected to the robot's I/O module or fieldbus adapter.
- RI[n] / RO[n] — Robot-specific I/O for signals like the pneumatic gripper, tool solenoids, or end-of-arm tooling.
- UI[n] / UO[n] — User interface I/O, typically connected to a PLC or safety relay for signals like Cycle Start, Fault Reset, and Robot Ready.
- SI[n] / SO[n] — System I/O reserved by the controller for internal functions.
Reading and Writing Digital I/O in TP
DO[1:GRIPPER_CLOSE] = ON ; close gripper
WAIT DI[2:PART_PRESENT] = ON TIMEOUT LBL[99] ; wait for sensor, jump on timeout
The label after the I/O address (colon + text) is an optional comment — it does not affect execution but makes programs dramatically easier to read.
Loops and Conditionals: IF, JMP LBL, and WAIT
TP programs are sequential by default. These instructions add flow control:
Conditional Jump
LBL[1]
IF R[1] < 10, JMP LBL[2]
JMP LBL[1]
LBL[2]
JMP LBL[n] unconditionally jumps to label n. The IF instruction evaluates a condition and jumps only when true. This is TP's primary loop and branch mechanism.
WAIT
WAIT 1.00(sec) ; pause for 1 second
WAIT DI[3:CONVEYOR_READY] = ON ; pause until input goes high
WAIT pauses program execution for a fixed time or until an I/O condition is met. A TIMEOUT LBL[n] clause redirects to a fault-handling label if the condition is not met within the robot's configurable timeout period.
A Complete Annotated First Program
The program below performs a simple pick-and-place: approach a pick position, close a gripper, lift, move to a place position, open the gripper, and return to a safe home position. It is written in standard TP syntax.
/PROG PICK_PLACE_01
/MN
1: UFRAME_NUM=1 ; use User Frame 1 (fixture frame)
2: UTOOL_NUM=1 ; use Tool Frame 1 (gripper TCP)
3: DO[1:GRIPPER]=OFF ; ensure gripper is open at start
4: WAIT 0.50(sec) ;
5:J P[1:HOME] 100% FINE ; joint move to home/safe position
6:J P[2:PICK_APPROACH] 80% CNT50 ; joint move to above pick point
7:L P[3:PICK_POINT] 200mm/sec FINE ; linear descent to pick point
8: DO[1:GRIPPER]=ON ; close gripper
9: WAIT 0.30(sec) ; allow gripper to close fully
10:L P[2:PICK_APPROACH] 300mm/sec FINE ; linear retract (lift)
11:J P[4:PLACE_APPROACH] 80% CNT50 ; joint move to above place point
12:L P[5:PLACE_POINT] 200mm/sec FINE ; linear descent to place point
13: DO[1:GRIPPER]=OFF ; open gripper (release part)
14: WAIT 0.30(sec) ; allow gripper to open fully
15:L P[4:PLACE_APPROACH] 300mm/sec FINE ; linear retract
16:J P[1:HOME] 80% FINE ; return to home
17: END ;
/POS
P[1]{
GP1:
UF : 1, UT : 1, CONFIG : 'N U T, 0, 0, 0',
X = 500.000 mm, Y = 0.000 mm, Z = 800.000 mm,
W = 180.000 deg, P = 0.000 deg, R = 0.000 deg
};
P[2]{... } ; /* teach remaining positions on your actual robot */
/END
Line-by-line walkthrough:
- Lines 1–2 set the active User Frame and Tool Frame. Explicitly setting these at program start prevents errors if another program changed them.
- Line 3 pre-opens the gripper before any motion starts — a defensive habit.
- Line 4 gives the gripper solenoid a settling time.
- Line 5 is a Joint move to a named home position. 100% joint speed is acceptable here because home is a known safe position with no obstacles.
- Line 6 is a blended Joint move toward the pick approach point. CNT50 keeps speed up because the exact path above the fixture does not matter.
- Line 7 is a Linear descent to the taught pick point. FINE ensures the robot stops exactly at the programmed position before gripping.
- Lines 8–9 close the gripper and wait for it to engage.
- Line 10 is a Linear retract — straight up, same approach path in reverse.
- Lines 11–15 mirror the pick sequence at the place location.
- Line 16 returns home to signal cycle complete.
- Line 17
ENDterminates the program. In continuous-cycle mode the controller typically calls the program again from line 1.
For PLC Programmers: Bridging the Mental Model
If you come from PLC programming or have experience with IEC 61131-3 languages, the transition to robot programming involves one core reframing: a PLC reacts, a robot acts.
A PLC scan cycle continuously evaluates rung conditions and drives output states. The program has no inherent "current step" — every rung is evaluated every scan. In contrast, a robot TP program has an explicit program counter. The robot is always at a specific line, executing it to completion before moving to the next. Motion takes real time: a 2-second Linear move holds the program counter for those 2 seconds.
This means the patterns you know from Structured Text programming — sequential logic, loops, conditionals — transfer well to TP. The patterns from Ladder Logic — parallel evaluation, coil-contact relationships — do not map directly. Think of a robot program more like an industrial version of a sequential material handling PLC program written in Structured Text than like a relay-logic rung network.
I/O interaction in robot programs is also different: rather than a PLC writing to a robot I/O bit directly on every scan, handshaking is done through UI/UO signals and discrete DI/DO points. The PLC sends a Cycle Start pulse via UI; the robot executes and signals Cycle Complete via UO. For a deeper look at how PLCs and robots coordinate in larger systems, the manufacturing automation guide covers integration architecture in detail.
Running and Testing Safely: T1, T2, and AUTO Modes
T1 (Teach 1) — Maximum 250 mm/s TCP speed. DEADMAN switch must be held. Use for: initial program testing, position verification, fault investigation.
T2 (Teach 2) — Full programmed speed with DEADMAN switch held. Use for: verifying cycle time, checking blending behavior at full speed before releasing to production. T2 requires a deliberate key switch position — do not enter T2 until T1 testing is complete.
AUTO — Full speed, no DEADMAN required. The safety fence or light curtain circuit must be closed. Personnel must be outside the robot's work envelope before enabling AUTO. AUTO mode is the production operating mode.
Dry Run — A pendant function that runs all motion at reduced speed regardless of programmed speed. Useful for visual path verification before full-speed testing.
Always test new programs line-by-line with SHIFT + FWD in T1 before stepping up to continuous execution or faster modes.
Offline Programming: ROBOGUIDE and Why It Matters
The teach pendant is sufficient for simple programs, but teach-pendant-only development becomes slow and costly for complex workcells. ROBOGUIDE is FANUC's PC-based offline simulation environment. It allows you to:
- Build a virtual 3D model of the robot and workcell
- Write and simulate TP and Karel programs without a physical robot
- Verify cycle times and detect reach or singularity issues before the robot arrives
- Generate positions that are then fine-tuned on the real robot
ROBOGUIDE reduces physical commissioning time significantly on complex programs. Most professional FANUC integrators develop 70–90% of their program logic offline and use the pendant only for final position touch-up.
For larger automation projects, offline programming connects naturally to the broader manufacturing automation guide principles around digital twin development and virtual commissioning.
This article covers the TP and Karel fundamentals you need to get started. For a complete reference covering multi-robot systems, coordinated motion, safety zones, and advanced Karel architecture, see our planned industrial robot programming guide.
Frequently Asked Questions
What language do FANUC robots use?
FANUC robots use two onboard languages: TP (Teach Pendant) programming for motion sequences and basic logic, and Karel for advanced applications requiring file I/O, string handling, TCP/IP communication, or dynamic program generation. TP is used for the vast majority of day-to-day programming work; Karel is reserved for tasks that require capabilities TP does not provide.
Is FANUC robot programming hard to learn?
FANUC TP programming is considered moderate difficulty. The motion instruction syntax is limited and logical, making the first program achievable in a day or two of focused effort. The steeper part of the curve is understanding coordinate frames, safe jogging procedures, and how to structure programs for reliable production use. Engineers who already understand PLCs or industrial automation programming typically progress faster because the underlying control system concepts are familiar.
How long does it take to learn FANUC robot programming?
Most technicians and engineers can write, test, and run a basic pick-and-place TP program within one to three days of hands-on time. Reaching professional-level proficiency — including program structure, error handling, I/O handshaking with a PLC, and offline programming in ROBOGUIDE — typically takes three to six months of regular practice on real projects. Karel programming adds additional learning time, but most roles do not require it.
What is the difference between TP and Karel?
TP is a motion-centric, line-numbered language edited directly on the teach pendant. It excels at defining robot movement sequences, triggering I/O, and implementing straightforward logic. Karel is a compiled, Pascal-derived language written on a PC and loaded onto the controller. It can manipulate strings, read and write files, communicate over Ethernet, and generate TP programs at runtime. Use TP for motion programs; use Karel when TP's capabilities are insufficient for the task.
What is offline programming for FANUC robots?
Offline programming means writing and simulating robot programs on a PC rather than directly on the teach pendant at the robot. FANUC's offline tool is ROBOGUIDE, which provides a 3D simulation environment where you can build a virtual workcell, write TP and Karel programs, verify reach and cycle time, and detect errors before commissioning. Programs are then transferred to the real robot controller and positions are fine-tuned on the physical hardware. Offline programming significantly reduces the time engineers spend at the robot and allows development to proceed in parallel with mechanical installation.


