Turning G-code

Writes an example lathe program to turn a plain diameter back from the front face, with an optional 45° chamfer and facing pass. Choose a FANUC-style G71 rough and G70 finish cycle, or plain G1 passes that need no canned cycle.

Example code – check it and dry-run it, at your own risk. This program is a generic example, not written for your machine or control. Read every line against your control’s manual, simulate it, then run it above the work in single block with reduced rapids and feed before cutting. Check the work offset, tool length offset, units and clearance heights. See the terms of use.
How it works, guides and notes

Which style to use

G71/G70 uses the FANUC-style two-block G71: the first block gives the depth of cut per side (U) and retract (R), the second gives the profile block numbers (P, Q), the finish allowances (U on diameter, W in Z) and the roughing feed. The profile between N100 and N200 is then finished with G70 P100 Q200. Other controls differ: some use a one-block G71, and LinuxCNC’s G71 reads the profile from a subroutine, so do not run this style without checking your manual.

Plain G1 passes write out every roughing pass and the finishing pass as ordinary G0 and G1 moves, so any control that reads G0/G1 can run them. Only the set-up line changes: FANUC-style lathes use G99 for feed per revolution, while LinuxCNC uses G95 and needs G7 for diameter mode (G99 means something else there).

How it works

X is on diameter and Z0 is the finished front face. Roughing removes (stock − finished − X allowance) ÷ 2 per side in equal cuts no deeper than your depth of cut, stopping short of the shoulder by the Z allowance. Each roughing pass feeds out by the retract amount at the shoulder, then rapids back clear. The finishing pass follows the profile: chamfer, diameter, then up the shoulder face. Facing goes past centre by twice the nose radius so no pip is left.

Hand check: 40 mm stock to 30 mm with 0.4 mm X allowance: (40 − 30.4) ÷ 2 = 4.8 mm per side; at 1.5 mm max that is ceil(3.2) = 4 cuts of 1.2 mm, at X37.6, X35.2, X32.8 and X30.4. A 1 mm chamfer starts at X28.0 Z0 and ends at X30.0 Z−1.0.

The finishing pass has no nose radius compensation, so a chamfer will be slightly undersized: see tool nose compensation. A chamfer bigger than one roughing cut is taken in the finishing pass alone. The run time shown is an estimate.

FANUC, Haas, Siemens, Heidenhain, LinuxCNC and Grbl are names or trademarks of their respective owners. They are mentioned only to describe which controls a code format relates to. Lathe Calculator is not affiliated with or endorsed by any of them. Trademarks.

Spotted a mistake? Report an error.