Gcode
Manufacturers all around the world use CNC programming to control a machine’s tools to produce parts. At the heart of this automated manufacturing process is a set of instructions that tells a CNC machine where – and how – to move. These instructions are called G-Code.
Many of the words, or individual pieces of code, that make up this machine-based language start with the letter G.
The goal of every G-code program is to produce parts in the safest and most efficient way possible. To achieve this you’ll typically find G-code blocks arranged in a very specific order like this:
- Start the CNC program
- Load the required tool
- Turn the spindle on
- Turn the coolant on
- Move to position above a part
- Start the machining process
- Turn the coolant off
- Turn the spindle off
- Move away from the part to a safe location
- End the CNC program
Each new line (called block) in the G-code can be roughly regarded as a new command. Everywhere you look in the code you will mostly see letters with numbers behind them. These letters corresponds to different types of commands. The most important ones are arguably G (used in most movement commands), M (miscellaneous commands), X, Y and Z. X,Y,Z are used to define (absolute or incremental) positions in the X,Y,Z space.
CAMotics
Would you start cutting without measuring first? Then why would you run a CNC program with out simulating? CAMotics will save you time and money and open up a world of creative possibilities by allowing you to rapidly visualize and improve upon designs without wasting materials or breaking tools.
With CAMotics, you can simulate 3-axis GCode programs for CNCs and visualize the results in 3D. With the power to simulate your CNC tool paths you will avoid dangerous and expensive mistakes.
G & M-Codes Explained
G & M-codes will make up the bulk of your CNC program. Codes that begin with G prepare your machine to perform a specific type of motion. The most common G codes that you’ll encounter time and time again in every CNC program include:
G0 – Rapid Move
This code tells a machine to move as fast as possible to a specified coordinate position. G0 will move the machine axis by axis, meaning that it will first move along both axes and finish the move on whichever axis is not in positions. You can see an example of this motion in the image below:
G1 – Linear Move
This code tells a machine to move in a straight line to a coordinate position with a defined feed rate. For example, G1 X1 Y1 F32 will move the machine to coordinates X1, Y1, at a feed rate of 32.
M-codes
M codes are machine codes that might differ between CNC machines. These codes control functions on your CNC machine like coolant and spindle directions. Some of the most common M-codes include:
Canned Cycles
The last aspect of G-code to touch on is canned cycles. These are similar to methods or functions in computer programming. They allow you to perform a complicated action in only a few lines of code without having to type out all of the details.
Take for example the canned cycle below. Here we are telling the CNC tool to create a hole with a peck drill in only two lines of code on the left. This same action takes over 20 lines of regular G-code.
G81 – Simple Drill Cycle
This cycle will make a hole by plunging to a specific Z-axis coordinate and then retracting. G81 does no pecking and has no special operation at the bottom of the hole. It just goes down at the feedrate, and then retracts.
Programming this cycle requires a depth, feed rate, XY coordinates, and plane to drill on.
Z1.0 (Initial Z)
X10 Y12 (XY for first hole)
– First, the machine rapids to the X and Y coordinates of the hole
G99 G81 R0.2 Z-0.7
- the tool rapids straight down to the R position, established by the “R” word of the cycle. We came in at a Z of 1.0″. R is 0.2″, so we rapid from 1.0″ down to 0.2″.
X10 Y14 (XY for second hole)
X10 Y16 (XY for third hole)
G80 (Cancel canned cycle)
G83 – Peck Drill
This cycle is used for quickly drilling deep holes. This is the practice of drilling a little (the peck distance), back off some distance, and then going back down to the bottom to take another peck. Think of the motion as being not unlike a woodpecker. The reason it’s done is to and allow the coolant to flush away chips from the bore. There’s only enough room down in the bore for the chips that fit in the flutes of the twist drill, and the deeper the hole, the harder it is to evacuate those chips out of the hole
The simplest implementation of this cycle requires an initial height, feed plane, peck increment, and depth.
A deep hole is any hole more than 5 diameters deep. The deeper you go, the harder it gets. A variety of techniques are needed, and peck drillings cycles are just one. Here’s a handy chart to help you keep up with the various techniques:
Software
Pro vs Beginner/Hobbyist Software
In many pursuits, it’s tempting to want to start with the best. Get what the Pro’s use, how can you regret it?
The reason why that may not be the best approach is that Pros and Beginners need to solve different problems.