G29 CNC Code | Movement from reference position

Mastering G29: Return From Intermediate Point in CNC Programming

The G29 G-code in CNC programming is often misunderstood. It is not a command to directly return to the machine’s home position (that’s G28). Instead, G29 is used in conjunction with G28 to move the tool from a previously defined intermediate point to a specified destination within your part program. Understanding this relationship between G28 and G29, and the impact of absolute (G90) and incremental (G91) modes, is crucial for using these commands correctly.

This article clarifies the function of G29, explains its interaction with G28, and provides practical examples for its use on CNC lathes and machining centers (mills).

Crucial Note: Before using any G-code, always consult the programming manuals for your specific CNC control system and machine tool. While G28 and G29 are generally standardized in their concept, there might be subtle variations in implementation.

1. Understanding G28 (Return to Reference) and the Intermediate Point

To understand G29, you must first understand G28 (Return to Reference Point). G28 does two things, and its behavior is critically dependent on whether the machine is in absolute (G90) or incremental (G91) mode:

  • G91 (Incremental Mode) + G28: This is the standard and safest way to use G28. G91 G28 X0 Y0 Z0 (or G91 G28 U0 W0 on a lathe) commands a direct return to the machine reference point (home position) for the specified axes. The X0 Y0 Z0 (or U0 W0) values are incremental distances of zero, meaning “move to the reference point along this axis.” There is no intermediate point in this case.
  • G90 (Absolute Mode) + G28: In absolute mode, any axis words (X, Y, Z, etc.) specified with G28 are interpreted as an intermediate point in the current work coordinate system (e.g., G54). The machine will move to this intermediate point first, and then continue to the machine reference point.
    • Example (G90 G28 - Mill): G90 G28 X10.0 Y20.0 Z5.0; This command will first move the tool to the position X=10.0, Y=20.0, Z=5.0 (relative to the active work offset), and then it will move the tool to the machine reference point (home).
    • Warning: Using G28 with G90 and specifying an intermediate point can be dangerous if the intermediate point is not carefully chosen. The machine will make a rapid move to that point before going home, potentially causing a collision.

2. G29: Return From the G28 Intermediate Point

The G29 command is always used after a G28 command that defined an intermediate point (i.e., a G28 command used in G90 mode with specified axis values).

  • G29 Function: G29 commands a move from the G28 intermediate point to a new position specified within the G29 block.
  • It does not use or interact with machine home in any way.

Key Concepts:

  • G28 (in G90 mode) sets the stage: The G28 X... Y... Z... command (in G90 mode) defines the intermediate point. The machine moves to this point and then to the machine reference point. However, the control remembers the intermediate point.
  • G29 completes the sequence: The G29 X... Y... Z... command moves the tool from the G28 intermediate point to the coordinates specified in the G29 block.
  • G90/G91 Affect G29: The X, Y, Z (or U, W) values in the G29 block are interpreted according to the active coordinate system mode (G90 or G91):
    • G90 (Absolute): The G29 coordinates are the absolute destination point in the active work coordinate system.
    • G91 (Incremental): The G29 coordinates are incremental distances from the G28 intermediate point.
  • G29 without a preceding G28: If a G29 command is used without first using G28, the result will vary depending on the machine.

3. Syntax (Fanuc and Similar Controls)

The general syntax for G29 is:

G29 X... Y... Z... A... B... C... ;

  • G29: The command to return from the G28 intermediate point.
  • X..., Y..., Z..., A..., B..., C...: The coordinates of the destination point. These are interpreted in the active work coordinate system (G54-G59, etc.) and according to the active G90/G91 mode.

4. Applications and Examples (Lathes and Mills)

The primary use of G28 with an intermediate point, followed by G29, is to move the tool to a safe position (the intermediate point) and then to a specific location for the next operation.

Example 1: Lathe - Safe Retract and Approach

O0001 (Lathe G28/G29 Example)
G21 G18 G40 G99 ; Metric, XZ plane, cancel comp, feed/rev
T0101 ; Select tool 1, offset 1
G97 S1000 M03 ; Spindle on

; --- Rough Turning ---
G00 X50.0 Z5.0 ; Rapid to near workpiece
; ... (Rough turning operations) ...

; --- Safe Retract and Approach for Finish Tool ---
G90 ; Absolute mode  <-- IMPORTANT
G28 X60.0 Z20.0 ; Move to intermediate point (X60, Z20) THEN to reference
                ; (Safe position above and away from part)
T0202 ; Change to finish tool
G29 X40.0 Z2.0 ; Move *from* the G28 intermediate point *to* the
                ; starting point for the finish pass (X40, Z2)
G96 S250 ; Constant Surface Speed
; ... (Finish turning operations) ...
G28 U0 W0; Home
M30;
%

