Skip to main content
CNC.wiki

G30 2nd / 3rd / 4th Reference Position Return: CNC G-Code Guide

Master G30 2nd/3rd/4th reference returns on Fanuc, Siemens, and Mitsubishi. Learn parameters, cancel offsets, analyze alarm codes, and prevent crash scenarios.

Hakan Gündoğdu
Hakan Gündoğdu

CNC CARE Co-founder

Commanding a G30 reference return in absolute mode with coordinates set to zero causes the tool turret or spindle assembly to plunge at maximum traverse rate directly into a table-mounted vise jaw, workpiece clamp, or revolving spindle chuck. This high-speed mechanical impact shatters the cutting tool, deforms the turret indexing mechanism, and generates an axis overload alarm code, leaving the operator with a completely ruined scrap part. To prevent this catastrophic crash, programmers must use incremental positioning to force the intermediate travel distance to equal zero, ensuring a direct and unobstructed path to the secondary zero position.

G30 Technical Summary

Technical SpecificationDetails
Command CodeG30
Modal Group / TypeGroup 00 (Non-modal / One-shot G-code)
Supported BrandsFanuc, Siemens, Mitsubishi
Critical ParametersFanuc No. 5007 (TC3/TC2), Siemens MD 34100 ($MA_REFP_SET_POS), Mitsubishi #2037 (G53ofs)
Main ConstraintRequires programming an intermediate waypoint coordinate. Active tool offsets must be cancelled prior to execution to prevent trajectory shifts.

Quick Read: G30 Key Facts

  • Retracting to G30 secondary reference positions is ideal for automated pallet changes and tool changes without returning all the way to primary machine zero.
  • You must program at least one axis coordinate in the G30 block; axes omitted from the block remain stationary and do not return.
  • Never execute G30 in absolute mode (G90) with zero coordinates, as this forces the tool to plunge into workpiece fixtures.
  • Cancel all active tool length and nose radius compensations (using G40 and G49 or Txx00) before triggering G30 to prevent axis coordinate shifts.
  • Verify path clearance with a first-article dry run "in the air" to account for the non-linear "hockey-stick" rapid path.
  • Remember that G30 is a non-modal (one-shot) command that must be explicitly written in every block it is executed.

Basic Concepts of G30

The G30 preparatory command functions as an automatic return to a pre-configured secondary reference position (such as P2, P3, or P4). In contrast to the G28 command which retracts axes to the primary machine zero, G30 moves the axes to alternative clearance coordinates. These secondary reference points are defined during machine setup to serve as safe, repeatable zones for automated operations like pallet changes on horizontal machining centers or tool turret indexing on multi-spindle machines.

The return motion is executed in two distinct phases: first, the control directs the programmed axes to travel at rapid traverse to a specified intermediate waypoint, and second, the axes automatically transition from that waypoint to the designated secondary reference position. Setting the intermediate point allows programmers to maneuver the tool around clamps, vise jaws, and raw material. However, this intermediate waypoint is often misunderstood, and errors in calculating its coordinates can lead to severe tool crashes.

Command Structure and Syntax

The structure of a G30 command requires the programmer to explicitly state the target axis coordinate addresses. The coordinates provided in the block represent the intermediate waypoint. The control calculates the path to this intermediate point based on the current active coordinate mode. Axes that are omitted from the block will not travel and remain stationary at their current position.

Additionally, the command uses a P address to designate which secondary reference position is targeted. If the machine only has a single secondary reference point, the P address can be omitted, and the control will assume the 2nd reference position (P2 or P1 depending on the system default). To ensure safety, it is highly recommended to program the intermediate point incrementally to minimize the distance traveled before home retraction.

; Fanuc & Mitsubishi Turning (Lathe System A)
G30 P2 U... W... ; (Incremental intermediate point)
G30 P2 X... Z... ; (Absolute intermediate point)

; Fanuc & Mitsubishi Milling (Machining Center)
G91 G30 P3 X... Y... Z... ; (Incremental reference return)
G90 G30 P4 X... Y... Z... ; (Absolute reference return)

