You are on page 1of 3

Lesson Five: G Code Commonalities

G Code Commonalities
As you know, G codes are preparatory functions. They prepare the control for what is
coming - in the current command, or in future commands. Most G codes are modal,
meaning they will remain active until they are changed or canceled. All motion types, for
example, are modal. Once you instate a straight line cutting motion (G01) in one
command, you need not include a G01 in every consecutive straight line motion
command.
Some G codes, on the other hand are non-modal or one-shot G codes. These special G
codes only take effect in the single command in which they are included. The zero return
command (G28), for instance, is a non-modal G code. If two or more consecutive
commands are given to send axes to their zero return position, a G28 must be included in
each command.
Before we get specific and discuss each individual G code, we need to introduce some
things that G codes share in common. Weve already mentioned, for example, modal and
non-modal G codes. There are several important points that are commonly left out of
basic CNC courses.
Maximum number of G codes per command
All controls limit the number of G codes you can include in one command. Most Fanuc
controls, for example, allow but three compatible G codes per command. By compatible,
we mean the G codes must be able to work together. You cannot, for instance, include a
G00 rapid motion word in the same command with a G01 straight line motion word.
You must understand that when you include more than three G codes in the same
command, most controls will not actually generate an alarm. Instead, they will simple
execute the last three (rightmost three) G codes. Any prior to them will be ignored.
Ensuring initialized states with safety blocks
Certain G codes are initialized, meaning they are automatically instated during the
machines power-up procedure. For certain functions, youll have the ability to change
the G code that is initialized. If, for example, you work exclusively in the inch mode,
youd want the machine initializing in the inch mode. If you work exclusively in metric
mode, youd want the machine initializing in metric. You can also manipulate whether
the machine comes on in incremental or absolute mode (G91 or G90), and rapid or
straight line cutting mode (G00 or G01). Control parameters are used to specify which of
these G codes is initialized.
Many programmers depend upon these G codes being as they were at power-up when
their programs are run. This can be a nasty mistake. I constantly get a call for help that
goes something like this:
Customer: Mike, my CNC turning center is barely creeping along in a cutting motion. I
notice the position display going 1..... 2...... 3......, and this is the tenths register of the
position display page. Ive programmed the machine to go at 0.015 inches per revolution
and the spindles running at 600 rpm. It should be cutting much faster!
Me: Oh - youve been trying to use sub-programming commands.

Lesson Five: G Code Commonalities


Customer: Yeah - how did you know?
Me: You meant to enter M98 to call the subprogram, but instead typed G98.
Customer: Yeah, but I found the mistake and changed the G98 to an M98. The subprogramming command works just fine now.
Me: Yes, but when you specified the modal G98 command, you put the machine in
inches per minute mode. Instead of taking your F0.015 feedrate as 0.015 per revolution,
its taking it as 0.015 per minute!
Customer: Oh. So all I have to do is command G99 (inches per revolution mode) and it
will fix my problem.
This is but one example of when assuming the machine is in the initialized states (G99 in
this case) will lead to problems. Others include inch/metric selection, mirror image, and
just about any coordinate manipulator command like rotation and scaling. If you include
a series of commands at the beginning of your program that set these modes (even if they
are initialized), you can ensure that the machine will be in the appropriate states as your
program is run.
Remember that most Fanuc controls have a limitation when it comes to how many G
codes can be in a command. Most allow but three compatible G codes, meaning youll
probably have to break up your safety command into two or more commands. Also, most
controls wont generate any kind of alarm if you break this rule. Theyll simply ignore
all but the last three G codes in the command - so you wont even know that youve
broken a rule.
Here is an example of safety blocks for a Fanuc-controlled CNC turning center. Again,
were simply ensuring that all G code states are as they were at power-up.
O0001 (Program number)
N005 G20 G23 G40 (Select inch mode, cancel stored stroke limit, cancel tool
nose radius compensation)
N010 G99 (Select feed per revolution mode)
N015 T0101 (Index turret)
N020...
.
.
.
Here is an example for a Fanuc-controlled machining center.
O0001 (Program number)
N005 G17 G20 G23 (Set XY plane, inch mode, cancel stored stroke limit)
N010 G40 G50 G64 (Cancel cutter radius comp, cancel scaling, select normal
cutting mode)
N015 G67 G69 G80 (Cancel modal custom macro call, cancel rotation, cancel
canned cycle)
N020 T01 M06 (Tool change)
N025 ...
.

Lesson Five: G Code Commonalities


.
.
Monitoring the current state of G codes
Whenever the machine is behaving in an erratic manner (as the turning center inches per
revolution/minute example stressed), its important to know about one feature of the
program check page. On this page you can view all currently instated G codes. While
the machine is doing something you dont understand, look at this list of G codes. Its
likely that youll spot the one causing the problem - and remember how the machine got
into that state. Note that when theyre having any sort of odd problem, many CNC
people simply turn of the power and turn it back on again. Since the machine comes back
on in the initialized states, many problems will go away. While this works, youll never
know what caused the problem!
Understanding G code groups
As stated, you are allowed up to three compatible G codes per command with most Fanuc
and Fanuc-compatible controls. By compatible, we mean the G codes must be able to
work together. More explicitly, the G codes cannot be in the same group. G00, G01,
G02, and G03, for example, are in group number one. Fanuc (and most control
manufacturers) group their G codes in this fashion for at least two reasons. The first is to
ensure that you know when youre breaking the compatible G code rule. But more
importantly, only one G code in a group can be active at a given time. This will have
important implications when we discuss parametric programming, since with it, you have
the ability in your program to access the currently active G code within any group.
Youll be able to determine, for example, whether tool length compensation is instated
(important when using a spindle probe), whether the machine is in incremental or
absolute mode, or which motion type is currently instated.

You might also like