G27 CNC Code | Reference Point Return Check

Mastering G27: The CNC Reference Point Return Check Command

In CNC machining, accuracy and repeatability depend on the machine’s ability to know its precise location within its coordinate system. The machine reference point (home position) serves as a fixed, known origin. While G28 and G30 are G-codes that command a return to the reference point, the G27 G-code performs a reference point return check. It verifies that the machine is at the expected reference position without commanding any movement. Understanding this distinction is critical for safe and accurate CNC programming.

This article explains:

  • The concept of the machine reference point.
  • The precise function of G27 (reference point check).
  • The critical difference between G27, G28, and G30.
  • Syntax and examples for Fanuc (and similar) controls.
  • Applications on lathes and mills.
  • Control-specific considerations (Fanuc, Siemens, Haas, Mazak, Mitsubishi).
  • Troubleshooting tips.
  • The role of CAM software.

Crucial Note: Always consult the programming manuals for your specific CNC control system and machine tool. While G27 is generally standardized in its checking function, the details of its implementation and the handling of reference points can vary.

1. The Machine Reference Point (Home Position)

Every CNC machine has a machine reference point, also known as machine zero or home position. This is a fixed, physical location within the machine’s travel limits, determined by the machine tool builder (MTB). It serves as the absolute origin of the machine coordinate system.

  • Machine Coordinate System: This is the coordinate system relative to the machine itself. All other coordinate systems (work offsets, etc.) are ultimately referenced to this.
  • Reference Point Setting: The reference point is usually established during the machine’s initial setup and calibration. It often involves limit switches or other sensors that detect when the axes are at their home positions.
  • Power Up: When you power on a CNC machine, it typically needs to be “homed” (moved to the reference point) to establish its position within the machine coordinate system.

2. G27: The Reference Point Return Check

The G27 command does not move the machine to the reference point. Instead, it checks whether the current position of the specified axes is within a defined tolerance of the stored reference point for those axes.

  • Check, Not Move: This is the key distinction. G27 is a verification command, not a motion command.
  • Tolerance: The control system has parameters that define the allowable tolerance for the reference point check. If the current position is within this tolerance, the program continues to the next block.
  • Alarm: If the current position is outside the tolerance, the control system generates an alarm (typically an “overtravel” or “reference point check error” alarm) and stops program execution.

Why Use G27?

  • Safety: To confirm that the machine is where the program expects it to be before starting a critical operation, especially after a manual jog or a tool change.
  • Accuracy: To ensure that any accumulated positioning errors (e.g., due to backlash or slight inaccuracies in rapid moves) are detected before they can affect the machining process.
  • Verification After Manual Intervention: If you’ve manually moved the machine (e.g., using the handwheel), G27 can be used to verify that you’ve returned it to the expected reference position before resuming automatic operation.
  • Verification after a tool change:

3. Syntax (Fanuc and Similar Controls)

The syntax for G27 on Fanuc and many compatible controls is:

G27 X... Y... Z... P... ;
  • G27: The reference point return check command.
  • X..., Y..., Z...: These are target positions to be checked against the stored reference point. They do not command a move to these positions. You typically specify the expected reference point coordinates (usually X0, Y0, Z0, or the equivalent in your machine’s coordinate system).
  • P…: Is an optional command.

Important: The X, Y, and Z values in the G27 block are not destinations. They are values to be compared with the machine’s current position.

Examples:

  • G27 X0 Z0; (Lathe): Checks if the X and Z axes are at their reference positions (typically X0 and Z0).
  • G27 X0 Y0 Z0; (Mill): Checks if the X, Y, and Z axes are at their reference positions (typically X0, Y0, and Z0).
  • G27 X0; : Checks only the X-axis position.
  • G27 Z0; (Lathe): Checks only the Z-axis position.

4. G28: Reference Point Return (Movement)

It’s essential to distinguish G27 from G28:

  • G28: Commands a movement to the machine reference point (home position). This is the command you use to send the machine home.

  • G28 Syntax:

G28 X... Y... Z... ;
  • X… Y… Z…: These values are intermediate points. The machine will move to the specified point first, then to home.
  • Commonly, G28 is used with G91 (incremental), such as:
    • G91 G28 Z0; This will home the Z axis.

Example (G28 - Return to Reference):

G28 X0 Z0 ; Return to reference point (home) through intermediate point X0 Z0 (Lathe)
G28 X0 Y0 Z0 ; Return to reference point (home) through intermediate point X0 Y0 Z0 (Mill)
G91 G28 Z0; Home the Z axis (incremental mode)

G28 moves the machine; G27 checks the machine’s current position.

