Changing Program Behavior
User-defined codes allow you to make minor method changes to machine workpieces without reprogramming.
CNC programmers dread process and engineering changes because they require program changes. The more workpieces involved, the more programs that must be changed. Consider any method change that would affect all of the workpieces you run on a given machine. How many programs would you need to change to accommodate this method change?
Of course, major process or engineering changes unavoidably will require reprogramming the affected workpieces, especially if those changes require modification of tool paths or machining methods. But with method changes that are minor, and with a little ingenuity, you may be able to handle the issue without having to change a single CNC program.
For example, I know of one company that wanted a machining center to execute a set of G10 commands for entering workpiece coordinate system offsets, not just at the beginning of every machining program, but at the beginning of every cutting tool sequence. The work-offset-setting commands are stored in a subprogram:
O1000 (Work-offset-setting commands)
G90 G10 L2 P1 X-12.2736 Y-8.1127 Z-13.2635
G10 L2 P2 X-15.3766 Y-8.3165 Z-13.3266
G10 L2 P3 X-18.9376 Y-8.3472 Z-13.3887
G10 L2 P4 X-21.1027 Y-8.2716 Z-13.3173
Every time the setup person prepares a new job, he or she measures work offsets and modifies program O1000 accordingly. The beginning of every one of the machining programs currently includes a subprogram-calling command:
N005 M98 P1000 (Enter work offsets)
The method change necessary in this example involves calling the work-offset-entering subprogram at the beginning of every cutting tool sequence, not just at the beginning of the machining program. (This shop has had operators run from the middle of the program for the first workpiece, skipping the subprogram-calling command, but this caused the machine to use work offset settings from the previous job and could have resulted in a crash.)
One way to handle this method change would be to add the subprogram-calling command to the beginning of every tool sequence. However, if an average of 10 cutting tools were to be used in each program, nine program modifications would be required per program. If the company runs 300 programs on the machine, that equates to 2,700 error-prone program modifications.
When you are faced with modifying many programs, and especially when program structure is involved, another alternative with FANUC CNCs is user-created G, M and T codes. These may make it possible to modify the way an existing CNC word works in order to achieve the desired result.
The solution for the shop in our example was to simply modify the G codes related to setting the workpiece coordinate system (G54-G59). Since the appropriate command for invoking workpiece-coordinate-system offsets was already specified at the beginning of every tool sequence, there was no need to modify any machining programs. Now, when G54 is executed to invoke offset number one, it executes a custom macro program that first calls the work-offset-setting subprogram and then executes G54.
Creating user-defined G codes is pretty simple. It requires a parameter change and is documented in the custom macro section of the FANUC operator’s manual. For a 0iF FANUC CNC, for example, parameter number 6050 species the G code number that will call program O9010. If it is set to a value of 54, the CNC will execute program O9010 whenever G54 is executed. For our example, here is program O9010:
O9010 (G54 program)
M98 P1000 (Call work-offset-setting program)
G54 (Perform the normal function of G54)
In this subprogram, G56 will perform its normal function: It will not cause the CNC to execute program O9010 again. Other user-defined G codes must be created for other needed work-coordinate-system-setting G codes, like G55, G56 and so on.
Another application for user-created codes is related to where the machine axes are directed just before the program ends. Maybe you want to come up with a convenient and consistent workpiece loading position. You can simply modify the M30 (or M02) end-of-program word so that when it is executed, the CNC will run the related subprogram. In the subprogram, you would specify the position to which you want the axes to move, then specify the end-of-program word. Here is an example of the subprogram, which assumes M30 is the program-ending word:
O9001 (Called when M30 is executed)
G53 X-12.5 Y-10.0 Z0 (Position is specified
relative to the machine’s reference position)
In order for this to work, of course, the related parameter must also be changed. For a FANUC 0iF control, parameter number 6071 is related to program O9001. For this example, it would be set to a value of 30 so that when the CNC executes an M30 word, it will call program O9001.