FIFTY LINETurn G-code

G7 and G8 in LinuxCNC: programming X as diameter or radius

· ~6 min read

On a lathe, the X coordinate is the distance of the tool from the spindle centerline. It can be written in two ways: as a radius (how many millimeters from the centerline) or as a diameter (what diameter you get). In LinuxCNC two codes switch between them: G7 and G8. Mixing them up is one of the most common, and most expensive, mistakes in lathe programming.

Contents

  1. G7 and G8 at a glance
  2. Example: one part in both modes
  3. Which mode is handier
  4. What changes and what does not
  5. Default mode and the INI setting
  6. How to check the current mode
  7. What happens if you mix them up
  8. Diameter and radius on other controls
  9. G7 and G8 in Turn G-code

G7 and G8 at a glance

Code X means X15 is LinuxCNC default
G7 diameter Ø15 (tool 7.5 mm from the centerline) no
G8 radius radius 15, i.e. Ø30 yes

Both codes are modal: the mode stays active until another code changes it.

Example: one part in both modes

Turning Ø40 stock down to Ø30 over 50 mm. The same toolpath:

Step In G7 (diameter) In G8 (radius)
Approach above the stock G0 X42 Z2 G0 X21 Z2
Finishing pass at Ø30 G0 X30 G0 X15
Turning along the length G1 Z-50 F0.1 G1 Z-50 F0.1
Retract G0 X42 G0 X21

Z is the same; only the X numbers change - in G8 they are half as big.

Which mode is handier

Diameter (G7) is how a machinist thinks:

  • drawings give diameters (Ø30h7, not R15);
  • micrometers and calipers measure diameter;
  • when correcting size you see the error directly: a part at Ø30.08 instead of Ø30 needs a 0.08 correction on the diameter.

Radius (G8) is closer to the machine’s geometry: X is the actual cross slide travel from the centerline. Taking 0.5 mm per side in G8 means X 0.5 smaller; in G7 it is 1.0 smaller. Some generators and CAM posts output code in radius.

There is no right mode - only a correctly stated one. What matters is that the program and the machine read X the same way.

What changes and what does not

  • Only X changes - both absolute coordinates and G91 increments: in G7, G91 G1 X-1 moves the tool 0.5 mm toward the centerline.
  • Z does not change at all.
  • Feed F is the speed along the actual path and does not depend on the X mode.
  • Arcs (G2/G3), threading and other cycles (G76, G71/G72) use X as well, and some of their parameters (for example I, J, K in G76) are interpreted differently in diameter mode. The rules depend on the LinuxCNC version - check the documentation for yours, and check the toolpath in the Axis preview before cutting.

Default mode and the INI setting

LinuxCNC starts in G8 (radius). To make the machine start in diameter mode, set it in the configuration INI file, in the [RS274NGC] section:

[RS274NGC]
RS274NGC_STARTUP_CODE = G18 G21 G7 G90 G40 G94

This also sets the XZ plane (G18), millimeters, absolute coordinates, cancels nose radius compensation and sets feed in mm/min.

But you cannot rely on the startup code alone: the mode is modal and can be left over from a previous program or from a command typed in MDI. So every program should set the mode itself in its safety line:

G21 G18 G90 G7 G40 G80

Then the program runs the same way no matter what the machine was doing before.

How to check the current mode

  • In Axis, the MDI tab has an Active G-Codes line - it shows whether G7 or G8 is in effect.
  • Toolpath preview in Axis: if the part on screen is twice as thick or thin as on the drawing, the mode is wrong.
  • Run every new program “cutting air” first, with extra X clearance, and watch the coordinates in the position display.

What happens if you mix them up

Program written Machine mode What happens
in diameter (X30 = Ø30) G8 X30 is radius 30, Ø60. The tool stops twice as far from the centerline: it cuts air or leaves the part oversize
in radius (X15 = Ø30) G7 X15 is Ø15. The tool goes twice as close to the centerline: it cuts far too deep, breaks the insert, ruins the part

The second case is more dangerous: the error goes into the metal - especially on a G0 rapid approach that was meant to stay “above the stock”.

Diameter and radius on other controls

  • Fanuc (and GSK, KND, Syntec in Fanuc syntax): the X mode is set by a control parameter; on lathes it is usually diameter. There are no G7/G8 codes for it, and Fanuc’s G7.1 is something else entirely - cylindrical interpolation.
  • Haas: lathes usually program X in diameter.
  • Siemens SINUMERIK: the commands DIAMON (diameter), DIAMOF (radius), DIAM90 (diameter for absolute, radius for incremental).
  • Mach3 Turn / Mach4 Lathe: diameter or radius mode is a setting.

So a program written for another control always needs checking: is it in diameter, and does it have G7 for LinuxCNC. Other differences are in the G-code and M-code reference for lathes.

G7 and G8 in Turn G-code

In Turn G-code the X mode is one G8/G7 button in the top bar of the main window, for all 12 cycles at once. The program:

  • puts the chosen code in the safety line of every program: G21 G18 G90 G8 G40 G80 G94 or G21 G18 G90 G7 G40 G80;
  • converts every X itself - you enter diameters in the form, as on the drawing, and get diameter or radius in the code;
  • shows the toolpath in the 2D simulator before generating the file.

Here are two real examples from this site. OD turning is output in G8: the Ø12 stock is written as X6, and the first roughing pass is X5.8:

G21 G18 G90 G8 G40 G80 G94
...
(Roughing pass 1, X5.8000)
G0 X5.8000
G1 Z-20.0000 F100.0000

And the threading example, M12×1.5, is output in G7: the first pass runs right at Ø12:

G21 G18 G90 G7 G40 G80
...
(Pass 1 of 10, X12.0000)
G0 X12.0000

Download Turn G-code - 15 days free, no key needed.

← All articles