A Universal Error-Trapping Program

Mistakes made when running CNC machine tools will cause consequences. At best, the machine will not behave as expected.

Mistakes made when running CNC machine tools will cause consequences. At best, the machine will not behave as expected. Worse, workpieces may be scrapped. And worse yet, damage may occur to the machine, and/or operators may be injured. While nothing replaces skill and common sense when it comes to running CNC machine tools, CNC programmers should assume some of the responsibility for minimizing the problems caused when mistakes are made.

With parametric programming, a programmer can create tests within programs that can check and see if a mistake has been made. This requires that the programmer is aware that the mistake may occur and has the ingenuity to come up with an appropriate way to test for the mistake condition.

This has been the topic of several columns. Even though we've shown several error-trapping examples, I think we've just scratched the surface of what can be done with parametric programming techniques. While some mistakes require more ingenuity and effort to error trap than others, just about any mistake can be error trapped.

One problem that programmers face is that error-trapping commands must be placed in many CNC programs. This can be tedious and error-prone. Additionally, you may be continually developing error-trapping techniques to handle new problems as they arise, and many commands will have to be added to all current programs. Many programmers just give up on error trapping.

Rather than try to incorporate the specific error-trapping commands in every program, we recommend developing one universal error-trapping program that will be referenced from any program when testing for a problem. Only one command will be added to each program that tests for a given problem. With this technique, you will have just one program to maintain. If a test condition changes, you will have only one set of commands to change. And you will be able to add new error-trapping techniques to this program at any time.

The error-trapping program below allows the testing of two specific problems. Again, you can include as many test conditions as you need in this program. In test number one, we're testing to confirm that the machine is at its Y and Z axis zero return position (this may be necessary on a horizontal machining center before a table index can safely occur). If not, an alarm will be sounded. In test number two, we're testing that the tool length compensation value for a given tool is greater than the specified value (the operator has entered an appropriate value).

O7001 (Universal error-trapping program)
IF[#8 EQ 1] GOTO 100
IF[#8 EQ 2] GOTO 200
#3000 = 100 (NO ERROR SPECIFIED)
N100 (Begin handling first problem—Machine at Y and Z home)
IF [#5022 EQ 0] GOTO 101 (If Y axis is at ZR position, skip alarm)
#3000 = 101 (Y AXIS NOT AT HOME)
IF [#5023 EQ 0] GOTO 199 (If Z axis is at ZR position, exit)
#3000 = 102 (Z AXIS NOT AT HOME)
N199 M99 (Return to calling program)
N200 (Begin handling second problem—tool minimum length)
IF [#20 NE #0] GOTO 201 (If T has been programmed, skip alarm)
#3000 = 104 (T MISSING)
N201 IF [#11 NE #0] GOTO 202 (If H has been programmed, skip alarm)
#3000 = #105 (H MISSING)
N202 IF [#[2000 + #20] GE #11] GOTO 299
#3000 = 106 (TOOL TOO SHORT)
N299 M99

Again, you can include as many test conditions as you need. Note that we've begun each test condition with a new series of sequence numbers to avoid repeating them as new tests are added. We've also specified a new alarm number for each problem. This will allow you to come up with your own alarm list (like what's in the operator's manual) to further document each problem.

When you want to include a test of the Y and Z zero return position (probably before a table index), simply include the following command. Note that this test condition requires no input data to complete the test. We simply include the E word to specify which test to perform.

N055 G65 P7001 E1.0 (Perform test number one)

When you want to test a tool offset value for minimum length, use the following command. This test requires a tool station num-ber (with T) and a minimum length (with H).

N205 G65 P7001 E2.0 T6.0 H3.0 (Perform test number two)