The first time you look at a CNC lathe program it is all G this and M that, and it reads like a cipher. Mine did too.
The good news is that the number of codes you genuinely use day to day is small. This article covers the ten G-codes to learn first and how to read a program, with a real example.
What G-code is, and how a program is put together
G-code tells the machine how to move. A lathe program is built out of these pieces.
| Address | What it sets | Example |
|---|---|---|
G | How the machine moves (preparatory function) | G01 = cut in a straight line |
M | Machine functions | M03 = spindle forward |
T | Tool selection | T0101 = tool 1 with offset 1 |
S | Spindle speed or surface speed | S1500 |
F | Feed rate | F0.2 = 0.2 mm per rev |
X / Z | Coordinates (X across the diameter, Z along the axis) | X50.0 Z-30.0 |
On a lathe, X is normally programmed as a diameter. X50.0 means the tool sits at 25 mm on radius. Z is usually zeroed on the face, and goes negative as you move into the part.
The ten G-codes to learn first
| Code | Meaning | Notes |
|---|---|---|
G00 | Rapid positioning | Fastest move, no cutting. Most crashes happen here, so watch the path it takes |
G01 | Linear feed | Cuts in a straight line at the feed you set with F. The one you use most |
G02 | Circular feed, clockwise | Cut an arc, radius given with R |
G03 | Circular feed, counter-clockwise | The other direction |
G28 | Return to reference | Back to machine home. Use it at a setup change or the end of an operation |
G50 | Spindle speed clamp | The safety limit when you are running constant surface speed |
G96 | Constant surface speed | Holds cutting speed in m/min as the diameter changes. Gives a consistent finish |
G97 | Constant RPM | Use this for threading and drilling |
G41/G42 | Tool nose radius compensation | Corrects nose radius error automatically. Full article here |
G40 | Cancel nose radius comp | Always cancel what you turned on with G41/G42 |
The M codes worth learning alongside
| Code | Meaning |
|---|---|
M03 / M04 | Spindle forward / reverse |
M05 | Spindle stop |
M08 / M09 | Coolant on / off |
M30 | End of program, rewind to the top |
Read a real one: an OD turning program
Take 50 mm bar down to 40 mm and put a step on it 25 mm long. A plain OD job. Follow it a line at a time.
O0001 (program number)
G50 S2500 (clamp the spindle at 2500 rpm)
G96 S200 M03 (200 m/min constant surface speed, spindle forward)
T0101 (call tool 1)
G00 X52.0 Z5.0 M08 (rapid up to the bar, coolant on)
G01 Z0 F0.25 (feed to the face)
X-1.6 (face off, run just past centre)
G00 X46.0 Z2.0 (move to the start of the first cut)
G01 Z-25.0 (turn 46 dia for 25 mm)
X52.0 (clear the part)
G00 Z2.0 (back to the start)
X42.0 (second cut)
G01 Z-25.0 (turn 42 dia)
X52.0
G00 Z2.0
X40.0 (finish size)
G01 Z-25.0 (finish 40 dia)
X52.0
G00 X150.0 Z100.0 M09 (back to the tool change position)
M30 (end of program)
Written out like that, you can see it is the same four moves over and over. Go to the start, cut, clear, come back. G-code is not free composition, it is a set of stock phrases. Once you have the patterns, you can read it.
There is a shortcut: canned cycles like G71
In the example above every cut was written out by hand. On the shop floor you will more often see a canned cycle such as G71, the OD roughing cycle, where you write only the finished profile and let the control work out the roughing passes. G76 and G92 for threading are the same idea. It is worth understanding the moves with G01 first, then moving on to the cycles.
From writing G-code to reading it
If your reaction to all this was "that is a lot to remember", you are not wrong. The job is shifting, though. Writing G-code from scratch is becoming rarer, and reading, checking and occasionally correcting CAM output is becoming the normal way to work.
Being able to read G-code will stay a valuable skill. The only person who spots the difference between the simulation and what the machine actually does is someone who can read the code. But keying it all in from scratch every time is not a thing you need to keep grinding at.
With LATHE-NC, the lathe CAM that runs in your browser, you load a DXF, check the simulation, and it outputs G-code like the program above. Being able to read what comes out is the point, and I hope this article helps with that.
Summary
- A lathe program is G, M, T, S, F and coordinates. X is a diameter value.
- Start with G00, G01, G02, G03, and knowing when to use G96 versus G97.
- Programs are the same move, cut, clear, return pattern repeating.
- Reading matters more than writing now. Letting CAM do the writing is a real option.
Let the CAM do the typing.
LATHE-NC is three steps: load a DXF, check the simulation, output G-code.
The beta is free for the first 100 users.