When it comes to the machining, safety should always be the top concern. Assuring safety at all times involves taking good care of the CNC operator, the workpiece, the machine, and any tooling or fixtures.
That is why it is important to pay close attention and fully understand how the G28 command works.
What does a G28 code do?
The G28 command tells the CNC machine to rapid move to a chosen reference point and then rapid move to the machines zero position in one or more axes.
This command is useful when you want to do a tool change or similar function during a program and want to avoid things that might be in the way of a direct rapid move to the zero position.
Using the G28 code can allow you to move your cutter to a safe position and then directly from the safe position to the machine zero position. This lets you make sure you don’t run into the part or any tooling or fixtures in the machine when returning to the zero position.
Because the G28 command is used for safety purposes, you will find it in many CNC programs.
Learn CNC Programming – It’s Easier Than You Think!
Learning G Code doesn’t have to be difficult…
If you know what to focus on.
Join our simple, easy-to-follow course, “G Code Made Easy: CNC Programming for Beginners“. We walk you through all the important codes – with simple explanations and real-world examples.
Want to become a super-skilled CNC programmer? Join now to take the shortcut to becoming a G Code Master today!Make Learning G Code Easy
When to use a G28 code?
G28 codes get used when you want to send the machine to a known position. This is often a “safe” position which means the machine is clear of any parts or tooling and is out of the way of any machine functions such as a tool or pallet change.
You will find G28 codes near the end of a section of code. This is because the code is used to prepare the machine for the next section of code.
What to think about when using a G28 code
The main things to think about when using the G28 are picking the right point to travel to that creates a safe straight line to the zero position and how many of the axes you are going to return to the zero position.
When you pick the point, you want to make sure that it doesn’t add too much extra travel because that will add extra time to machine each part.
With that in mind, the best way to avoid collisions is to move the Z-axis first. You will want to move the cutter up and away from the workpiece. This is why you will often see a G28 code that only sends the Z axis to the zero position.
All axes that are used with the G28 code will be sent to the machine zero position.
In most CNC programs, when using a G28 command you will also use a G91 code on the same line.
The G91 code sets the machine to incremental positioning. This means the machine will take each new location value as distances from the machine’s current location.
The other type of positioning is absolute positioning which bases locations off the workpiece zero. The workpiece zero is usually the center or a corner of the part.
Both positioning modes are modal which means they will stay in effect until switched.
If you use G28 without also using G91, it is possible that your CNC is in absolute positioning mode. This could cause a crash if you aren’t careful.
It is easier to move incrementally when you want to retract the cutter.
A simple code can be used to move the cutter two inches up in the Z axis and know that you are safe to travel to the zero position.
If you are in absolute positioning mode, you would need to calculate the XYZ location of the move. Moving incrementally makes the move as simple as a Z move only.
The main portion of a CNC program is often written in absolute positioning mode. This is why it is important to switch to incremental mode and also to switch back to absolute mode once you are done moving incrementally.
Is G28 a modal command?
No, G28 is not modal. Modal commands stay in effect until changed, such as a G20 (inches) or G21 (mm) code.
G28 only affects the line it is on. It is a very simple canned cycle with two steps.
Step one = move to the intermediate position.
Step two = move to the machine zero position.
Common modal commands
Circular Interpolation, Clockwise
Circular Interpolation, Counter-Clockwise
Cutter Compensation, Left
Cutter Compensation, Right
Tool Length Compensation
Various Canned Cycles
Hole Drilling, Reaming, Boring, etc.
G28 vs G53
The G53 code is a very similar command to G28.
Remember that we talked about the two positioning modes, absolute and incremental positioning. The G53 command sets a different type of positioning mode. G53 sets the positioning mode as relative to the machine’s coordinates.
This means the X0Y0Z0 location will be the machine’s zero return position. This also makes it easy to locate a secondary tool changer or a safe location for a pallet change.
One key difference when compared to the other positioning modes is that the G53 code is not modal. This means the machine will move relative to the machine coordinates but only for the line in which the G53 code appears.
G53 is a very handy code and often is safer than using a G28, but not all machines will accept a G53 code. G28 can be used on just about any CNC machine.
When figuring out whether you should use a G28 or G53 code, the best thing is to do is be consistent so that no one gets confused. It will be better for everyone involved, including operators, programmers, and setup personnel, if they only have to remember to use one code.
Keep it simple and if all your machines don’t accept G53 then stick with using G28 for consistency.
G28 vs G28.1
The G28.1 command sets the location that the machine will go to when the G28 command is used.
The location set by the G28.1 code will be used instead of the machine zero position when a G28 command is used.
G28 codes examples with descriptions of what they do
G28 X0 Y0 Z0
This line of code returns all 3 axes (X, Y and Z) of the CNC machine to the zero reference position. This point is often called the home position.
If the positioning mode is set to incremental (G91), the machine will go straight to the zero return position.
If the positioning mode is set to absolute (G90), the machine will go to the work offset (G54) zero location. This could often result in a machine crash.
G28 U0 W0
This line of code is often used for CNC lathes. U0 & W0 are incremental moves in the X and Z axis. Because these incremental moves are zero, the machine will move directly to the machine zero position.
G28 G91 Z0
This line of code sets the positioning mode as incremental with the G91 command. The Z0 means that the machine will move 0 units in the Z axis which means it won’t move and then the machine will return to the zero position.
G28 G91 X0 Y0 Z35.0
This line of code is very similar to the one above with the exception that the Z axis will move 35 units in the positive Z axis and then return to the zero position.
CNC codes that are similar to G28
There are different ways to return to the reference point and as explained before, G28 and G53 are very similar codes that allow users to achieve the same goal.
Both are safe retracts and home positioning commands that not only help protect the machine but also help protect the workpiece and/or any tooling that could be damaged.
The G28 code and other similar codes also have the benefit of making the program look clean and neat.
This is very important because a clear and easily read piece of code helps anyone who might be using the program.
Remember that it might be some time between before the program gets run again which gives you plenty of time to forget everything you knew about that specific program. This is also one of the reasons that it is recommended to include comments in your program so that it is easier to follow along and understand the code.