Tool Changes and Tool Offsets in G-Code

Learn CNC Programming with CNCCookbook’s G-Code Tutorial

G-Code Tool Changes

Most CNC g-code programs will have one or more g-code tool changes programmed into them. This will be true even if your machine doesn’t have an automatic tool changer. That’s because the tool change programming serves two purposes. First, in the case of a machine with an automatic tool changer (ATC), the tool changing g-codes tell the ATC to load a particular tool in the spindle or, in the case of a lathe, to rotate that tool into position on the lathe’s turret. The second role of these codes is to set up a different tool length offset. The tool length offset tells the CNC machine how much the length of the current tool differs from tool #1. It will adjust its notion of where the tool tip is when you make your next move based on this.

Accomplishing these two functions can require anywhere from one to several g-codes. Let’s go through each possible g-code and it’s style of use.

T Tool Select and M06 Tool Change

The “T” word is commonly used to select a tool. On a VMC with ATC, usually the “T” word tells the mill to select that tool, but it requires the M06 word to be executed before the tool is actually changed. This gives the ATC a little bit of advanced warning, allowing it to rotate the new tool into position while the machine is busy doing something else, which can make for a faster tool change. On most lathes, and even for some mills, the M06 is not needed. On those machines, it is likely an error to use an M06.

Sample tool change using T + M06

N10 T12 ( Select Tool #12 )

N20 M06 ( Change to selected tool )

If the machine doesn’t use M06, the sample would look like this:

N10 T12

If you wanted to take advantage of the separate T and M06 to give your machine maximum time to get ready in order to make the tool change faster, you’d do something like this:

T12

M06

T14

(Machining with T12 in spindle, but T14 is ready for next M06)

M06

(Now T14 is loaded)

T02 (Setting up T02 for later)

(Machining with T14)

M06

(Now T02 is in spindle)

( etc. )

 

Random Memory Tool Selection

One trick some machines use to make tool changes go even faster is to set it up so tools don’t have to go back into a particular pocket on the changer. Instead, the machine just sticks the tool in the nearest pocket so it doesn’t have to take so long to rotate a pocket into position. The machine keeps track of which slot T02 is actually in, for example, and you can always refer to it as “T02”
no matter what slot it winds up in.

Tool Offsets: Geometry and Wear Offsets

Now what about that business of selecting a Tool Offset so the machine knows how long the tool is?

First thing to note is that there are actually 2 different length offsets–the Geometry Offset and the Wear Offset. The Geometry offset is associated with each tool by number and is the one that grossly determines tool length. The Wear Offset is a fine tuning change to the overall tool length that is used to compensate for wear and to give the machinist the ability to fine tune what’s happening from part to part. For example, you may be turning a part to diameter and discover that after measuring the diameter with a micrometer it is slightly off. Perhaps it is 0.0013″ too large. To correct, you can enter a wear offset of -0.0013 to cause the machine to come out much closer to the desired tolerance.

Let’s ignore the Wear Offset for the moment. When you do your tool change, your machine controller will automatically apply the Geometry Offset based on the information contained in its tool table about each tool.

Fanuc-Style Combined Tool Number and Offset for Turning

Now that we know about these offsets, let’s take a look at specifying a toolchange on a lathe using Fanuc’s syntax. It’s pretty simple. To select tool #2, we’d use:

T0202

“Why is the “02” repeated twice?” you wonder. That second “02” can be any 2-digits, and it selects the wear offset to use. By convention, most programs make the wear offset the same as the tool number so you don’t have to worry about matching them up.

G-Wizard Editor/Simulator Tool Change and Offset Post Options

This is all pretty simple to set up in the G-Wizard Editor / Simulator’s Post Options:

You have the ability to specify the range of T#’s as well as how many digits at the end of the T# are used to specify the offset.

Exercises

1. Get out your CNC controller manual and set up GWE to match your control’s way of doing Tool Changes.

2. Write a sample g-code program containing a tool change and verify during GWE playback that the tool was changed.

3. For some extra credit, check out our 2-part article on Tool Data Management and start thinking about how you will manage your tool data.

Next Article: Basic CNC Lathe Programming

Recently updated on August 21st, 2023 at 11:33 am