G29 G-Code: Return from Reference Position for CNC Machines
Understand G29 G-code syntax, parameters, and alarms for Fanuc, Siemens, and Mitsubishi. Learn safe tool return pathways from reference positions.
Introduction to G29 Return from Reference Position
When a CNC machine finishes a machining cycle and executes a reference position retraction using G28 or G30, the tool moves to its home position. Retracting the tool zero points clears the immediate cutting envelope, but returning directly to the next coordinate can lead to a catastrophic crash. If a programmer commands a direct rapid traverse back to the workpiece, the straight-line rapid travel path will often intersect with workholding equipment. The tool or turret can slam directly into a vise jaw, a workpiece chuck, or a physical clamp, resulting in a broken spindle, a bent turret, an immediate alarm shutdown, and a ruined scrap part. The G29 command (Return from Reference Position) prevents this hazard by instructing the machine to first rapid traverse to the exact intermediate point (waypoint) recorded during the retraction step, and then proceed along a safe, validated trajectory to the programmed target.
G29 Technical Summary
| Technical Specification | Details |
|---|---|
| Command Code | G29 |
| Modal Group | Group 00 (Non-modal / One-shot) |
| Supported Brands | Fanuc, Siemens (via G291 ISO Dialect mode), Mitsubishi |
| Critical Parameters | Parameter No. 1091 (Ignore middle point), Parameter No. 1279 ext15/bit6 (Enable single block stop at middle point) |
| Main Constraint | A prior reference return (G28 or G30) must be executed after power-on to record the intermediate waypoint in memory. |
Quick Read
- Perform a G28 or G30 cycle first to establish and record the intermediate waypoint in coordinate memory before calling G29.
- Switch off cutter radius (nose R) compensation during G28 retraction and G29 waypoint return to avoid calculation errors.
- Program G29 with target coordinates in a separate block from tool selection (T-codes) to prevent program errors.
- Avoid manual axis moves or coordinate shifts during single-block pauses at the intermediate waypoint to prevent offset trajectory collisions.
- Set Parameter No. 1091 to control whether the machine traverses through the recorded waypoint or takes a direct path to the reference position.
- Switch to ISO Dialect mode (G291) on Siemens SINUMERIK controls to run programs containing G29, as it is not natively supported.
Basic Concepts of G29
The G29 return command serves as an essential automatic safe-approach strategy on the shop floor. When a tool has finished its cutting cycle and has retracted to the machine zero reference position via a G28 or G30 command, it is typically at a distant, safe home position. If a programmer commands a direct rapid traverse back to the workpiece, the tool's straight-line path may collide with workholding equipment. By programming G29, the machine is instructed to first move at a rapid rate back to the exact intermediate point (waypoint) recorded during the retraction step, and then proceed to the programmed target. This intermediate point is strategically selected to clear obstacles such as a vise jaw, a workpiece chuck, or a physical clamp.
Utilizing G29 guarantees that the tool backtracks around these obstacles along a safe, validated trajectory. This sequence prevents a catastrophic hard collision where the tool or turret slams into the workholding, which would result in a broken spindle, a bent turret, an immediate alarm code shutdown, and a ruined scrap part. The waypoint coordinates are dynamically updated in the CNC memory each time a G28 or G30 command is successfully executed, making the safe path adaptive to the latest retraction coordinates.
G29 Command Structure and Parameters
The programming syntax for G29 is designed to specify the final target position after returning through the intermediate waypoint. The controller automatically retrieves the coordinates of the intermediate point from its registers, meaning the programmer only needs to input the final destination coordinates in the G29 block. Depending on whether the system is set to absolute or incremental mode, the coordinate values represent the absolute end position or the distance to be traversed from the intermediate point.
On lathe systems using Fanuc G-code System A, absolute or incremental movements are specified directly by the address letters (such as X/Z for absolute and U/W for incremental). On machining centers and milling systems, absolute or incremental modes are modal and must be active prior to executing G29. At least one axis coordinate must be programmed in the G29 block to execute the command.
; Lathe G-Code System A (Absolute) G29 X[X-coordinate] Z[Z-coordinate] ;; Lathe G-Code System A (Incremental) G29 U[U-distance] W[W-distance] ;
; Milling and Machining Centers (Absolute) G90 G29 X[X-coordinate] Y[Y-coordinate] Z[Z-coordinate] ;
; Milling and Machining Centers (Incremental) G91 G29 X[X-distance] Y[Y-distance] Z[Z-distance] ;
- Parameter No. 3401: Selects G-code System A, B, or C on Fanuc systems, determining coordinate address parsing.
- Parameter No. 3402: Controls the clear state of modal G-codes upon power-on or system reset, affecting active motion modes.
- Parameter No. 1091: Dictates whether the control ignores the programmed intermediate point during reference operations, forcing a direct path.
- Parameter No. 1279: Enables single block stop (pause) at the intermediate waypoint during single block execution on Mitsubishi and Fanuc controls.
- Parameter No. 8122: Determines whether tool length compensation applied before home return is reactivated upon axis movement after referencing.
Brand Applications
Fanuc
On Fanuc controls, G29 is a native, unmodal Group 00 preparatory function. The coordinate parser relies on Parameter No. 3401 to parse address letters under G-code System A, B, or C, while Parameter No. 3402 dictates the motion state at system reset.
The G-code is programmed as G29 X7.85 Z2.0 T0400 ; to return absolute axes via the recorded intermediate point.
- Parameters: Parameter No. 3401 (Bit 7 and 6) for G-code System selection; Parameter No. 3402 (Bit 6) for modal clear states; Parameter No. 1091 to ignore intermediate waypoint.
- Alarms: Alarm PS0187 when scaling or rotation is active; Alarm PS0010 for invalid G-code or option disabled; Program Error (P430) for no prior G28/G30; Program Error (P29) for T-code or workpiece offset mismatch in the same block.
- Versions: Lathe G-code Systems A, B, C selection; older controls limit sequence numbers to four digits (N4) compared to modern five/eight digits (N5/N8) for block searching.
Ensure that coordinate scaling (G51) or rotation (G68) are canceled before G29 execution to prevent machine alarms and potential crashes.
Siemens
Siemens SINUMERIK controls do not natively support or define G29 in either native Siemens mode (G290) or ISO Dialect Mode (G291). Zero point return sequences are typically managed via background macros like cycle328.spf.
To run G29 programs, the control must be toggled into ISO Dialect mode by executing the G291 command block, and then switched back to Siemens mode via G290.
- Parameters: G290/G291 mode toggle commands;
WALIMON/WALIMOF`working area limitation commands. - Alarms: — (no source)
- Versions: ISO Dialect mode (G291) allows interpreting Fanuc-style G-code structures, but the control bypasses G29 natively. Boundary check safety zones utilize text-based limits instead of binary check systems.
Do not attempt to execute G29 in native Siemens mode (G290) as it will be rejected by the control, resulting in an command execution halt.
Mitsubishi
Mitsubishi CNC systems process G29 as a native unmodal Group 00 command. Normal line control behaves according to Parameter No. 1086 while single-block waypoint pauses are governed by Parameter No. 1279.
An absolute machining center return is commanded as G29 X50.0 Y50.0 Z0 ; to position all three axes via the intermediate waypoint.
- Parameters: Parameter No. 1091 (#1091 Mpoint) to ignore the waypoint; Parameter No. 1279 (ext15/bit6) to enable single block stops at the waypoint; Parameter No. 1086 (#1086 G0Intp) for normal line control; Parameter No. 8122 (#8122 Keep G43 MDL M-REF) to reactivate tool length compensation.
- Alarms: Program Error (P430) when executed without a prior G28/G30; Program Error (P29) for T-codes in G29 blocks; Operation Error (M01 0013) for mode switching during a waypoint pause; Operation Error (M01 0129) for PLC interrupt during a waypoint pause.
- Versions: On Machining Center systems, Z-axis cancellation ignores physical movement to the intermediate point (display update only), whereas lathe systems process physical movement directly. M8 Series uses Parameter No. 8122 to control compensation reactivation.
Do not switch machine modes or trigger PLC interrupts while the machine is at a single-block stop at the intermediate position to avoid operation errors.
Brand Comparison
| Feature | Fanuc | Siemens | Mitsubishi |
|---|---|---|---|
| Native G29 Support | Yes, processed natively as unmodal Group 00 preparatory command. | No native support or definition in either Siemens mode (G290) or ISO Dialect mode (G291). | Yes, processed natively as unmodal Group 00 preparatory command. |
| Coordinate Syntax | Lathe System A uses absolute X/Z and incremental U/W. Milling & Systems B/C use G90/G91. | — (no source) | Lathe uses incremental U/W or absolute X/Z. Milling uses modal G90/G91. |
| Waypoint Tracking | Dynamically tracks intermediate coordinates of last active G28 or G30 block in active channel. | — (no source) | Positions axes to latest recorded G28 or G30 intermediate point. |
| Waypoint Ignore Parameter | Ignored via parameter No. 1091 (ignores programmed intermediate point and forces direct path). | — (no source) | Bypasses waypoint when parameter #1091 Mpoint is set to 1 (prevents updating waypoint memory). |
| Waypoint Single Block Stop | Can stop at intermediate point based on MTB parameters. | — (no source) | Performs single-block stop at intermediate point when #1279 ext15/bit6 is set to 1. |
| Safety Interlocks | Triggers standard program errors for T-code or workpiece compensation mismatches in G29 block. | Relies on text-based WALIMON/WALIMOF boundary limits for safety zone verification. | Enforces Operation Errors M01 0013 and M01 0129 for mode switches or PLC interrupts during waypoint pause. |
| Axis Cancellation | Processes axis coordinates directly on all systems. | — (no source) | On machining centers, if Z-axis is canceled, physical Z movement to intermediate point is ignored (display only). |
Technical Analysis
The core programmatic differences between Fanuc, Siemens, and Mitsubishi center on how they store and verify waypoint coordinates. Fanuc integrates G29 at the kernel level as a Group 00 unmodal instruction, which updates its registers automatically upon any G28 or G30 execution. Mitsubishi operates on a similar architectural logic but adds extra safety layers. For example, Mitsubishi systems feature Operation Errors M01 0013 and M01 0129, which act as interlocks to prevent operators from switching modes or executing PLC interrupts while the machine is paused at the intermediate point. Fanuc does not enforce these specific error codes at the control level, leaving it to machine tool builders to configure similar interlocks.
Siemens SINUMERIK departs from the Fanuc/Mitsubishi model by not natively supporting G29. Siemens controls run reference position returns through the cycle328.spf macro file and do not keep a dynamic return waypoint register in standard G-code modes. To run programs containing G29, a Siemens control must be toggled into ISO Dialect mode using G291. Siemens manages safety envelope checking via text-based WALIMON and WALIMOF commands, whereas Fanuc and Mitsubishi rely on G22 and G23 binary stroke checking limits.
Mitsubishi machining centers implement axis cancellation logic. If the Z-axis is canceled, the machine updates only the coordinate display and suppresses the physical slide motion to the intermediate point. Fanuc lathe and milling systems process the coordinates directly, causing physical axis movement. Finally, coordinate address parsing on Fanuc and Mitsubishi lathes allows for direct incremental positioning using U and W address letters under G-code System A, avoiding modal G90/G91 toggles that could trigger syntax errors on other controls.
Program Examples and Dry Runs
Fanuc G29 Program Example
N010 G28 U0 W0 ; Retract to reference zero, recording intermediate waypoint
N020 T0404 ; Select tool 4 and apply geometry offset
N030 G00 X100. Z50. ; Rapid traverse to starting position
N040 G01 X80. Z2. F0.25 ; Cutting operation
N050 G28 U0 W0 ; Retract to reference zero via intermediate waypoint (U0 W0)
N060 G29 U5.0 W2.0 ; Return from reference position incrementally to target
Dry Run Verification:
To perform a dry run for the Fanuc program, remove the cutting tool from the turret and enable the dry run switch on the operator panel. Set the Z-axis coordinate shift offset to a safe distance, such as +100mm, to keep the tool path clear of the chuck. Execute the program in single-block mode. Observe block N010 to verify the tool moves to the reference zero. Verify that block N050 retracts the tool safely, and block N060 returns the axis to the intermediate waypoint before moving to the offset end position. Visually check that the path does not intersect with the chuck or work clamps.
Siemens SINUMERIK G29 Program Example
N010 G291 ; Switch to ISO Dialect Mode to enable G28/G29 commands
N020 G28 X0 Y0 Z0 ; Retract to reference point, registering intermediate waypoint
N030 G29 X50.0 Y50.0 Z10.0 ; Return from reference position via intermediate point
N040 G290 ; Switch back to native Siemens mode for standard machining
N050 M30 ; Program end and reset
Dry Run Verification:
Before executing the Siemens ISO Dialect program, verify that the cycle328.spf macro is loaded in the control directory. Activate the dry run feedrate and set the feedrate override dial to 0%. Step through block N010 to confirm the switch to ISO Dialect mode. In block N020, verify that the axes retract to the machine home. In block N030, monitor the axis display and confirm that the tool returns to the recorded intermediate waypoint before moving to the target coordinates. Ensure the motion path remains clear of any vise jaws or work fixtures.
Mitsubishi G29 Program Example
N010 G28 X0 Z0 ; Retract X and Z axes to machine home, recording waypoint
N020 G29 X100.0 Z50.0 ; Return from reference position via intermediate waypoint
Dry Run Verification:
For the Mitsubishi program, set the dry run signal on the control panel to active. Step through block N010 in single-block mode and observe the axis retraction to the zero point. When executing block N020, verify that the axes first move rapidly to the intermediate waypoint. Confirm that the tool does not pause or throw an error. Watch the coordinate display and verify that the physical axes move to the target coordinates (100.0, 50.0) without coming close to the spindle chuck or chuck jaws.
Error Analysis
| Brand | Alarm Code | Trigger Condition | Operator Symptom | Root Cause / Fix |
|---|---|---|---|---|
| Fanuc | Alarm PS0187 | G29 is commanded while scaling (G51), coordinate system rotation (G68), or programmable mirror image (G51.1) is active. | The control halts execution immediately, displays the alarm message, and stops axis movement. | Active coordinate scaling or rotation interferes with return calculations. Cancel G51, G68, or G51.1 before executing G29. |
| Fanuc | Program Error (P430) | G29 is executed after power-on without first executing an automatic reference position return (G28 or G30). | The program stops, displaying a reference return error code. | The intermediate waypoint is not established in memory. Perform a G28 or G30 cycle first to record the coordinates. |
| Fanuc | Program Error (P29) | Tool select or wear offset command (T code) is issued in the G29 block. | The control halts and registers a format error. | Workpiece compensation values must remain uniform to calculate the return vector. Program T-codes in a separate block. |
| Mitsubishi | Operation Error (M01 0013) | Operator switches the machine mode to MDI or Reference Position Return while at a single-block stop at the intermediate position. | The CNC halts execution at the waypoint and triggers an operation alarm. | Mode switching is prohibited during the waypoint pause. Avoid changing modes until the G29 cycle is complete. |
| Mitsubishi | Operation Error (M01 0129) | PLC interrupt operation is executed while the CNC is at a single-block stop at the intermediate position. | Axis movement stops immediately at the intermediate waypoint with an operation error. | PLC interrupts are disabled during the waypoint pause. Do not trigger PLC interrupts while paused. |
Application Note
Turret collisions and bent spindles occur when rapid tool returns follow a straight diagonal path that intersects workpiece chucks, vise jaws, or raw stock. When a tool has finished cutting and retracted to the machine zero reference position, operators often command a direct rapid traverse back to the machining area. A direct G00 rapid path ignores physical obstacles in the workspace, causing the tool nose to drive straight into clamping fixtures. Utilizing G29 avoids this hazard by forcing the axes to backtrack through the exact waypoint coordinates stored during the previous G28 or G30 retraction cycle. This safety loop ensures the tool contours around the vise jaw or chuck before approaching the final target. However, manual coordinate shifts or manual axis movements during single-block pauses at the intermediate waypoint will corrupt the return registers. This corruption offsets the return trajectory, sending the tool turret into workholding equipment, causing immediate alarm shutdowns, broken tooling, and ruined scrap parts.
Related Command Network
- G28 (Automatic Return to Reference Position): The preparatory command used to retract the machine axes to the home position while establishing the intermediate waypoint stored for the G29 return cycle.
- G30 (Return to 2nd, 3rd, or 4th Reference Position): A command that retracts axes to secondary reference positions, similarly recording intermediate waypoint coordinates in the control memory.
- G27 Reference Position Return Check: A function used to check if the axes have successfully arrived at the reference position, utilizing the same background cycle macros as G28.
- G26 Upper Working Area Spindle Speed Limit: A command used to set upper bounds on spindle velocity or working area limits in Siemens controls to prevent over-travel.
- G26 Spindle Speed Fluctuation Detection On: A preparatory command that monitors spindle speed variations to maintain cutting stability prior to axis retraction.
Conclusion
Safe retraction and return sequences depend on maintaining a consistent coordinate relationship between the retraction waypoint and the final target. Programmers must ensure that G28 or G30 cycles are executed before G29 commands to load waypoint registers, and that offset compensations are carefully managed to avoid trajectory shifts. Implementing G29 with correct parameters protects machine spindles and workholding fixtures from rapid collisions.
Frequently Asked Questions
Can G29 be executed immediately after powering on the CNC machine?
No. Executing G29 immediately after power-on will result in a Program Error (P430) because the CNC memory has no recorded intermediate waypoint. Always program a G28 or G30 cycle first to establish the waypoint coordinates before calling G29.
Why does a G29 command block trigger a Program Error (P29)?
This error is triggered when a tool selection command (T-code) is programmed in the G29 block, or if workpiece compensation amounts differ between current and previous blocks. To resolve this, program all tool changes and offsets in separate blocks prior to executing the return command.
What happens if the Z-axis is canceled during a Mitsubishi G29 machining center sequence?
If the Z-axis is canceled on a Mitsubishi machining center, the physical Z-axis movement to the intermediate point is ignored, and only the position display is updated. Operators must verify their program path in dry run mode to ensure the tool does not collide with workholding when the Z-axis remains stationary.
Still not resolved?
Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

- 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
G71 Metric Dimensioning Guide for Siemens SINUMERIK Controls
Learn how to program G71 and G710 metric dimensioning on Siemens SINUMERIK controls, including parameter MD 10240, alarm codes, and G-code syntax errors.
G69 Balance Cut Cancel: Coordinate Recovery & Crash Prevention
Learn how to program the G69 balance cut cancel command for Fanuc, Siemens, and Mitsubishi turning centers. Cancel dual slide synchronization and prevent crashes.
G70 CNC Finishing Cycle Guide for Fanuc, Siemens, and Mitsubishi
Learn the G70 finishing cycle for CNC turning. Master syntax, parameters, and alarm codes for Fanuc, Siemens CYCLE95, and Mitsubishi controls to avoid crashes.
G69 Coordinate System Rotation Cancel: Modals, Alarms, and Setup
Learn to cancel G68 facing turret mirrors and coordinate rotations using G69 on Fanuc, Siemens, and Mitsubishi CNCs to prevent turret crashes.