Skip to content

G31: move that stops on a skip signal

G31 runs a linear move that cuts off the moment an external signal arrives, normally from a touch probe contacting the part, and stores the exact position where it stopped in macro variables. That position is the basis of all probing: measuring a face, finding the center of a hole, checking a dimension or correcting a work offset. If the signal never arrives, the move ends at the programmed position, and that is exactly the situation the program has to handle.

For reference only: syntax changes with the control, the post-processor and the machine parameters. Check the official manual and run a simulation before cutting. Legal notice.

The brands and control names mentioned belong to their owners and are used only to identify the equipment. GetGCode is not affiliated with or endorsed by any manufacturer, ISO or ASME: this is our own content, not official documentation. Legal notice.

Family
Probing
Machine
Milling, Turning, Mill-turn
Risk
High
Example
G31 Z-50 F100

Syntax by control

Fanuc (milling and turning)
G31 Z-50. F100
Linear move toward the commanded position that is cut off when the skip signal comes in. It is not modal: it only affects that block. Keep the feed low, because measuring accuracy depends on how fast the control can react.
Fanuc with multiple signals
G31 P1 Z-50. F100
Some controls accept several skip inputs selectable with P, to tell probes or different signals apart. Which ones exist depends on how the machine is wired.
Haas
G31 Z-50. F100 ; M78 / M79
Haas uses G31 with the same idea and adds M78 and M79 to generate an alarm depending on whether the signal was detected or not, which saves writing the check by hand in the macro.
Siemens 840D / 828D
MEAS=1 G1 Z-50 F100
Siemens measures with MEAS or MEAW inside a normal motion block, and the result ends up in system variables. It also offers its own measuring cycle packages that wrap all of this.
Heidenhain TNC
TCH PROBE 4 MEDICION 3D / cycles 400-431
Heidenhain handles probing with dedicated probe cycles, covering everything from measuring a face to automatic work offset correction. The low-level equivalent is the manual measuring cycle.

Address letters used with it

LetterWhat it setsUnit
X Y ZTarget position of the move. It is the point the axis would reach if the signal never appeared, so choose it so that the travel breaks nothing.mm / in
FProbing feedrate. The lower it is, the more accurate the measurement and the slower the cycle. Typical values run from tens to a few hundred mm/min depending on the probe.mm/min
PSelects the skip input on controls that accept several. It depends on the wiring done by the machine builder.integer
Position variablesThe control stores the position at the moment of the trigger in system macro variables. The number for each axis is given in the control's macro manual, and it is not the same on every control.numeric variable
Skip signalThe physical input that cuts off the move. It can come from a touch probe, a tool setter or another sensor connected by the machine builder.digital signal

Worked example

Measuring the actual height of the top face of a part with a touch probe, in order to correct the Z work offset afterward. The probing move goes down slowly and stops on contact; the position is stored and compared with the expected one. Variable numbers are written generically because they change between controls.

O0310 (MEDICION DE CARA SUPERIOR CON G31)
( Header of the measuring program. )
G21 G17 G40 G49 G80
( Safety block. It matters especially here: active cutter radius compensation would falsify the measured position. )
G91 G28 Z0.
( Z to the reference point before the change. )
T20 M06
( Loads the touch probe, which takes a magazine pocket like any other tool. )
G90 G54 G00 X50. Y50.
( Positions over the point to be measured, with Z up. )
G43 H20 Z50.
( Applies the probe length. Without this block the measurement means nothing. )
(NO ARRANCAR HUSILLO CON LA SONDA)
( Reminder: with the probe loaded you do not program M03. That mistake destroys the probe on the spot. )
G00 Z10.
( Rapid approach to a safe height above the face, with enough margin in case the stock is high. )
G31 Z-5. F200
( Probing move: goes down toward Z-5 and stops as soon as the probe touches. If it touched nothing it would reach Z-5, which is why that target is chosen so it does not break the probe. )
(la posicion del disparo queda en la variable de sistema del eje Z)
( The control has stored the exact contact position. From here on you work with that number. )
G00 Z50.
( Immediate retract after probing, before any calculation. )
(comparar la cota medida con la esperada)
( The difference between the measured and the theoretical value is the correction to apply. )
(si la diferencia excede el margen, generar alarma con un mensaje)
( A measurement out of range has to stop the program with a clear message, not blindly correct a work offset. )
(escribir la correccion en el corrector de origen con G10)
( G10 lets you update the work offset from the program itself, which is the usual way to close out a probing cycle. )
G91 G28 Z0.
( Z to the reference point. )
G90 M30
( End of program. )
Open the simulator to check the example

