Example program · Mill
Setting a Work Offset Automatically with a Probe (G31) — G-Code Example
Simple probing routine that touches the top of the part with G31 and writes the result into G54 Z with G10.
Simple probing routine that touches the top of the part with G31 and writes the result into G54 Z with G10.
| Item | Value |
|---|---|
| Machine | CNC mill / machining centre (Fanuc-style) |
| Units | Metric (G21) |
| Lines | 16 |
Program
O1016 (PROBE Z TOP -> G54)
G21 G17 G40 G49 G80 G90
T20 M06 (TOUCH PROBE)
G54 G00 X20. Y20.
G43 H20 Z10.
(PROBE ON - MACHINE SPECIFIC M-CODE)
G91 G31 Z-25. F150.
G90
#100 = #5063 (SKIP POSITION Z, WORK COORDS)
IF [#100 LT -14.9] GOTO 99 (REACHED END = NO TOUCH)
#101 = #5223 + #100 (NEW G54 Z = OLD + TOUCH)
G10 L2 P1 Z#101
G91 G00 Z10.
G90
M30
N99 #3000 = 1 (NO CONTACT)▶ Simulate in the G-code viewer
How it works
- #5063 holds the skip position; #5223 is the G54 Z offset on Fanuc.
- Probe-on commands and variable numbers vary — check your probe manual.
- Real-world probing uses protected positioning (e.g. Renishaw O9810).
Codes used in this program
- G31 — Skip Function (Probing Move)
- G10 — Programmable Data Input (Set Offsets)
- G65 — Macro Call (Non-Modal)
Always check feeds, speeds, offsets and clearances for your own machine and tooling, and prove new programs with single block and reduced rapid.
More milling programs
- Face Milling Program (Zig-Zag Passes)
- Outside Contour with Cutter Compensation (G41)
- Circular Pocket with Helical Entry
- Bolt Hole Circle with Polar Coordinates (G16)
- Peck Drilling a Hole Grid (G83)
- Rigid Tapping Program (M8 × 1.25)
- Internal Thread Milling M12 × 1.75
- Rectangular Pocket in Depth Passes Using a Subprogram
- Machining Multiple Parts with G54–G57
- Counterbore Holes for M6 Socket Head Screws
- Fine Boring a Precision Bore (G76 on a Mill)
- Milling a Slot with Ramping Entry
- Chamfering an Outside Edge with a Chamfer Mill
- Parametric Bolt Circle Macro (WHILE Loop)
- Spindle Warm-Up Program
- GRBL Router: Rectangle Cut-Out in Depth Passes
- GRBL / LinuxCNC Touch Plate Z Probe (G38.2)
- Haas G12 / G13 Circular Pocket in One Line
- Haas M97 Local Subprogram for Repeated Features
- High-Speed Peck Drilling in Aluminum (G73)
- Helical Boring a Ø20 Hole with a 10 mm End Mill