Share

The Basics of CNC G CODES

To direct CNC machines, machinists use a command system called G Codes. While various manufacturers who utilize CNC machines create their own standard use for some G Codes there is a specific group of codes that is common on every machine tool. 

These standards are utilized on CNC milling machines, lathes, routers and 3D printers. Understanding the basics of CNC G codes will provide an overview of how these machines respond to commands, and help a new programmer with the fundamentals.

 

G00 Rapid Motion 

On an older machine with less ram, this code may be shortened to G0. 

Rapid motion is a high-speed command to move a machine tool to a new position when it is not in touch with the material. The simple process can significantly reduce the time it takes to machine the part. Some machinists prefer to program rapid movement as close to the part as possible. 

We advise giving yourself a minimal clearance of 1mm for safety. For a first-time run, we also recommend machinists keep their hands on the feed knob and advance slowly. From all the various G codes, the G00 command can cause the most damage if the tool machine tool is not set up properly. 

When employing rapid motion, machinists should be conscious of any vice, parts, or clamps that may be in the way of their path. An additional safety measure is to consider moving the X and Y axis first, then on a different line, move down in Z. This will increase machining time slightly, but it will help prevent a crash. 

 

G01 Linear Interpolation Motion 

This code is used to cut a straight line and must be accompanied by an active feed rate (F). Once active, the feed rate will function with multiple G codes and only needs to be addressed if the speed needs to change.

The G01 command can be utilized with all axes cutting at the same time, or just one. Generally, it is uncommon to cut with the Z-axis, X-axis and Y-axis together, however, it can be done. 

(When machinists set up the program it makes it easier for them to utilize cutter command G41 and G42 and do not need to enable the radius of the cutter when mapping out tool paths, they can just utilize the dimensions on the drawing and the machine will offset to achieve the correct dimensions.)

 

G02/G03 Circular Interpolation 

The G02 command is utilized to introduce a radius or an arc in a clockwise direction, and the G03 command is counterclockwise. To define the radius machinists have to utilize an ‘R’ value, or offset, to enable the G02/G03 command to move the cutter from a starting point to an endpoint with a defined curve, or radius.

When using these three codes, G01 with G21 and G03, any shape can be machined. These are the essence of G Code commands and are always used when machinists have to cut material. 

G04- Dwell Code

There are applications, especially when drilling when machinists have to stop the cutter for a specified amount of time.t, This is known as the t G04, or dwell code. For example, if a machinist is drilling with a flat bottom drill and the surface of the bore becomes uneven due to chatter, the drill in the Z-axis can be stopped while still rotating for half a second for machinists to clean up the surface. 

G20 and G21 Unit Selection Codes

CNC machines can read measurements in imperial and metric systems. G20 and G21 are commands for measurement that are defined in imperial units; inches (G20) and metric until; millimeters (G21).  

While this code is generally needed only once in the program, it is best practice to implement G20 or G21 code information after every tool change.  This allows a program to run from any point without the risk of calibration errors.

G90 and G91 Absolute and Incremental Codes

G90 is defined as absolute positioning and G91 is defined as the incremental position. These positioning commands have to be defined before movement begins. With the G90 code, all movements of the spindle are taken from the datum, or starting, position. With the G91 code, the movements of the spindle are taken from its last registered position. 

G40, G41, G42 – Cutter Compensation 

Cutter compensation refers to the diameter of the tool in use in the cutting operation. Code G40 cancels cutter compensation, G41 is for left cutter compensation and G42 is for right cutter compensation. Without utilizing cutter compensation when programming machinists will have to allow for the diameter of the tool when writing cutting paths. By using cutter compensation machinists can program the dimensions of the component and offset the cutter by its radius depending on the direction of the cut. 

 

There are many other codes, such as M Codes, and unique G codes machine manufacturers have programmed for their equipment, but the basics of CNC G codes follow the same pattern as manual machines. There are generally a few simple tools and a few functions on each axis that are needed to fabricate a part.


Download CNC G Code Cheat Sheet