; Siemens ISO Dialect Mode
G291 ; (Switch to ISO Dialect Mode)
G30 P2 X... Y... Z... ; (Return to 2nd reference point via intermediate coordinates)
G290 ; (Switch back to Siemens native mode)
BrandAddress / Syntax ParameterDescription
All BrandsX, Y, Z, U, V, WCoordinates of the intermediate waypoint. Linear axes move to this point before the home return.
All BrandsPReference position number selection. Specifies P2 for 2nd, P3 for 3rd, and P4 for 4th reference position.

Brand-Specific Applications

Fanuc

On Fanuc controls, the secondary reference return is integrated with tool change sequencing. The configuration uses Parameter 5007 to map P2, P3, or P4 to the automatic tool change position.

The command is written as G30 P2 U0 W0 for lathes to ensure an incremental return without physical movement at the intermediate stage. For machining centers, G91 G30 P3 X0 Y0 Z0 is used.

CategoryItem / CodeDetails / Values
ParametersParameter No. 5007 Bits 1 & 0 (TC3/TC2)Maps secondary reference position to tool changes. Binary states: 01 for 2nd reference, 10 for 3rd reference, 11 for 4th reference.
ParametersParameter No. 3401 Bits 7 & 6 (GSC/GSB)Selects G-code system A, B, or C.
ParametersParameter No. 5040 Bit 3 (TCT)Controls availability of tool length compensation plus/minus.
AlarmsAlarm PS0092Reference return LED / misposition alarm. Triggered if axes do not align precisely with secondary coordinates due to active offsets.
AlarmsAlarm PS0368Triggered if Parameter 5040 Bit 3 is modified while tool offsets remain active in registers.
VersionsSeries 15 FormatLegacy programming format is active when Parameter No. 0001 Bit 1 (FCV) is set to 1.

WARNING: Modifying Parameter 5040 Bit 3 (TCT) while offsets are applied will result in immediate Alarm PS0368 or incorrect subsequent tool length offsets.

Siemens

Siemens SINUMERIK controls handle G30 differently by executing it through an internal background cycle named cycle328.spf. Programmers must switch the parser using G291 to enable the ISO translation engine.

A typical command is block-enclosed, starting with G291, followed by G30 P3 X30.0 Y50.0, and ending with G290 to revert the system parser to native Siemens NC language.

CategoryItem / CodeDetails / Values
ParametersMD 34100 $_MA_REFP_SET_POS to [5]Axis-specific machine data defining coordinates of up to four machine reference positions.
ParametersMD 18800 $MN_MM_EXTERN_LANGUAGEOptions parameter. Must be set to 1 to enable the external ISO Dialect G-code translation engine.
ParametersMD 20154 $MC_EXTERN_GCODE_RESET_VALUES[n]Channel-specific machine data defining reset G-code groups in external language.
AlarmsAlarm 61004Geometry axis configuration incorrect. Triggered during background execution of cycle328.spf if axis order is invalid.
AlarmsAlarm 61800External CNC system missing. Triggered if MD 18800 is not active when G30 is commanded.
AlarmsAlarm 14800Programmed path velocity is zero or negative. Triggered if feedrate is unconfigured.
Versions840D sl vs. 802D slCompact 802D sl lacks advanced options like G50.2/G51.2 multi-edge turning control, but supports G30 reference return.

WARNING: Since Siemens cycle328.spf uses DISPLOF to freeze screen updates, operators cannot monitor axis travel coordinates in real-time during G30 execution.

Mitsubishi

Mitsubishi CNC systems process G30 as a native preparatory function within the NCK kernel. They support Tool Change Position Returns from G30.1 to G30.6.

The command is written as G30 P3 X100.0 Y50.0 Z0.0 for Machining Centers. Toggling to incremental mode via G91 G30 P4 Z150.0 prevents plunge crashes.

