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
M99
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)
M99
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)
M30
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.
Related Content
4 Reasons to Use Safety Commands
Safety commands help safeguard CNC applications from common programming or operation errors.
Read MoreObscure CNC Features That Can Help (or Hurt) You
You cannot begin to take advantage of an available feature if you do not know it exists. Conversely, you will not know how to avoid CNC features that may be detrimental to your process.
Read More3 Mistakes That Cause CNC Programs to Fail
Despite enhancements to manufacturing technology, there are still issues today that can cause programs to fail. These failures can cause lost time, scrapped parts, damaged machines and even injured operators.
Read MoreHelp Operators Understand Sizing Adjustments
Even when CNCs are equipped with automatic post-process gaging systems, there are always a few important adjustments that must be done manually. Don’t take operators understanding these adjustments for granted.
Read MoreRead Next
The Future of High Feed Milling in Modern Manufacturing
Achieve higher metal removal rates and enhanced predictability with ISCAR’s advanced high-feed milling tools — optimized for today’s competitive global market.
Read MoreIMTS 2024: Trends & Takeaways From the Modern Machine Shop Editorial Team
The Modern Machine Shop editorial team highlights their takeaways from IMTS 2024 in a video recap.
Read MoreIncreasing Productivity with Digitalization and AI
Job shops are implementing automation and digitalization into workflows to eliminate set up time and increase repeatability in production.
Read More