G54, G52, and G92 G-Codes: Work Offsets for CNC Fixtures
Recall the Coordinate Transformation Pipeline that is used to convert coordinates in g-code to the actual coordinates the machine is to move to:
The 5 Step G-Code Coordinate Pipeline…
This chapter on g-code programming is all about G52, G54, G92 and related work and fixture offset commands. After the prior steps in the pipeline, our coordinates have been converted to the proper units (Imperial or Metric), converted to absolute coordinates (via G90/G91 status) and now we’re ready to offset those coordinates to the actual work location.
Why Offset Coordinates to a Work Location?
Why would we want to offset the coordinates to a work location? Think of work offsets as being like bookmarks. They identify places in your machine’s work envelope (the range of positions it can move to) that are of interest. For example, suppose we have 4 vises on the table capable of holding 4 parts for machining. This can speed up production as we can stick 4 workpieces in the vises, push the “Start” button, and not have to worry about it until the machine has finished 4 parts. This requires much less effort than swapping out ever single part as it is finished.
What would a program for such a 4 part setup look like?
Well, ideally, we don’t want to have to change the part program to handle the coordinates of each part position. We’d like to write the program relative to part zero, and then let some other function magically change the coordinates as we work on each part. After all, they’re just shifted over relative to one another, but other than that, the part programs would be identical.
A specialized fixture may be set up for a number of part positions, and it may be intended that each position have a work offset assigned to make it easy to program g-code for the fixture. The most complex examples of this are 4th axis and tombstones that may even combine different kinds of parts and use a variety of work offsets to keep it all straight.
Sometimes there are work offsets associated with some feature of the machine. Maybe you’ve mounted a tool sensor at a particular place on the table and use a work offset to keep track of that location.
Dealing with those kinds of situations is what work offsets were made for.
How Are Work Offsets Specified in G-Code?
Basic work offsets are very simple to specify: simply enter one of G54, G55, G56, G57, G58, or G59. Most machine startup with G54 selected. It’s a good practice to put a G54 into the safety line at the top of all of your g-code programs to make sure you know what work offset is being used unless you have reason to want to leave that aside.
When you execute the work offset g-code, the XYZ offset will be added to all of your coordinates from that point forward. Let’s return to our 4 vise setup. You might want to set 4 work offsets to be the coordinates of the left rear vise jaw corner of each vise. You want to choose the non-moving jaw because that one’s position is more accurate. Use and edge finder or probe to locate the position of that vise jaw corner and then set that work offset based on the way your machine controller sets up offsets. Once you have G54 through G57 set to the four vise jaw positions, you’re ready to go.
You could issue a work offset manually based on which vise you stick the workpiece in, but it’s more productive to do it right in the g-code. The overall scheme looks like this:
( Code for part in first vise )
( Code for part in second vise )
( Code for part in third vise )
( Code for part in fourth vise )
For now, you’ll probably just cut and paste copies of the code. Assuming your control supports them, once you learn to use subprograms, you can keep one copy of the part code, and call it as a subprogram from each work offset block. By way of example, here’s how a subprogram setup might look to make 4 identical parts with work offsets:
( Call the part subprogram )
( Call the part subprogram )
( Call the part subprogram )
( Call the part subprogram )
M30 (Stop the program )
O2000 (Part Subprogram)
( g-code to make a part )
M99 (Return to Main program)
As you can see, subprograms can make it very slick and easy for you to make a lot of identical parts.
Extending the Number of Work Offsets
With G54 to G59, you have 6 work offsets. That’s pretty helpful, but what if you have even more parts to be made. There might be room for dozens of small parts on a big fixture plate for a machine with long travels.
Over the years, the makers of CNC Controllers have come up with several ways to extend the syntax to allow a lot more work offsets. One common approach is to use “G54.1 Pxxx” where the “xxx” is a number. Typical ranges for the number are 1..48 or 1..300. You’ll want to look up the specifics in your machine’s programming manual. To use work offset #45, you’d simply issue the following g-code:
G54.1 P45 ( Use Work Offset #45 )
Some controls allow the “.1” to be omitted, so you could write “G54 P45”.
Using this new syntax, you get the original 6 work offsets plus however many more are available.
Extra Offsets for Haas Machines
Haas allows G110..G129 to reference offsets just as G54.1 Px does.
Setting Up G-Wizard Editor’s Work Offsets
Here are the relevant post variables:
Set this checkbox if your controller allows G53..G59.
Mach3 allows the syntax G59 P1..P255 for an additional 255 offsets.
Okuma controls use G15 H0..H50 for their work offset syntax.
These work offsets are used once and then the system goes back to the prior offset that was used. The syntax is G16 H0..H50 for a one shot work offset.
Offsets.Plus300Offsets and Offsets.Plus48Offsets
As mentioned G54.1 Pxx is a popular syntax for more offsets. xx may range from 1..300 or 1..48. You can also set the Haas G110..G1xx offsets on the 1..48 tab where they are called out.
Haas allows G110..G129 to provide additional work offsets beyond the basic 6.
In addition Haas allows the syntax “G154 Pxxx” where “xxx” is number from 1..99.
More G-Wizard Editor Tools for Work Offsets
The whole purpose of G-Wizard Editor is to make all this g-code programming easier, right? Well, here’s what we’ve added to make using work offsets easier:
Work Offset Hints
The Hints feature in G-Wizard Editor tells you what a line (what’s officially called a “block”) of g-code does in plain English. It’s really handy when learning g-code, but it tells you all sorts of things that just aren’t in the g-code even if you know how to read it already. For example, on an arc, it calls out the arc center as well as a bunch of other information. In this latest release, when a new work offset is put in place, it tells you the XYZ coordinates of the Work Offset. Something like this:
This gcode sets several work coordinates as part of a loop and each of them is recorded in the hint…
That hint is particularly nifty because the workoffsets are being set as #variables. The line G#100 executes a gcode based on the value of variable #100. In this case, the value goes from 54 to 59, so we set all the work offsets from G54 to G59. You get to see the Work Offset XYZ coordinates for each value of the variable below. That can be really helpful in a sophisticated gcode like this one in helping understand what’s going on.
Work Offset Spreadsheets
Here’s on more goodie if you work with #variables a lot. GWE stores those variables in spreadsheet CSV files. This means you can open up the file to see all the variables laid out at once. You could even substitute a file to set up for different jobs. To find these files, go to the Setup Files tab. All the setup files are called Preferences files and that tab tells you the directory where they are kept.
G92: A Programmable Temporary Work Offset
Suppose you want a programmable temporary work offset. There are a lot of ways to accomplish this, but one that is tried and true is to use G92. G92 establishes a work offset based on the offset coordinates you provide. So, if that vise jaw corner we’ve talked about is located from the current tool position at offset X10Y10Z0, you could execute the following:
Now the coordinates of the vise corner are X0Y0Z0. You’ve just established your own work offset using G92.
Let’s consider another example where a G92 or one of the other ways of programming a work offset might be handy. Let’s suppose you have a fixture plate that has a grid of parts on it. You know in advance that the parts are 4 across and 2 down, so there will be 8 parts. The plate is made so that the X and Y distance between each part is constant (within tolerances of course). So, the parts are maybe 5 inches apart in X and 5 inches in Y.
Since G92 is an offset from the current tool position, we move the tool to part zero on the first part at the beginning of the g-code program. We can then use G92 to add offsets relative to that position, 5 inches in X and 5 inches in Y for each part as we step through them. Pretty handy, huh?
Note that G92 is available on mills and some lathes, but most lathes use G50 for this function.
G52: Offset the Offsets
Given the number of features associated with offsets on CNC machines, it must be obvious how handy they can be. So much so that there are a lot of different ways to achieve similar results. Suppose you’ve set up work offsets for each part on the table. Now further suppose each part has some identical features located at different points on the part. You could use even more work offsets to identify those identical features so you can use the same g-code to machine them, or you could use G52 to create a temporary offset on the offset. That might look like this:
G54 (Select the work offset for the part)
G52 X10Y10 ( Select an offset from part zero for the first feature. That feature is now at part zero after G52. )
G52 X20 (select another offset from part zero for the second identical feature)
G52 X0Y0 (Turn off the G52 offset so things are back to “normal”)
I’ll bet you can see where G52 would come in handy right away, right?
G10 is a handy g-code that lets you program the G54 style work offsets from within your g-code. The typical syntax would be:
G10 L2 Poo Xxx Yyy Zzz
Where “oo” is the work offset number, “xx” is the X offset, “yy” is the Y offset, and “zz” is the Z offset.
If you have an older control that doesn’t have very many work offsets, you can use G10 to reuse the available work offsets with different coordinates.
Work Offsets and Macro Variables
On machines that allow parameterized programming, there are usually also macro variables that correspond to each coordinate of each work offset. On Fanuc, for example, the following variables are used for G54:
#5221 G54 X Offset
#5222 G54 Y Offset
#5223 G54 Z Offset
#5224 G54 Fourth Axis Offset
You can access these variables to see what the values are or to change them.
Stop Using Work Offsets Entirely With G53.
To stop using the work offsets, use G53. This forces the machine to use the machine zero coordinates with no offset whatsoever as part zero. This is not done very commonly, but it is possible to do so.
Work Offset Alternative: Relative Coordinates
Another way to avoid using a work offset is to use relative coordinates. The idea is to position the operation in absolute coordinates then switch to relative coordinates in the code that would’ve used an offset. You can learn more about relative coordinates in our chapter on g90 g code and g91 g code.
Now you know how to use Work Offsets, which make it easy to set up for making multiple parts or quickly accomodating multiple fixtures on your machines.
1. Set up GW Editor to use your controller’s work offset syntax.
2. Write a g-code program that uses multiple work offsets to create multiple identical parts. Set the values of the work offsets in G-Wizard Editor by changing the #variable values for the offsets so you can see all the parts on the backplot.
No credit card required–just your name and email.