Don’t have time to read the whole guide right now?

No worries. Let me send you a copy so you can read it when it’s convenient for you.

Just let me know where to send it (takes 5 seconds):

Yes! Give me my PDF
Image

G-code programs today can be thousands of pages long. Don’t worry, those programs are typically spit out by some CAM software.

The heart of G-code can be understood with much less code.

The following concepts will give you a good understanding of G-code, and enough of baseline where you can confidently add it as a skill to your tool box.

Also, if you eventually do move onto a CAM package like Mastercam, you will be capable of due diligence so you can ensure your programs are ready to send to the machine.


How to read G-code

Read the code left to right, word by word, block by block.


Image

Note: The code above is very important, we know it as a safe line. You should see something similar to it at the top of every program.

Read it as: Absolute positioning mode, Metric mode (G20 for inch), Cancel cutter compensation, cancel all fixed cycles.

Always
Remember
Modality
When
Using
G-code

Some of the G-words we come across (G54, G01, G43) are going to be modal, some will not. (List below)

So when you are reading, always remember these rules.

If the G-code is modal:  It will remain in effect for all subsequent blocks until replaced by another modal G word. Or canceled.

If the G-code is not modal: It will only affect the block in which it is included.

Various meanings of G-code letters


LetterMeaning
NLine Number, LN, block number, sequence number.
GDescriptor code. Specifies the type of operation we want the machine to follow.
X, Y, ZCartesian coordinate letters and axis labels. Designates which axis we want to be active.
I, J, K
U, V, W
A, B, C
P, Q, R
FFeed rate, always used to tell the MCU what we want the cutting speed of the tools to be in relation to the work piece.
SSpindle speed in revolutions per minute RPM.
TTell the machine what tool we want to use.
MOur machines have misc. functions such as coolant on. Your controller could have extra codes specific to just your machine.
H, DSpecifies extra functions for the controller, such as use too length offset X.

G-code G-word list


G codeModeSpecification
G0ModalRapid positioning mode. The tool is moved to its programmed XYZ location at a maximum feed rate.
G01ModalLinear interpolation mode. The tool will be moved along a path at a specific feed rate.
G20ModalInch mode for all units.
G21ModalMillimeter mode.
G28Not modalReturns to tool reference points.
G43ModalSpecify tool length offset.
G49ModalCancels tool length offset.
G53ModalCancels G54-G59.
G54-G59ModalSpecify fixture work offset locations.
G80ModalCancels and fixed cycle. Use this G-word at the beginning and end of every single program.
G90ModalSpecify absolute position programming.
G91ModalSpecify incremental position programming.
G92ModalDirects the MCU to shift the absolute zero point XY values from the current tool to the part origin.
G98ModalSpecify a return to the initial point in a machining cycle that was created by a modal G-word.

The best way to learn

Like with anything else, you have to just keep doing it.  The guys that you know are succeeding, they never stop growing.

The G-code G-word meanings are all over the internet, but it you do not practice reading and writing G-code, then you will never fully grasp it.

Keep this skill sharp. 

I love my CAM as much as the next guy, and will never get rid of it, but I try to always keep my G-code sharp.

So let’s do some reading and writing, scenario:

I think most of us machinist, engineer, tinker type people, like to have a goal in mind, so here is the scenario: 

  1. We have a 3-axis mill
  2. We want to “make the connection” (I’ll explain next)
  3. We want to draw a square with the tool
  4. We then want to translate that square into a cutting path

A couple things I am not going to cover in this guide:

  • What work offsets and tool lengths offsets are in depth
    • I am assuming you have some knowledge of what these are
  • Speeds and feeds
  • Cutter compensation

Making
The
Connection

The computer has revolutionized the manufacturing industry.  That includes, Machining, Robotics, 3D-Printing, etc.  Just visit the MT facebook page, or Instagram, the complexity of some of the stuff today is remarkable. 

My manual machinist friends are going to dog me for this, but without the computer skills, it will be very hard for someone to progress in this new era of manufacturing.

What does this mean for us?

We need to be able to "make the connection" when ever were are working in the computer or with G-code.

Making the connection = Visualizing and planning how you are going to translate the work you are doing in the virtual environment or with hand G-code, onto the physical machine or work space you are using. 

Don’t have time to read the whole guide right now?
No worries. Let me send you a copy so you can read it when it’s convenient for you.
Just let me know where to send it (takes 5 seconds):
Yes! Give me my PDF
Image

G54 – G59 Work Offset

Image

We know how to set our work offsets using an edge finder.

This will set the location connection between our virtual environment and out physical machine.

Your controller should have a work offset page where you will enter this data.

We will use G54-G59 to access the data.

Image

G43 Tool Length Offset

Image

We also know how to set a tool length offset.

This will correctly make the connection between our tool and the work piece.

Your controller should have a tool length offset page where you will enter this data.

We can then access the proper tool data via G43.

Image

Example Program

N001 G90 G80 G40 G20 G17 G94 (safety block)
N003 M06 T1
N004 G54 G00 X-.5 Y-.5
N005 G43 Z1.0 H1
N006 G0 G90 X.5 Y-.5
N007 Y-2.0
N008 X3.0
N009 Y-.5
N0010 X.5
N0011 G28 X0 Y0 Z0

Image

Let’s read it:

