Dedication
This document is a G code tutorial for LinuxCNC the free CNC software. Formally known as EMC or The Enhanced Machine Controller. This document is intended to teach the proper usage of G code used by LinuxCNC. This document focuses on mill and lathe type of machines.
G code Preamble
The G code preamble sets up the working environment for the machine. It is important to specify modal codes in the preamble that might be in a different state than desired from a previous G code file.
Lathe Diameter Mode
If this is a Lathe the diameter mode should be set in the preamble. G7 is for Diameter measurements and G8 is for radius measurements for the X axis. This setting only affects the X axis on lathes.
Units
No matter what units your configuration was made in you should specificy the units used by the interpreter in the G code file. G20 is for inch measurements and G21 is for millimeter measurements.
Active Plane
The active plane should be specified in the preamble. Normally for a mill you use G17 the X-Y plane and for lathes G18 the X-Z plane. There are some exceptions for using the G18 plane on a lathe. Currently canned cycles only work in the G17 plane and the only ones that make sense are drilling, boring and rigid tapping cycles done at X0 on a lathe.
Tool Compensation
Tool compensation should be turned off in the preamble in case it was left on by a poorly written G code file. G40 turns off tool compensation.
Coordinate System
The coordinate system desired should be specified in the preamble. Normally it is the G54 coordinate system.
Path Blending
The path blending desired should be set in the preamble. The default of G64 may have large deviations in programmed path and should be avoided. Using G64 Pn.n will give you the best possible path and stay within the P value.
Canned Cycles
Canned cycles should be turned off in the preamble in case they were left on by a poorly written G code file. G80 turns off canned cycles.
Preamble Examples
G20 G17 G40 G64 P0.001 G80
G7 G20 G18 G40 G64 P0.001 G80