CategoryItem / CodeDetails / Values
Parameters#2037 G53ofsAxis-specific parameter containing the coordinate offset of the 1st through 4th reference positions.
Parameters#1091 Ignore middle pointSetting to 1 bypasses the programmed intermediate waypoint, forcing a direct path to the reference position.
Parameters#1279 ext15/bit6Enables single-block stop at intermediate waypoint (1 to enable, 0 to bypass).
Parameters#8122 Keep G43 MDL M-REFEnables automatic reactivation of pre-referencing tool length offset when the axis moves again (1 to enable).
AlarmsOperation Error (M01 0013)Triggered if the operator switches mode to MDI or manual return during a single-block pause at the intermediate point.
AlarmsOperation Error (M01 0129)Triggered if a PLC interrupt operation is executed during the single-block pause at the intermediate point.
AlarmsProgram Error (P10)Triggered on M80/M830 controls when G30 commands are given to two or more rotary axes simultaneously.
AlarmsOperation Error (M01)Triggered if reference position parameters are changed during an active coordinate interlock pause.
VersionsM80 / M830Enforces rotary axis multi-command Program Error P10. Lathe systems support G30.1–G30.5; Milling support G30.1–G30.6.

WARNING: Standard tool length compensations are cleared at the end of G30. You must reactivate G43/G44 before approaching the workpiece to avoid a crash.

Brand Comparison

Comparison TopicFanucSiemensMitsubishi
Parser / Command TypeNative Group 00 unmodal preparatory command; must be explicitly written in every block it is executed.Handled via software-driven background cycle macro cycle328.spf when in ISO Dialect mode (G291). Rejected in native mode (G290).Native Group 00 unmodal preparatory function; directly processed in the NCK motion kernel.
Tool Change MappingParameter-based integration. Parameter 5007 Bits 1 & 0 configures TC3/TC2 to map P2/P3/P4 as automatic tool change position.Coordinates configured via machine data parameters 34100 $_MA_REFP_SET_POS to [5]. Geometry switchovers can be write-protected.Supports a native set of Tool Change Position Returns (G30.1 to G30.6), outputting a Tool Change Position Return Complete Signal (TCP) to the PLC.
Offset RetentionOffsets are cancelled upon home return.Offsets are cancelled upon reaching the secondary reference point.Offsets are cancelled, but unique parameter #8122 Keep G43 MDL M-REF can automatically reactivate pre-referencing tool length offset when the axis moves again.
Safety Interlocks at WaypointDoes not enforce hardware PLC interrupts during single-block stops at intermediate waypoint.Software-driven macro cycles manage intermediate states; does not enforce hardware-level PLC interrupts at waypoints.Enforces rigid safety interlocks: switching mode to MDI or executing a PLC interrupt during single-block waypoint stop throws operation errors (M01 0013 / 0129).

Technical Analysis

The architectural differences in how Fanuc, Siemens, and Mitsubishi handle G30 reflect their distinct control philosophies. Fanuc and Mitsubishi execute G30 directly in the NCK motion kernel as a low-level preparatory command. Because it is compiled at the system kernel level, execution is immediate and depends on physical coordinate offsets or hardware limit switches. In contrast, Siemens SINUMERIK delegates G30 to a background cycle macro, cycle328.spf. This software-driven approach allows Siemens to manage axis coordinates dynamically but introduces cycle-specific diagnostic errors like Alarm 61004 if the geometry axis configuration in the channel settings does not match the cycle sequence.

The mechanism for managing tool changes and PLC handshaking varies widely. Fanuc ties G30 directly to machine parameters (No. 5007), allowing bits to select which secondary position becomes the default tool change target. Mitsubishi goes a step further by implementing a dedicated group of Tool Change Position Return G-codes, G30.1 through G30.6 (or G30.5 on lathes). These codes instruct the controller to move axes in a specified, parameter-configured order (e.g., Z first, then X and Y) and natively output a Tool Change Position Return Complete Signal (TCP) to the PLC. Siemens, on the other hand, relies on its standard tool management options and machine data parameters (MD 34100) to lock or modify reference positions.

