Printed from Kezuriba (kezuriba.net/en/nc/g31/)
G31
Machining center, LatheOne-shot, group 00Skip function (moves in a straight line until a signal comes in)
Format and notes
G31 X_ Y_ Z_ F_ (lathe: G31 X(U)_ Z(W)_ F_)
- Moves in a straight line like G01 until a signal, such as from a touch probe, comes in; when the signal arrives it stops on the spot, discards the rest of the move and goes on to the next line. Used to measure workpiece height and position, and for feeding until contact
- One-shot (group 00). Write it on every line where it is used
- The stopped position is stored in variables, so a macro can use the measured value in calculations. Variable numbers differ by model (Haas: #5061–#5066)
- Cancel tool radius compensation and tool nose radius compensation (G41, G42) before commanding it (the Siemens ISO dialect gives an alarm, Mitsubishi Electric a program error, and Haas states explicitly that they must not be used together)
- If the next line is an incremental command, it moves from the stopped position. If it is an absolute command, it moves to the commanded position. If only one axis is given as an absolute command, the axes not written stay at the stopped position (Siemens ISO dialect, Mitsubishi Electric)
- If no signal comes in, some models stop with an alarm and others move to the end point and carry on as if nothing had happened. On the models that carry on, a macro compares the stopped position with the end point to decide that it “did not touch”
- Always write F. To protect the probe, do not set the feed too high (Haas recommends less than 2500 mm/min)
Example
G00 G90 G54 X0 Y0 ; G43 H01 Z10. ; (probe tool length) G31 Z-5. F200 ; (stops on contact. Always write F) #100 = #5063 ; (Z where it stopped. #5063 is the Haas number) G00 Z10. ;
A skeleton example written by Kezuriba for measuring the height of the top surface of a workpiece with a touch probe. The variable number that stores the stopped position differs by model.
Diagram: G31: how the next block moves after the signal stops the axes
Full guide with examples: Intro to custom macros: variables (using #5061 and other skip positions in calculations)
Differences between controls and machines
The same code can be written or assigned differently depending on the CNC control and the machine builder. Always check your machine’s manual.
| Source | Machine | Item | Detail |
|---|---|---|---|
| Mitsubishi Electric | Lathe | Notes | If no signal comes in, it moves to the commanded position and ends (no alarm). If F is omitted, the speed in parameter #1174 is used. Feed override is fixed at 100%, and dry run has no effect |
| Haas | Machining center | Notes | If no signal comes in, it records the end point position and carries on (no alarm). Stopped positions are in #5061–#5066 (per axis). Without F, an alarm occurs. A feed below 2500 mm/min (100 inch/min) is recommended |
| Siemens (ISO dialect) | Lathe | Notes | If it reaches the end point without a signal, an alarm occurs. The stopped position is in the system variable $AA_IM[axis] |
| Siemens (native) | — | Format | MEAS (a signal deletes the rest of the move), MEAW (moves on to the end point without deleting it) |
| LinuxCNC | — | Code | There is no G31. G38.2 (error if no contact), G38.3 (no error), G38.4/G38.5 (moving away). Stopped positions are in #5061–#5069, and success or failure is in #5070 |
Sources
The meaning of this code agrees in two or more sources from different publishers. Explanations are written in our own words.
- Siemens AG — SINUMERIK 802D sl/840D/840D sl/840Di/840Di sl/810D Programming Manual ISO Turning, 04.2007 Edition cache.industry.siemens.com
- Siemens AG — SINUMERIK 802D sl/840D/840D sl/840Di/840Di sl/810D Programming Manual ISO Milling, 04.2007 Edition (6FC5398-7BP10-0BA0) cache.industry.siemens.com
- Mitsubishi Electric — MITSUBISHI CNC 700/70 Series Programming Manual (Lathe System) (IB-1500057) mitsubishielectric.com
- Haas Automation, Inc. — G31 Feed Until Skip (Group 00) (machining center, per-code explanation page) haascnc.com
- Haas Automation, Inc. — Lathe Operator's Manual – 16 Lathe G-Codes (online version) haascnc.com
- LinuxCNC project — G-Codes (LinuxCNC Documentation) linuxcnc.org
- Siemens AG — SINUMERIK 840D sl/840D/840Di sl/810D Fundamentals, Programming Manual, Edition 08/2005 (6FC5398-1BP10-0BA0) cache.industry.siemens.com