CNC Probing & Measurement Cycles: G31, G38, G65, G76 and On-Machine Inspection Explained
Modern CNC machining doesn’t stop at cutting — it measures, verifies, and corrects in real time.
Using probe cycles such as G31, G38, G65, and G76, machines can automatically locate work offsets, measure tools, inspect parts, and even adjust tool wear during production.
This guide explains real probe G-codes, macro logic, and examples from Fanuc, Haas, Siemens, and Heidenhain.
📌 1. What Is CNC Probing?
CNC probing refers to automated measurement and inspection performed by a touch probe installed in the spindle or on the table.
These probes detect surface contact and send an electrical signal to the control system.
Probing Applications:
- Workpiece setup (finding X/Y/Z zero)
- Tool length & diameter measurement
- In-process inspection (during machining)
- Broken tool detection
- Adaptive machining (auto offset correction)
📌 2. Main G-Codes for Probing
| G-Code | Function | Description |
|---|---|---|
| G31 | Skip function | Stops motion when probe triggers |
| G38.x | Probing move | Used in Haas, Mach3, LinuxCNC |
| G65 | Custom probing macros | Executes measurement subprograms |
| G76 | Tool measurement cycle (Fanuc/Siemens) | Automatically measures tool length |
| G37 | Tool length measurement (Haas) | Detects and updates H offset |
📌 3. Fanuc Example — Workpiece Edge Measurement
%
O8001 (FANUC EDGE PROBING)
G90 G17 G21 G40 G80 G54
T20 M06 (RENISHAW PROBE)
G31 X100. F100.
#100 = #5061 (STORE PROBED X)
G91 G01 X-5.
G31 X[#100-2.] F100.
#101 = #5061
#102 = [#100 + #101]/2
#5221 = #102 (SET G54 X ZERO)
M09
M30
%
This program probes a workpiece edge and sets the G54 X-zero automatically using system variables.
#5061stores the machine position where the probe triggered.
📌 4. Fanuc System Variables for Probing
| Variable | Description |
|---|---|
| #5061–#5063 | Last probed position (X/Y/Z) |
| #5221–#5243 | Work offset registers (G54–G59) |
| #3006 | Display message |
| #3000 | Alarm stop |
| #149 | Active tool number |
📌 5. Haas Example — G31 Skip and G37 Tool Length
%
O9001 (HAAS PROBING EXAMPLE)
T10 M06 (SPINDLE PROBE)
G31 Z-50. F100.
#100 = #5063
#3006 = 1 (PROBE TRIGGERED)
G37 H01 (MEASURE TOOL LENGTH)
M30
%
G31detects surface contact;G37measures and updates tool length automatically to offset register H01.
Haas Next-Gen Control also supports Renishaw Inspection Plus cycles (O9810–O9850).
📌 6. Haas G38.x Probing Commands
| Code | Function | Direction |
|---|---|---|
| G38.2 | Probe toward part (stop on contact) | Standard |
| G38.3 | Probe toward part (ignore contact) | Skip |
| G38.4 | Reverse probe (stop on loss) | Used for retract |
| G38.5 | Reverse probe (ignore loss) | Continuous scan |
Example:
G38.2 Z-25. F100
G38.4 Z5. F100
Moves down until probe contact, then retracts until contact is lost — common for surface calibration.
📌 7. Siemens Example — MEASURING and G76 Cycle
MEASURING ON
G76 T="PROBE" X100. Y0 Z-50. F200
MEASURING OFF
Siemens allows direct measurement command syntax and real-time probe feedback through the NCK.
| Command | Function |
|---|---|
MEASURING ON | Enables probe input |
MEASURING OFF | Disables probe |
G76 | Performs auto measurement (tool/work) |
RPARAM | Stores result to variable |
📌 8. Heidenhain Example — Cycle 401 & 402
CYCL DEF 401 PROBE X-PLUS
Q260=+50 ; START POSITION
Q261=+100 ; PROBING FEED
Q262=+1 ; MEASURING DIRECTION
Q310=+1 ; WRITE ZERO OFFSET
Heidenhain uses Cycle 401 (X/Y probing) and Cycle 402 (Z probing) for automatic part alignment and offset registration.
📌 9. Macro Example — Automatic Work Offset Update
#100 = #5061
#101 = #5221
#5221 = [#101 + (#100 - 50.0)]
#3006 = 1 (OFFSET UPDATED)
Adjusts the G54 X offset automatically based on the new probe position.
📌 10. Tool Measurement Cycle (Fanuc G76)
G76 P1 Q2 R10.
| Parameter | Meaning |
|---|---|
| P1 | Tool length measurement |
| Q2 | Measurement type (1=Single, 2=All tools) |
| R10. | Safe retract distance |
Used with laser or contact tool setters to measure tool offset automatically.
📌 11. Real Application — Broken Tool Detection
G65 P9814 Z-50. Q2. F200.
IF [#5063 GT -49.9] THEN #3000 = 5 (TOOL BROKEN)
Probes tool tip position and compares it with expected value — if too short, raises alarm.
📌 12. On-Machine Measurement for Quality Control
Modern probing cycles are used for:
- Part verification (dimensional checks)
- Datum alignment
- Tool wear compensation
- Adaptive machining (cut–measure–cut)
- Closed-loop control with CMM feedback
📌 13. Renishaw Inspection Plus Example (Fanuc)
G65 P9810 X0 Y0 Z-10. F200.
G65 P9811 X100. Y0 Z-10. F200.
G65 P9814 Z-50. F200.
Executes standard Renishaw cycles:
- P9810: Single surface probe
- P9811: 2-point edge find
- P9814: Bore or boss measurement
📌 14. Siemens Advanced Inspection — CYCLE977
CYCLE977(PROBE, "INSPECT", X=50, Y=0, Z=-20, F=100)
Measures a specific point and writes measurement result to the inspection log file.
📌 15. Macro Logic — Automated 3-Point Plane Measurement
#100 = 0
WHILE [#100 LT 3] DO1
G31 Z-50. F100.
#101[#100] = #5063
#100 = [#100 + 1]
G91 G00 X25.
END1
#500 = [#101[1] + #101[2] + #101[3]]/3
#3006 = 1 (PLANE Z LEVEL FOUND)
Samples 3 points on a surface and calculates the average plane Z level.
📌 16. Integration with MES / Quality Systems
Probing data can be exported via:
- MTConnect / OPC-UA
- Renishaw Reporter
- Siemens SINUMERIK Inspect
- Heidenhain QC Log
Enables full digital quality traceability and statistical process control (SPC).
📌 17. Smart Probing Trends (2025–2030)
- AI-driven auto calibration: Machine self-compensates for thermal drift.
- Laser touchless probes: Measure surface finish and geometry instantly.
- Closed-loop quality feedback: CNC corrects offsets live during machining.
- Edge computing inspection: Data processed in real time — no manual CMM needed.
- Hybrid metrology-CNC systems: Integrated 5-axis inspection without setup change.
✅ Conclusion
Probing is no longer just a setup tool — it’s the intelligent eye of the CNC machine.
By mastering G31, G38, G65, and G76 cycles, you enable fully automated setup, inspection, and correction, transforming your CNC into a self-verifying, self-adjusting manufacturing cell.
Leave a comment