Programs

From Industrial Robotics & Automation - Fanuc Teach Pendant Programming
The example used on this page is for a milling program, where a technician sets a cutting depth, then starts the process with a START button.

Teach pendant programs are generally simplistic, following much of the same structure as other programming languages.

It's a good idea to break your program into sections as listed below, to help organize your code.

This is an example program that you may see in the field. A technician can set a cutting depth on a knob, and then press a START button to begin cutting the product.



Setup Section

The first lines of a program should be your setup instructions. This often means zeroing registers and setting constants to be used later. It's also a good idea to set all your outputs to ideal conditions. We just happen to be using PR[10] in this program, but you may not know what you're going to use until you reach it. You can always insert lines at the beginning of your program to setup the registers later on when you know which registers you will use.

We can zero entire position registers easily using a single register instruction.

Examples:

PR[10]=PR[10]-PR[10]


Intro Motion

It can be useful to include motion instructions that take your robot to a known position, in case of power failure or a prior program leaving off in a weird place. Use a Joint move to ensure you don't enter singularity.

J P[1:Home] 20% FINE


Loop

Since when looping, you aren't likely to want it to go home every single time and don't want to zero your registers each time, we will begin our loop here. We will jump to this label later in the program, with JMP LBL[1]

LBL[1]

Everything inside the loop will occur over and over. In this example, we only want it to repeat when we press a "Start" button. We can also open up the digital input 104 in the IO screen and comment it with the word START.

WAIT DI[104:START] = ON

Configuration

Depending on program state, input values, counts, times, and other variables - you can set up configuration data to match. This lets you run short, efficient motion instructions with few or no special sections. In this example, an analog input, AI[1] is read and applied to the Z element (element 3) of our position register. We multiply by negative 1 so that it subtracts that z height from our motion instructions later.

Note that this part isn't reached until someone presses that "Start" button above, so the technician will set the analog value with a knob and THEN press start.

PR[10, 3] = AI[1] * -1

Any changes to the knob after starting won't affect the motion until the next loop, so the technician could actually begin entering the next value on the knob immediately.

Motion

Your motion lines should be efficient and minimalist. Anything that can be done with a new tool frame, user frame, offset, and registers should be, instead of having lots of similar motion lines.

In this example, each of the lines uses the offset of PR[10] so whatever negative value was on the knob when START was pushed, will be applied to the motion instructions.

J P[1] 100% Fine

L P[2] 222mm/s Fine OFFSET PR[10]

L P[5] 100mm/s Fine OFFSET PR[10]

L P[3] 222mm/s Fine OFFSET PR[10]

C P[8] OFFSET PR[10]

... P[6] 222mm/s Fine OFFSET PR[10]

L P[1] 100mm/s FINE OFFSET PR[10]

Since we don't want this program to end, instead just waiting to begin again when the button is pushed again, we will add a jump instruction up to LBL[1].

JMP LBL [1]


Results

The program sets everything up (zeroing the position register), goes home, and then waits for input. The technician configures the knob to whatever depth they wanted to perform the tasks at, and then presses START. The program will set the value of the knob (as a negative number) to the position register, and then the robot performs its motion tasks, at the newly offset height. Once it has finished, it will jump back up and wait for the technician to set a new height and press START again.