Practical keys to using G31 in the workshop

What exactly happens when the signal arrives

When the skip input turns on, the control cancels the rest of the move and brakes the axes, but the position it stores is not where the axes stop: it is the position at the instant of the trigger, worked out by the control to discount the braking distance. That is why the measurement can be reliable even though the probe overtravels a few tenths of a millimeter before stopping. Even so, accuracy depends on feed: the faster the move, the more uncertainty in the instant of the trigger. Hence the usual practice of a fast approach followed by a second, slow pass over the same point.

The dangerous case is when the signal never arrives

If the probe touches nothing, G31 does not throw an error: it simply finishes the move at the programmed position, and the program carries on with a variable holding that end point as if it were a real measurement. From there on, any work offset correction calculated from that number is garbage, and it can drive the next tool into the part. That is why all serious probing checks whether the trigger happened, by comparing the stored position with the programmed target or by using whatever functions the control offers for it, and stops the program with a message if something does not add up.

The probe is not a cutting tool

With the probe loaded you do not start the spindle, you do not aim high-pressure coolant at the stylus and you do not make rapid moves near the part. The probe also has its length and its ball radius in the tool table just like a cutter, and it has to be calibrated periodically against a known standard, because the ball radius and the runout go directly into the measurement. Probing that gives strange results is usually a calibration or temperature problem, not a program problem. And a broken probe costs as much as several tools.

Mistakes that cost you a part (or a tool)

  • Starting the spindle with the probe loaded: it destroys the probe on the first move and there is no way to recover it.
  • Not checking whether the signal actually happened: with no trigger, the variable holds the end position of the move and the program uses it as if it were a measurement.
  • Programming the G31 target beyond what the probe can safely travel, so a signal failure ends with the stylus driven into the part.
  • Probing at a high feed and expecting micron accuracy: the uncertainty of the trigger instant grows with speed.
  • Forgetting to apply the probe length with G43 before probing, which shifts the whole measurement.
  • Leaving cutter radius compensation or a canned cycle active during probing, which falsifies the recorded position.
  • Not recalibrating the probe after a crash or a stylus change, and carrying the error into every part measured.

Frequently asked questions

Where is the measured position stored?

In the control's macro system variables, one per axis. The specific numbers change between controls and generations, so look them up in your machine's user macro manual. Read those variables after the G31 and before the next one: on Fanuc they are only overwritten by another G31, not by any move.

What happens if the probe touches nothing?

The move runs all the way to the programmed position and the program carries on without warning. This is the most dangerous scenario, because the variable holds a number that looks like a measurement. That is why you always have to check the trigger, either by comparing the recorded position with the target or by using the alarm functions the control offers.

What feed do you probe at?

Slowly, and the usual way is in two stages: a first approach at a moderate feed to locate the surface and a second, very slow pass over the same point for the real measurement. The probe manufacturer gives recommended values, and they are worth respecting because they are tied to the stylus trigger force.

Can I use G31 without a touch probe?

Yes, as long as some signal is wired to the skip input. It is used with tool setters to measure tool length, with broken tool detectors and, on some setups, with the shop's own sensors. What does not change is the mechanics: a move that gets cut off by a signal and a position that gets recorded.

Is it better to use the manufacturer's probing cycles?

For everyday work, yes. The cycle packages from Renishaw, Blum or the control itself already handle the trigger check, the double pass, calibration and work offset correction, and they are proven. Raw G31 makes sense when you need something the cycle does not cover or when you want to understand what the cycle you already use does inside.

Related codes

M78/M79G10G65M43/M44G08/G09

Other codes in Probing

See the full list of G and M codes

Related apps