G90 G80 G40 G20 G17 G50 G94 G6
Safety Block: Absolute mode, Cancel all fixed cycles, Cancel cutter compensation, cutting plane X, Y, Feed rate IPM.

M06 T1
Automatic tool changer, load Tool 1

(4) G54 G00 X-.5 Y-.5
Using the G54 offset from the MCU, move to absolute X-.5 Y-.5.

(5) G43 Z1.0 H1
Rapid move tool 1 to 1.0 inch above part. 
(With proper Machine coordinates, the tool should move –Z down towards the part and stop 1.0 inch above G54 X0 Y0)

(6) G0 G90 X.5 Y-.5
Using rapid positioning (aka moving in rapid), also using absolute positioning mode, move in both the x and y axis to X.5 Y-.5

(7) Y-2.0
With G0 G90 still active, move in rapid, only in the Y axis, to the absolute position of Y-2.0

(8) X3.0
With G0 G90 still active, move in rapid, only in the X axis, to the absolute position of X3.0

(9) Y-.5
With G0 G90 still active, move in rapid, only in the Y axis, to the absolute position of Y-.5

(10) X.5
Back to the G54 X0 Y0 origin of our part.

(11) G28 X0 Y0 Z0
Rapid move to reference point (Machine home).

Make It Cut!

1.We want to “make the connection” (I’ll explain next)
2.We want to draw a square with the tool
3.We then want to translate that square into a cutting path

If we want to make our machine preform a cutting action, we need to use three more descriptor in our program.
F = Feed Rate (IPM or mm/min)
S = Spindle speed (RPM)
M = Miscellaneous

In order to create a block that will use these correctly, we need to give each of these descriptors a specific value.

N006 G0 G90 X0 Y-.5 S2200 M3
N007 G01 X.5 F30.

This is the exact same motion command from before, except the N006 block turns the spindle on, it also moves just shy of the point before, this is our “entry move”.

With the spindle on now, N007 tells the machine to move with linear interpolation at a feed rate of 30.


Example Program With Cutting

N001 G90 G80 G40 G54 G20 G17 G50 G94 G64 (safety block)
N003 M06 T1
N004 G54 G00 X-.5 Y-.5
N005 G43 Z1.0 H1
N006 G0 G90 X0 Y-.5 S2200 M3
N007 G01 X.5 F30.
N008 Y-2.0
N009 X3.0
N0010 Y-.5
N0011 X.5
N0012 G28 X0 Y0 Z0

Image

Let’s read it:

G90 G80 G40 G20 G17 G50 G94 G6
Safety Block: Absolute mode, Cancel all fixed cycles, Cancel cutter compensation, cutting plane X, Y, Feed rate IPM.

M06 T1
Automatic tool changer, load Tool 1

(4) G54 G00 X-.5 Y-.5
Using the G54 offset from the MCU, move to absolute X-.5 Y-.5.

(5) G43 Z1.0 H1
Rapid move tool 1 to 1.0 inch above part. 
(With proper Machine coordinates, the tool should move –Z down towards the part and stop 1.0 inch above G54 X0 Y0)

(6) G0 G90 X0 Y-.5 S2200 M3
Using rapid positioning (aka moving in rapid), using absolute positioning mode, move in both the x and y axis to X0 Y-.5.  Also, start machine spindle and set speed at 2200, in the clock wise direction. 

(7) G01 X.5 F30.
Using linear interpolation motion, at a feed rate of 30 IPM, using absolute positioning mode, move to X.5

(8) Y-2.0
With G01 G90 still active, move at 30 IPM with the sindle on, only in the Y axis to the absolute position of Y-2.0.

(9) X3.0
With G01 G90 still active, move at 30 IPM with the sindle on, only in the X axis to the absolute position of X-2.0.

(10) Y-.5
With G01 G90 still active, move at 30 IPM with the sindle on, only in the Y axis to the absolute position of Y-.5.

(11) X.5
Back to the G54 X0 Y0 origin of our part.

(12) G28 X0 Y0 Z0
Rapid move to reference point (Machine home).


Final Note: Safety

We both know that computers are only as smart as we direct them to be, so in order to keep our fingers, we need to be detailed about what we direct the machine to do. 

In todays manufacturing environment, a majority of the programs are created via CAM software, which makes avoiding position based errors much easier.

But there are two techniques that still should be used in order to stay safe. 

1.Safe lines or reset blocks.

2.Program comments.

(Comments are just that, comments to the machinist, engineer, operator, that are not read by the machine.  They Allow the programmer to communicate with other humans, and even remind our own stupid selves some times.)  Typically you just use () to comment.

Safe line / reset line (examples above):  Is a block that you should definitely consider placing at the top of your program.  This is a part  of always remembering modality… and always remembering to cancel modality too.

A good example of when you would use a reset/cancel within a program:  (G83 X22. Y8. Z-14 R2.5 Q3 F90 peck drill cycle) will continue to run at every subsequent location, until you to cancel with a G80.


Thank You

Thank you for stopping by and reviewing G-code with me.  This a crucial skill in manufacturing, especially concerning machining and (c)NC programming. 

-Micah

Don’t have time to read the whole guide right now?

No worries. Let me send you a copy so you can read it when it’s convenient for you.

Just let me know where to send it (takes 5 seconds):

Yes! Give me my PDF
Image