G28 and G30: Return to Reference Position
G28 rapids the machine to its home (reference) position, by way of an intermediate point. G30 does the same for a second reference position, often used for tool changes.
G28 sends the machine to its reference position, usually machine home, at rapid speed. G30 does the same for a second reference position set in the control, often a convenient spot for a tool change or for loading parts.
Both are non-modal: they only act on the line where they appear.
The intermediate point
The axis words on a G28 or G30 line are not the destination. They are an intermediate point the machine rapids to first, before it continues to the reference position. Only the axes you name move.
That is why the classic line is:
G28 G91 Z0
In incremental mode (G91), Z0 means "move Z by zero", so the intermediate point is where the tool already is, and Z goes straight up to home. Compare it with the same line in absolute mode (G90):
G28 Z0
Now Z0 is the work Z zero, often the top of the part. The machine rapids down to Z0 first, then goes home. On a part with clamps or a tall feature, that can be a crash.
After G28 G91 Z0, put the machine back in absolute mode with G90 before any more moves.
A typical program ending
G0 Z25
M5
G28 G91 Z0
G28 G91 X0 Y0
G90
M30
The tool raises to home first, on its own, then X and Y move. Moving all three axes together is shorter but can drag the tool across the part.
G30 for tool changes
Many machines use G30 to send the spindle to a tool change position that's lower or more convenient than home. Fanuc controls support up to four reference positions: G30 P2 Z0 uses the second (the default), and P3 and P4 select the others. Their locations are set in the control's parameters, not in the program.
Machine differences
- Fanuc and Haas: G28 goes to machine zero through the intermediate point. Haas programs commonly use
G28 G91 Z0and alsoG53 G0 Z0(see G53 machine coordinates). - GRBL: G28 and G30 go to positions stored with G28.1 and G30.1, which save the current machine position. If none has been stored, G28 goes to machine zero. Homing must be enabled for the positions to mean anything.
- LinuxCNC: G28 and G30 go to positions stored in parameters, also set with G28.1 and G30.1.
- Mach3: G28 goes to the G28 home location set in its configuration. G28.1 homes the axes, which is different from GRBL and LinuxCNC.
How CutViewer shows G28 and G30
CutViewer doesn't know where your machine's reference positions are, so it doesn't draw G28 or G30 moves, and it doesn't treat the axis words on those lines as a move. The tool stays where it was until the next normal move.
Frequently Asked Questions
Why do programs use G28 G91 Z0 instead of G28 Z0?
The axis words on a G28 line are an intermediate point the machine moves to first. In absolute mode (G90), G28 Z0 means rapid to Z0 in work coordinates, often the top of the part, and only then go home. In incremental mode (G91), Z0 means "no movement", so the machine goes straight up to home.
Does G28 move all axes?
Only the axes named on the line. G28 G91 Z0 moves only Z. G28 G91 X0 Y0 then moves X and Y. Raising Z first, on its own line, keeps the tool clear of the part and clamps.
What is the difference between G28 and G30?
G28 goes to the first reference position, normally machine home. G30 goes to a second reference position set in the control's parameters, often a tool change or load position. Fanuc controls can have up to four, selected with G30 P2, P3 or P4.
What do G28.1 and G30.1 do?
In GRBL and LinuxCNC, G28.1 and G30.1 store the machine's current position as the G28 or G30 position. In Mach3, G28.1 homes the axes instead. Check your control's manual before using them.
More G-Code Guides
Rapid positioning and straight cutting moves.
Clockwise and counter-clockwise arcs with I/J/K or R.
Pause for a set time, in seconds or milliseconds.
Choose the XY, XZ or YZ plane for arcs.
Inch or millimetre units for the program.
Cutter radius compensation, left, right and off.
Tool length offset on and off.
Work coordinate systems and machine coordinates.
Drilling canned cycles, from plain drilling to peck drilling.
Tapping cycle, and how to work out the feed rate.
Absolute positions or incremental distances.
Set the current position by shifting coordinates.
Feed per minute, per revolution, or inverse time.
Constant surface speed or a fixed spindle RPM.
Where a drilling cycle retracts between holes.
Spindle, coolant, tool change, stop and subprogram codes.
Check your own program before you cut: open it in CutViewer to see the toolpath in 3D, the run time and any problems.
Open CutViewer