You are on page 1of 4

# Basics of CNC Part 1 – G Code

A program starts with various code to set the machine up – Inch/Metric, Absolute/Incremental coordinate system, etc. This varies a bit from machine to machine. After that, the fun starts (the machine starts moving). The main thing you should know about G-code is that each line is an instruction that “pulls” the machine from [wherever it is] to a new coordinate. Along with the new position, you can describe the shape of the path (linear or in an arc) and the speed at which to travel – a.k.a. feed rate. That's pretty much it. Of course that's never really true though is it? The fact is, there are tons of things and several ways you can tell a CNC machine to do something and it can become fairly complicated if you want it to. Luckily, most things can be accomplished with pretty simple code. Here are the basic commands in a nutshell. G0 (G zero, not “go”) This is the command for rapid position. With this command, the machine motors will travel as fast as they are set up to move toward whatever coordinate you attach to it. For example, if the machine is sitting at coordinate X3.0 Y2.0 Z-2.5 and you command: G0 X0 Y0 Z0 it will simply move as fast as the motors are allowed to spin, stopping at X0 Y0 Z0. This is a pretty uninteresting command but it will be used all the time. G1 Linear interpolation. This command will coordinate the motors to move the machine in such a way that it travels from [wherever it was] in a straight-line path to the new position. You also need to tell it how fast to travel along this path. i.e. machine is sitting at X0 Y0 Z0 and you command: G1 X4.0 Y4.0 F10.0 The machine will travel in a straight line at 45º toward the point (4,4) at a speed of 10 inches per minute. Note that there is no Z coordinate included here. That means that only X and Y will change and Z will stay wherever it was before the new command. No new info = no position change. Side note: Also note that when I specified zero above, I just wrote 0 with no decimal point. All controls understand what zero is and a decimal is never necessary. However, some controls interpret values differently – some read “4” to mean .0004 and some to mean 4.0 – for this reason, I always write a decimal point when specifying values other than zero so that it can be understood by any machine. It's just good practice. You can leave off the trailing zero (I usually do). Machine controls interpret 4. and 4.0 to mean the same thing, but just to be clearer I'll leave the trailing zero on for this presentation (unless I forget). So G0 and G1 are the two most basic motion commands.