I’ve seen all kinds of structure (or lack of it) in CNC programs. Admittedly, it is hard to argue with success – and if the structure you use is working for you, by all means, continue using it. I simply want to make a few suggestions that may get you thinking about the structure you use.
Here is an example of a structure recommended for vertical CNC machining centers.
O0001 (program number)
N001 G17 G20 G23 (Select XY plane, inch mode, cancel stored stroke limit)
N002 G40 G50 G64 (Cancel cutter radius compensation, cancel scaling, select normal cutting mode)
N003 G67 G69 G80 (Cancel modal custom macro call, cancel rotation, cancel canned cycle)
(TOOL NAME FOR FIRST TOOL)
N005 T01 M06 (Load first tool in spindle)
N010 G54 G90 S300 M03 T02 (Select fixture offset, absolute mode, turn spindle on fwd at desired RPM, get next tool ready)
N015 G00 X5.0 Y5.0 (Move to first XY position)
N020 G43 H01 Z0.1 (Instate tool length compensation for first tool, move to first Z position)
N025 M08 (Turn on the coolant)
N030 G01 . . . . F3.0 (In first cutting movement, be sure to include a feedrate)
N075 M09 (Turn the coolant off)
N080 G91 G28 Z0 M19 (Return to tool change position, orient the spindle during motion)
N085 M01 (Optional stop)
(TOOL NAME FOR THIS TOOL)
N135 T02 M06 (Ensure that the next station is still ready and make the tool change)
N140 G54 G90 S450 M03 T03 (Select fixture offset, select absolute mode, turn spindle on CW at desired RPM, get next tool ready)
N145 G00 X4.0 Y4.0 (Move to this tool’s first XY position)
N150 G43 H02 Z0.1 (Instate tool length compensation, move to first Z position)
N155 M08 (Turn on the coolant)
N160 G01…. F4.0 (In first cutting movement, be sure to include a feedrate)
N310 M09 (Turn coolant off)
N315 G91 G28 X0 Z0 M19 (Return to tool change position in Z, orient spindle during motion)
N320 G28 Y0 (Return to zero return position in Y)
N325 M30 (End of program)
Notice right off the bat that a large percentage of commands in most programs are related to the program’s structure. Only the commands related to what the cutting tool is doing (motion commands) are not part of the structure shown.
The first reason I offer for strictly structuring your programs is that it will help you (and others that view your programs) become familiar with programming words and commands.
When you start writing a new program, simply follow the program startup format. Then write the motion commands for the first tool. When you’re done with the first tool, follow the tool changing structure. Then write the motion commands for the second tool. Repeat this process until you’re finished with the last tool’s cutting motions – and finish by following the program ending structure.
With the format developed, you – and others – won’t have to memorize all words and commands in a program. You’ll simply have to remember what the word or command does when you see it. This should be easy since the word or command will be in the correct context of a CNC program.
You may be questioning the first three commands after the program number (N1 through N3). I call these safety commands. The goal is to ensure that all initialized states (words that are automatically instated during power up) are still in effect. The G20, for example, ensures that the machine is in the Imperial measurement system (inch) mode. Since many Fanuc controls allow only three compatible G codes per command, we break the safety commands into three separate commands.
Setup people and operators must often read – and work on – your programs. Using a strict structure ensures that once they learn how you structure your programs, they won’t be in for any nasty surprises. It will also help you repeat past successes since if the structure works in one program, it will continue to work in another.
If your company has more than one programmer, it is important to ensure that they all structure their programs in the same manner. I have been in companies that have several programmers, and everyone structures their programs differently. This can wreak havoc for setup people and operators, since they’ll have multiple program structures to learn.
The most important reason for strictly formatting programs is to allow the re-running of individual cutting tools. If you have a five-tool program and something goes wrong in the middle of the fifth tool, you’ll need to correct the problem and run the fifth tool again. It wouldn’t make sense – nor would it be advisable – to run the entire program again just to get to the fifth tool. Doing so would be a waste of time – and could cause some damage to the workpiece.
The way a program is structured determines whether it will be possible to re-run individual tools. Certain programming words and commands needed to at the beginning of the program will be needed for each tool. In some cases, this means repeating some redundant information at the beginning of each tool – just to gain the ability to rerun the tool should the need arise.