Explanation:

  1. G90: We’re in absolute mode.
  2. G28 X60.0 Z20.0: The tool moves to a safe position above and away from the part (X60, Z20 in the current work offset) and then to the machine reference point. The safe position (X60, Z20) is the intermediate point.
  3. T0202: Tool change.
  4. G29 X40.0 Z2.0: The tool moves from the G28 intermediate point (X60, Z20) to the starting point for the finishing pass (X40, Z2).

Example 2: Mill - Safe Retract and Approach

O0002 (Mill G28/G29 Example)
G21 G17 G40 G49 G80 G90 ; Metric, XY plane, cancel comp, absolute
T01 M06 ; Tool change
G00 G54 X10.0 Y10.0 Z5.0 ; Rapid to near workpiece
; ... (Machining operations) ...

; --- Safe Retract and Approach for Next Operation ---
G90 ; Absolute mode
G28 X20.0 Y20.0 Z50.0 ; Move to intermediate point (X20, Y20, Z50) THEN to reference
                       ; (Safe position above part)
T02 M06 ; Tool change
G29 X-10.0 Y-10.0 Z5.0 ; Move *from* the G28 intermediate point *to* the
                       ; starting point for the next operation
; ... (Next machining operations) ...
M30;
%

Explanation:

  1. G90: Absolute mode.
  2. G28 X20.0 Y20.0 Z50.0: Move to a safe position above the part (X20, Y20, Z50 in the current work offset) and then to the reference point. This safe position is the intermediate point.
  3. T02 M06: Tool change.
  4. G29 X-10.0 Y-10.0 Z5.0: Move from the G28 intermediate point to the starting point for the next operation.

Example 3: Using G28 and G29 in G91

(Example: Incorrect usage of G28 and G29)
G0 X50 Y50 Z50;	Initial Position
G91 G28 X10 Y10 Z10; Move relative, then home.
; Tool is now at home position.
G29 X20 Y20 Z20; Move to a point relative to home position + (X10, Y10, Z10).
;The result will not be as intended, and will change based on machine.

5. Control-Specific Variations

  • Fanuc: G28 for reference return (with the G90/G91 distinction) and G29 for return from the intermediate point are standard.
  • Siemens: Siemens controls use G28 for reference point return. The behavior is similar to Fanuc. Refer to Siemens documentation for any equivalent of G29 functionality, which might involve different commands or coordinate transformations.
  • Haas: Haas controls use G28 in a similar way to Fanuc. G91 G28 is the recommended method for direct homing. Consult the Haas manual for any G29-like functionality.
  • Mazak: Refer to specific machine documentation.
  • Mitsubishi: Refer to specific machine documentation.
  • Other Controls: Always consult your documentation.

6. Troubleshooting

  • Unexpected Movements:
    • Confusing G28 and G29: The most common error. Understand that G28 (with G90) uses an intermediate point, while G91 G28 goes directly home. G29 moves from the G28 intermediate point.
    • Incorrect G90/G91 Mode: Using G28 in G90 mode without understanding the intermediate point concept, or using G29 without a preceding G28 with a defined intermediate point.
    • Incorrect Work Offset: The intermediate point in G90 G28 is relative to the active work offset.

7. CAM Software

CAM software typically handles reference point returns using G28 (usually with G91 for direct return). You usually don’t need to program G29 manually when using CAM. The CAM system will generate safe and efficient toolpaths, including appropriate retract and approach moves, based on your machine’s configuration and the defined work offsets. However, a skilled CAM programmer could potentially use G28 with an intermediate point and G29 in specific, well-defined circumstances if the post-processor is configured to support it and they understand the implications. This is an advanced technique.

8. Frequently Asked Questions (FAQ)

  • Q: What’s the difference between G28 and G29?
    • A: G28 (usually with G91) sends the machine to the reference point (home). G29 moves the machine from an intermediate point defined by a preceding G28 command (in G90 mode) to a specified destination.
  • Q: Can I use G29 without G28?
    • A: The behavior is unpredictable and control-specific. It might generate an alarm, or it might use some previously defined (and possibly outdated) intermediate point. Do not use G29 without a preceding G28 that defines an intermediate point.
  • Q: What’s the safest way to use G28?
    • A: G91 G28 Z0 (home Z first on a mill), then G91 G28 X0 Y0 (home X and Y). On a lathe, G91 G28 U0 W0.
  • Q: Can I use G28 with absolute coordinates (G90)?
    • A: Yes, but be extremely careful. Any axis words specified with G28 in G90 mode define an intermediate point in the current work coordinate system. Make sure this intermediate point is safe.
  • Q: Does G29 use the work offset (G54, etc.)? * A: Yes, it does.

9. Conclusion

The G29 G-code is used to move the tool from an intermediate point (defined by a preceding G28 command in absolute mode) to a specified destination point within your part program. It is not a direct return-to-home command. Understanding the crucial relationship between G28 (and its behavior in G90 vs. G91 mode) and G29 is essential for using these commands correctly and safely. Always consult your machine’s documentation, and for complex operations, use CAM software.