G-code and post processors in plain English
G-code is a text list of movements. G0 is a fast move with no cutting, G1 is a cutting move at a feed rate, and X, Y and Z are the destination. The post processor is a translator that writes those lines in the exact dialect your controller expects.
Reading a line
A typical line looks like this:
Move in a straight line, cutting, to the point 2.5 in X, 1.75 in Y, 0.125 below zero in Z, at 60 units per minute.
That is the whole idea. A program is a few thousand of those, plus some setup at the top and a tidy shutdown at the bottom.
The commands you will actually see
| Code | Means | Notes |
|---|---|---|
| G0 | Rapid move | Maximum speed, not cutting. Happens at safe Z, above the work. A G0 at a cutting depth is a red flag. |
| G1 | Linear cutting move | Straight line at the programmed feed rate |
| G2 / G3 | Arc, clockwise / counter-clockwise | Smoother and smaller than thousands of tiny G1 segments |
| G20 / G21 | Units: inches / millimetres | Near the top of the file. Getting this wrong scales your job by 25.4 |
| G90 / G91 | Absolute / relative positioning | Almost everything is G90, absolute |
| G54 | Work coordinate system 1 | The offset from machine home to your work zero |
| M3 / M5 | Spindle on / off | With S for speed, as in M3 S18000 |
| M6 | Tool change | Behaviour varies hugely between controllers |
| F | Feed rate | Units per minute, in whatever units G20 or G21 set |
Why post processors exist
Controllers do not all speak the same dialect. One expects a tool change to pause and wait for a button. Another wants the spindle command written differently, or does not support arcs in a certain plane, or needs the file to end with a specific sequence. The CAM software knows the geometry; the post processor knows your machine's quirks.
This is why choosing the wrong post processor is a real and common problem. The toolpaths are right, the geometry is right, and the machine still does something strange: it ignores tool changes, it runs in millimetres when you meant inches, or it plunges at rapid speed. Almost always the answer is the post processor, not the design.
Previewing before you cut
Every serious CAM package has a simulation, and there are free G-code viewers that will draw the toolpath for you. Use them. Two minutes of looking at a preview catches:
- A rapid move that crosses the work at the wrong height
- A cut that goes deeper than your material
- A toolpath that runs past the edge of your stock
- Toolpaths in the wrong order, for example a profile cut before the pocket that needed the material held down
Editing G-code by hand
Occasionally useful, mostly avoidable. Reasonable edits: changing a feed rate, removing a tool change, adding a pause. Unreasonable edits: trying to fix geometry. If the shape is wrong, fix it in CAD and re-post. Hand editing a few thousand coordinate lines is how you get a cut that is right for 90 percent of its length.