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.

By cnccode · Updated

Simple probing routine that touches the top of the part with G31 and writes the result into G54 Z with G10.

ItemValue
MachineCNC mill / machining centre (Fanuc-style)
UnitsMetric (G21)
Lines16

Program

G-code
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

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