5. G30: 2nd, 3rd, and 4th Reference Point Return

  • G30: Commands a movement to a secondary reference point. Many machines have multiple reference points (e.g., for tool changes, pallet changes, or different setup positions).

  • G30 Syntax:

G30 Pn X... Y... Z...;
    • Pn: Specifies which reference point to use (P2 = 2nd, P3 = 3rd, P4 = 4th). If P is omitted, it often defaults to the 2nd reference point.
    • X..., Y..., Z...: Optional intermediate point (like G28).

Example (G30 - Return to 2nd Reference Point):

G30 P2 X0 Y0 Z0 ; Return to the 2nd reference point through X0 Y0 Z0

6. Applications on CNC Lathes

You might use G27 on a lathe to:

  • Verify Position Before a Tool Change: After manually jogging the machine, use G27 X0 Z0 to ensure it’s back at the expected reference position before initiating an automatic tool change.
  • Check Position Before a Critical Operation: Before starting a precision machining operation (e.g., threading), use G27 to confirm that any accumulated errors haven’t shifted the machine’s position.
  • Before a Canned Cycle:

Example (Lathe - G27 Check Before Tool Change):

; ... (Previous operations) ...
; (Manual intervention - operator might have jogged the machine)
G27 X0 Z0 ; Check if X and Z are at the reference position
M05 ; Spindle Stop
M09; Coolant Off
M06 T0202 ; Tool change (if G27 check passed, proceed with tool change)
; ...

7. Applications on CNC Machining Centers (Mills)

Similar to lathes, you might use G27 on a mill to:

  • Verify Position Before a Tool Change: Especially important on machines without absolute encoders, where the machine might “lose” its position if power is interrupted.
  • Check Position Before a Critical Operation: Before starting a high-precision operation (e.g., a finishing pass), use G27 to confirm the machine’s position.
  • Pallet Change Verification:

Example (Mill - G27 Check Before Critical Operation):

; ... (Previous operations) ...
; (Manual intervention or potential for accumulated errors)
G27 X0 Y0 Z0 ; Check if X, Y, and Z are at the reference position
; ... (Critical operation - if G27 check passed, proceed) ...

8. Control-Specific Variations

  • Fanuc: G27 for reference point return check is standard on many Fanuc controls. The syntax G27 X... Y... Z... is used.
  • Siemens: Siemens controls may use a different method for checking the reference position. It might not be a G-code; it could be a function within a cycle or a specific machine data setting. Consult the Siemens documentation. G74 is often used for referencing axes.
  • Haas: Haas controls may use G27 in a similar way to Fanuc, but always check the manual.
  • Mazak: Consult documentation.
  • Mitsubishi: Consult documentation.
  • Other Controls: Always consult your documentation.

9. Troubleshooting

  • G27 Alarm: This indicates that the machine is not at the expected reference position (within the defined tolerance).
    • Check for Obstructions: Make sure nothing is physically blocking the machine’s movement.
    • Verify Reference Point Setting: Ensure the reference point itself is correctly defined (usually through parameters).
    • Check for Mechanical Issues: Loose couplings, worn ballscrews, or other mechanical problems can cause positioning errors.
    • Encoder Problems: Faulty encoders can lead to incorrect position feedback.
  • Unexpected Machine Behavior Ensure you are not confusing G27 with G28.

10. CAM Software

CAM software typically does not use G27 directly. CAM systems rely on the machine’s known reference point (established during homing) and generate toolpaths relative to work offsets. The reference point return check, if needed, would usually be handled manually by the operator or through a separate setup routine, not within the CAM-generated part program.

11. Frequently Asked Questions (FAQ)

  • Q: What’s the difference between G27 and G28?
    • A: G27 checks if the machine is at the reference point. G28 moves the machine to the reference point (often through an intermediate point).
  • Q: Do I need to use G27 in every program?
    • A: No. It’s a verification tool, used strategically when you need to be absolutely certain of the machine’s position.
  • Q: Can I use G27 to move the machine?
    • A: No. G27 does not command any movement.
  • Q: Does G27 use work offsets?
    • A: No. G27 is in reference to machine coordinates.

12. Conclusion

The G27 G-code is a reference point return check command, used to verify that the machine is at its expected home position (or a defined reference position) without commanding any movement. It’s distinct from G28 (return to reference) and G30(return to 2nd/3rd/4th reference). While its implementation is generally consistent across controls that support it, the details (especially regarding parameter settings for the tolerance) can vary. Always consult your machine’s documentation, and use G27 strategically to enhance safety and accuracy in your CNC machining operations.