G54.APP

G-code deep dive

G38.2 & G31 Probing Moves: Touch Probes in G-code

G38.2G38.3G38.4G38.5G31M115M116M125M126

A probing move is a feed move with an exit condition: advance until the probe input trips, remember exactly where that happened, stop. It's how machines find part corners, bore centers, surface heights, and tool lengths — the bridge between where the part actually is and where the work offsets say it is.

This is also the least portable corner of G-code. Three unrelated spellings exist for the same operation:

; Find the top of the part and set G54 Z0 there (LinuxCNC/GRBL dialect)
G91                  ; incremental — probe moves are usually relative
G38.2 Z-25 F100      ; feed down max 25mm until the probe trips
G0 Z2                ; back off the surface
G38.2 Z-5 F25        ; second touch, slower, for repeatability
G90                  ; absolute again
G10 L20 P1 Z0        ; "current (tripped) position is G54 Z0"
G0 Z10

The two-touch pattern — fast find, slow confirm — is standard because trip accuracy scales with approach speed. The result lands in parameters (#5061+ on LinuxCNC/FANUC; GRBL reports a PRB: message), and the G10 L20 line is what turns a measurement into a usable work offset.

Error or no error: choosing the variant

G38.2 alarms if it travels the full distance without contact. That's a feature: "part not found" should stop a program, not let it cut air — or worse, cut where the part isn't. G38.3 (no error) exists for search patterns that legitimately expect misses. The away-variants G38.4/.5 release from a surface — used to find the back side of a trip point and in tool-setter routines. Centroid mirrors the same choices with L1 on its M-codes suppressing the error.

OperationLinuxCNCGRBLCentroidFANUCMach3Mach4Notes
Probe toward work, error if no contact G38.2 G38.2 M115 / M116 G31 G31 G31 FANUC syntax: G31 P1–P4 for multi-step skip. Centroid has NO G31/G38 — it probes with protected-move M-codes. Centroid: protected-move probing; M115 minus, M116 plus
Probe toward work, no error if no contact G38.3 G38.3 M115/M116 L1 Centroid: L1 suppresses the no-contact error
Probe away from surface G38.4 / G38.5 G38.4 / G38.5 M125 / M126 G38.4 errors if still in contact; G38.5 does not. Centroid: probe-away variants
Multiple probe inputs G31.1 / G31.2 / G31.3 Select among several probe inputs.
Move an axis until a switch trips M105 / M106 Feeds the named axis until a PLC switch/input opens (P > 0) or closes (P < 0). Centroid: M105 minus, M106 plus

— means the control has no equivalent code. Full cross-control tables: the complete G-code & M-code reference.

Common mistakes

Frequently asked questions

What does G38.2 do?

It feeds toward the target like a G1, but stops the instant the probe input trips and records the trip position. If the move completes without contact, the program stops with an error — the fail-safe you usually want, since no-contact means the part isn't where you thought.

What is the difference between G38.2 and G38.3 (and G38.4/G38.5)?

Two axes of variation: toward vs away, and error vs no-error. G38.2 probes toward the surface, erroring on no contact; G38.3 is the same without the error. G38.4/G38.5 probe away from a surface the probe is touching, stopping when contact breaks — .4 errors if contact remains, .5 doesn't.

Where does the probed position get stored?

LinuxCNC: parameters #5061–#5069 (probed position) and #5070 (success flag). GRBL: reported in the PRB status message. FANUC: skip position in #5061+ via the G31 skip function. Probing routines read these and write the result into a work offset with G10 L20.

Why doesn't G38.2 work on my Centroid machine?

Centroid CNC12 has no G31/G38 at all — probing is done with protected-move M-codes: M115/M116 (probe toward, minus/plus direction), M125/M126 (probe away), with L1 suppressing the no-contact error. Same concept, entirely different spelling; probing routines must be rewritten, not just re-posted.

See it, don't guess it

Paste a program into the free G54.APP viewer and watch these codes execute — toolpaths, stock removal, and machine state, live in your browser. Nothing is uploaded.

Open the G-code viewer