Professional Documents
Culture Documents
Getting Started With G-Code: Advanced Manufacturing
Getting Started With G-Code: Advanced Manufacturing
ADVANCED MANUFACTURING Menu
By Ellie Rathbone
August 10, 2020
1 of 13
Getting Started with G-Code - Advanced Manufacturing
2 of 13
Getting Started with G-Code - Advanced Manufacturing
WHAT IS G-CODE?
G-code is a programming language for CNC that instructs machines where and
how to move. Most machines speak a different “dialect” of g-code, so the codes
vary depending on type, make, and model. Each machine comes with an
instruction manual that shows that particular machine’s code for a specific
function.
G-code stands for “geometric code,” and follows some variation of the alpha
numeric pattern:
N: Line number
G: Motion
X: Horizontal position
Y: Vertical position
Z: Depth
F: Feed rate
S: Spindle speed
T: Tool selection
M: Miscellaneous functions
I and J: Incremental center of an arc
R: Radius of an arc
Alpha numeric codes are used for programming as they are a simple way to:
3 of 13
Getting Started with G-Code - Advanced Manufacturing
For example,
would generally indicate a linear feed move (G01) to the given XY position at
feed rate of 20. It is using Tool 1, and the spindle speed is 500. Miscellaneous
functions will vary from machine to machine, so in order to know what the
m-code means, the machine’s instruction manual will need to be referenced.
MACHINE MOTION
Every g-code tells the machine which variation of these basic motions to
perform, and how to perform it.
X and Y are Cartesian coordinates for horizontal and vertical position, and Z
represents the depth of the machine. These alpha numerals will follow the
motion/function command (G) to declare the position of the machine.
Next, F determines the feed rate (for feed moves or circular moves), while S
determines the spindle speed. T is used to select a tool. Other alpha numerals
used in programming might include I, J, and R, which have to do with arc centers
and radii.
MISCELLANEOUS CODES
The line of a program might also include m-codes, which are generally codes
that tell a machine how to perform an action. While not guaranteed to be the
same across machines, some common, standard m-codes are:
4 of 13
Getting Started with G-Code - Advanced Manufacturing
MODALITY
Just like a light will stay on until it’s turned off, g-code functions (on controllers
that support modality) will remain active until they are deactivated by another
code. In other words, only one function can be active at any given time. To
deactivate a function, just select a new function.
For example, say a code begins with a linear rapid move at X1 Y1 (G00 X1 Y1). If
the next function is another linear rapid move, it is not necessary to write G00
again. All that is needed on the next line of code is the new position (say, X2 Y2)
because the modal condition is the same. Then, to change the function to a
linear feed (G01), programming G01 on the following line would deactivate the
linear rapid move and activate the linear feed.
Once a condition is set, it stays active until it is turned off or another condition
overrides it.
5 of 13
Getting Started with G-Code - Advanced Manufacturing
CANNED CYCLES
Canned cycles are a kind of modal condition that incorporate all the motions to
complete a common task into one code.
For example, oftentimes G81 is code for a basic drilling function. In the case of
basic drilling, the tool would have to be 1) moved to the starting point of the
hole’s location, 2) rapid to the clearance plane, 3) fed to the depth, and 4) rapid
out. That would be four lines of code in the program that would have to be
repeated for every new drill position! With the canned cycle G81, only the hole
locations need to be specified after activation. Canned cycles like G81
significantly reduce the amount of code by incorporating multiple motions into
one code.
6 of 13
Getting Started with G-Code - Advanced Manufacturing
Some other common canned cycles exist for peck drilling, counter boring, and
tapping.
Learn how to get the most out of your CNC machines in this free eBook.
Modal code groups allow there to be multiple codes on a single line, but there
can only be one code from each group on a line. This is because codes within a
group will override each other.
Group 1 (motion): G00, G01, G02, G03, G80, G81, G82, G84, G85, G86, G87,
G88, G89
7 of 13
Getting Started with G-Code - Advanced Manufacturing
Group 12 (work coordinate system selection – WCSS): G54, G55, G56, G57,
G58, G59)
POSTPROCESSORS
8 of 13
Getting Started with G-Code - Advanced Manufacturing
on your computer screen into the language for a machine control. You can create
a post processor by searching for a sample program that aligns closely with your
machine, and then amending the program to precisely fit your machine. Before
you can do this, you’ll need to know:
The program will often start with an initialization code (%), followed by a
program number. Then, there will be a line of safety codes. Next will be a line for
tool change. This puts the appropriate tool in the machine and set the speed to
be used. The bulk of the program will then be the machine movements and
positioning.
If using line numbering, it’s a good idea to name each line in increments of at
least five. This way, if you need to add lines of code later, the lines will still be
labelled in order.
When you’ve finished programming your g-code, you’ll typically end the program
with a series of functions that stop and reset the machine so it’s ready for the
next time.
POSTPROCESSORS
Ready to start using g-code to program your machines? Begin by reviewing your
machine’s unique coding chart. Remember, every machine is a little different.
A Haas’ code for a function might not be the same as an Anilam’s code for that
function. You have to know which codes your specific machine uses for the tasks
you want it to perform.
9 of 13
Getting Started with G-Code - Advanced Manufacturing
The program will often start with an initialization code (%), followed by a
program number. Then, there will be a line of safety codes. Next will be a line for
tool change. This puts the appropriate tool in the machine and set the speed to
be used. The bulk of the program will then be the machine movements and
positioning.
If using line numbering, it’s a good idea to name each line in increments of at
least five. This way, if you need to add lines of code later, the lines will still be
labelled in order.
When you’ve finished programming your g-code, you’ll typically end the program
with a series of functions that stop and reset the machine so it’s ready for the
next time.
Some machines and controllers ignore spaces. G01 X1 Y1 Z1 might mean the
same thing as G01 X1Y1Z1.
The Z-axis is positive in the up direction. Z1 will bring the tool up, while Z-1
will bring the tool down.
Your machine’s g-code dialect will specify if a leading zero is necessary (as
in G01, as opposed to G1).
The dialect will also determine if decimal points are always necessary (ex.
G01 X1. Y1. Z0.5)
It’s a good idea to run the sample programs that come in your machine
manual before you try to run a big program. Oftentimes, the sample
programs do not work and you will need to note the issues and set your
own benchmarks.
When used correctly, g-codes are an invaluable tool for CNC machinists, allowing you to take full
advantage of your machine’s capabilities. And integrated CAM solutions continue to streamline the
CNC coding process, so you don’t have to program parts by hand using g-codes. Producing high
quality parts has never been faster.
G-code shouldn’t be “all Greek” to you. Even as automatic coding and other manufacturing
advancements take shape, understanding CNC language will bridge the manufacturing borders that
have been holding you back, helping you make the best products possible.
10 of 13
Getting Started with G-Code - Advanced Manufacturing
Ready to MAKE?
VISIT WEBSITE
Related Articles
BLOG
Surface Finishes When
Machining – Vital Details to
...
One of the most important things to
consider when you’re looking to create a
mold is surface finish. No matter what ...
11 of 13
Getting Started with G-Code - Advanced Manufacturing
BLOG
Replacing EDM
Manufacturing with CNC
Milling for Efficiency
Many different manufacturing processes
are used to actually manufacture tooling
for mold making. Most mold making
involves CNC machining, or subtractive ...
BLOG
A closer look at Vertical and
Horizontal Milling ...
For machine shop operators considering
milling machines, one of the most basic
questions they have to answer relates to
configuration: vertical or ...
Add comment
No comments yet
12 of 13
Getting Started with G-Code - Advanced Manufacturing
Ready to MAKE?
VISIT WEBSITE
13 of 13