Compensation behavior post-referencing is another critical differentiator. While all three systems cancel tool length offsets upon reaching the reference point, Mitsubishi provides a unique parameter, #8122 Keep G43 MDL M-REF. When manual high-speed returns are executed with this parameter enabled, the control caches the active tool length offset and automatically reapplies it as soon as the axis initiates its next move. Fanuc and Siemens offer no such caching; any subsequent axis movement will proceed without offset compensation unless G43 or G44 is programmatically recalled.

Program Examples

Fanuc Example: Safe Retraction for Tool Change

G90 G00 X100.0 Z50.0 T0101 ; Rapid position tool under absolute coordinates
G40 G49 ; Cancel tool nose radius and tool length offsets
G91 G30 P2 X0 Y0 Z0 ; Incremental return to 2nd reference position via zero-distance waypoint
M06 ; Trigger tool change

Dry Run Analysis

During a dry run, the operator sets the machine coordinates in incremental mode. The control processes the G30 P2 block. Since coordinates are programmed incrementally as X0 Y0 Z0, the intermediate waypoint matches the current tool position. The turret immediately moves along a straight line directly to the secondary reference position configured in Parameter No. 5007. No displacement occurs, ensuring a safe clearance from the workpiece vise jaw.

Siemens Example: ISO Dialect Retraction

G291 ; Switch interpreter parser to ISO Dialect mode
G40 G49 ; Cancel active radius and length compensation
G30 P3 X30.0 Y50.0 Z100.0 ; Traverse to intermediate point and return to 3rd reference point
G290 ; Revert parser back to native Siemens mode
M06 ; Execute tool change

Dry Run Analysis

The interpreter switches to ISO Dialect mode via G291. When the G30 P3 block is executed, the SINUMERIK controller calls cycle328.spf. In the dry run, the axes travel to the absolute coordinates X30.0, Y50.0, Z100.0 at rapid traverse. Once the waypoint is reached, cycle328 deactivates transformations and moves the axes to the 3rd reference position defined in MD 34100 $_MA_REFP_SET_POS[2]. Offsets are canceled upon arrival, and the block display is suppressed.

Mitsubishi Example: Multi-Axis Milling Center Return

G90 G00 X50.0 Y50.0 Z20.0 G43 H02 ; Tool positioned with active length compensation
G40 G49 ; Cancel cutter compensation and tool length offset
G91 G30 P4 Z150.0 ; Incremental Z waypoint move of 150mm, then return to 4th reference position
M02 ; End of program

Dry Run Analysis

The control cancels all active tool offsets. The Z-axis is commanded to retract incrementally by 150mm. During the dry run, the Z-axis moves up 150mm from its current position to establish a safe vertical clearance. From this intermediate waypoint, the axes return at rapid traverse to the 4th reference coordinates defined in parameter #2037 G53ofs. Setting #1279 ext15/bit6 to 1 allows the operator to verify the intermediate position before retraction.

Error Analysis

BrandAlarm CodeTrigger ConditionOperator SymptomRoot Cause / Fix
FanucAlarm PS0092Physical axes do not align precisely with configured secondary reference coordinates.The zero-return arrival LED on the operator panel fails to illuminate, and the program halts.Active tool compensations or coordinate offsets were left active. Cancel offsets using G40/G49 before G30.
FanucAlarm PS0368Attempting to modify Parameter No. 5040 Bit 3 (TCT) while offsets are active.The control rejects parameter modification and throws a system error.Cancel active coordinate offsets and tool length compensation in the registers before editing parameters.
SiemensAlarm 61004Configured order of the channel geometry axes is incorrect during cycle execution.Background cycle cycle328.spf fails, and the NC stops automatic run with a cycle-level error.Check and correct the geometry axis configuration in the channel settings.
SiemensAlarm 61800Executing G30 without external ISO Dialect interpreter options activated.The parser fails to recognize the G30 code and halts program compilation.Enable MD 18800 $MN_MM_EXTERN_LANGUAGE (set to 1) or options bit 19800.
SiemensAlarm 14800Path feedrate velocity F is set to zero or remains unconfigured during G30 cycle.Program execution halts before executing the movement.Activate fixed feedrates or program a valid feedrate F value in the preceding blocks.
MitsubishiOperation Error M01 0013Switching control mode to MDI or manual reference return during waypoint pause.The control locks automatic operations, and the alarm displays on the screen.Do not change the active control mode during a single-block intermediate pause.
MitsubishiOperation Error M01 0129Executing a PLC interrupt operation while paused at the intermediate point.The machine cycle halts, and an operation error code is displayed.Avoid triggering PLC interrupts during an active single-block intermediate pause.
MitsubishiProgram Error P10Commanding G30 to two or more rotary axes simultaneously on M80/M830 controls.The control blocks axis movement and flags a program syntax error.Command G30 to only one rotary axis at a time. Linear axes must adjust independently.
MitsubishiOperation Error M01Altering 2nd, 3rd, or 4th reference position coordinates during active interlock pause.NC execution is arrested, preventing further motion.Do not modify reference position coordinates or parameters while the program is in a paused state.

