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…
| Property | Value |
|---|---|
| Code | G38.2 |
| Function | Straight Probe Toward Workpiece (Stop on Contact, Error if Not) |
| Modal group | 01 |
| Type | One-shot (non-modal) — active only in its own block |
| Used on | Milling machines |
| Syntax | G38.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
G38.2 Z_ F_| Address | Meaning |
|---|---|
X Y Z | Target (beyond the expected contact) |
F | Probing feed |
G38.2 example program
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.
Related codes
- G38.3 — Straight Probe Toward Workpiece (No Error)
- G31 — Skip Function (Probing Move)
- G10 — Programmable Data Input (Set Offsets)