G-code reference

G38.2 G-Code: Straight Probe Toward Workpiece (Stop on Contact, Error if Not)

Straight Probe Toward Workpiece (Stop on Contact, Error if Not) — GRBL and LinuxCNC probing move: travels toward the target until the probe input triggers, then stops and stores the position. If the probe does not trigger…

By cnccode · Updated
PropertyValue
CodeG38.2
FunctionStraight Probe Toward Workpiece (Stop on Contact, Error if Not)
Modal group01
TypeOne-shot (non-modal) — active only in its own block
Used onMilling machines
SyntaxG38.2 Z_ F_

What does G38.2 do?

GRBL and LinuxCNC probing move: travels toward the target until the probe input triggers, then stops and stores the position. If the probe does not trigger before reaching the target, an error stops the program. It is used with touch plates to set Z zero on routers.

G38.2 is a one-shot code: it only acts in the block where it is written, and the previously active modal codes take over again afterwards.

Syntax and parameters

Format
G38.2 Z_ F_
AddressMeaning
X Y ZTarget (beyond the expected contact)
FProbing feed

G38.2 example program

Example
G91 G38.2 Z-25 F80 (touch plate)
G10 L20 P1 Z15.0 (plate is 15 mm thick)
G0 Z5
G90

▶ Open this example in the G-code viewer

Tips and common mistakes

  • Test that the probe input works before every session — a dead probe crashes the bit into the plate.
  • G38.3 is the same but without the error.

Controller compatibility

G38.2 follows the ISO/Fanuc dialect used by Fanuc, Haas, Brother, Doosan, Hurco (ISO mode), Mazak (EIA/ISO mode), Okuma (G-code mode) and Siemens in ISO dialect mode. Parameters, option packages and builder-specific behaviour can differ, so confirm the details in your machine's programming manual before running a new program.

Frequently asked questions

Is G38.2 modal?
No. G38.2 is a one-shot (group 00) code and only acts in the block where it appears.
What does G38.2 mean in CNC?
G38.2 means Straight Probe Toward Workpiece (Stop on Contact, Error if Not). GRBL and LinuxCNC probing move: travels toward the target until the probe input triggers, then stops and stores the position. If the probe does not trigger before reaching the target, an error stops the program. It is…
What is the difference between G38.2 and G38.3?
G38.2 is Straight Probe Toward Workpiece (Stop on Contact, Error if Not), while G38.3 is Straight Probe Toward Workpiece (No Error). See the G38.3 page for its syntax and examples.
Can I use G38.2 on a lathe?
Usually not with the same meaning: G38.2 is documented here for milling machines. Check your control manual for the equivalent.