Application Note

Deforming the turret indexing mechanism and shattering a solid carbide milling cutter occurs when the intermediate waypoint is programmed in absolute coordinate mode (G90) with coordinates set to zero. Under this condition, the NCK motion kernel evaluates the workpiece coordinate origin (such as G54 X0 Y0 Z0) as the intermediate point. The axis servomotors accelerate the spindle or turret assembly at maximum rapid traverse directly toward the part. If the raw material is secured in a table-mounted vise jaw, a workpiece clamp, or a revolving chuck, a catastrophic high-speed crash will result. To bypass this hazard, setup personnel must write the intermediate motion incrementally (G91 or lathe System A U0 W0), which sets the intermediate waypoint distance to zero and forces the control to traverse the tool directly from its current position to the secondary reference point.

Related Command Network

  • G28: Automatically returns axes to the primary reference position (machine zero) via a programmed intermediate waypoint.
  • G29: Commands the axes to return from a reference position back to the programmed coordinates via the last intermediate point.
  • G27: Verifies if programmed axes have arrived at the configured reference coordinates, throwing an alarm if positioning is incorrect.
  • G30.1 to G30.6: Triggers parameter-configured tool change position returns in a pre-defined multi-axis sequence.
  • G40 / G49: Cancels active cutter radius compensation and tool length offsets to prevent trajectory displacement during G30 moves.

Conclusion

Retracting tools to the G30 secondary reference position is a highly efficient method to execute automated tool and pallet changes safely. Programmers must ensure all active coordinate offsets are canceled using G40 and G49 before executing G30, and always command the intermediate waypoint incrementally. Confirming the path with a dry run and checking parameters like Fanuc 5007 or Mitsubishi #2037 prevents costly crashes with machine fixtures.

Frequently Asked Questions (FAQ)

What happens if I omit the P address in a G30 command?

Omitting the P address causes the CNC controller to default to the 2nd reference position return. To ensure the machine moves to the correct physical location, operators must verify that the coordinate values for the 2nd reference position are properly configured in machine parameters like Fanuc Parameter 5007 or Mitsubishi #2037.

Can G30 be executed while tool length compensation G43 is active?

No, executing G30 while G43 is active shifts the calculated intermediate waypoint by the offset value, causing the tool to travel along an offset path. Operators should program a G49 code in the block preceding G30 to cancel active tool length offsets before the axes retract.

How does Mitsubishi's Keep G43 MDL M-REF parameter benefit operators?

Parameter #8122 Keep G43 MDL M-REF automatically restores the active tool length offset as soon as the axis moves following a manual high-speed reference return. Operators can enable this parameter by setting #8122 to 1, eliminating the need to program manual offset recall blocks after referencing.

Still not resolved?

Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

Ask AI Assistant
Hakan Gündoğdu
Hakan Gündoğdu
  • CNC CARE Co-Founder (May 2025 - Present)
  • Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
  • Reis CNC Service Engineer (2003 - 2008)
  • Ören Kalıp CNC Mold Line Team Leader (1999 - 2002)

With over 25 years of experience working in all areas of the CNC machine industry, I continue my activities as a co-founder of CNC CARE, where we offer brand-independent consulting, engineering, and original spare parts services.

Related Articles

Other articles on this topic