Every
CNC programmer and most of CNC machine operators have a simple chart of all
common G-commands (G-codes) and M-functions (M-codes), usually tucked away
somewhere under the lid of their tool box or they have them posted on any
convenient machine side or cork board. This chapter covers most of those
G-codes that are either uncommon, seldom used, special, or outright mysterious.
Keep in mind that machine manufacturers often add G-codes and M-codes of their
own. These special codes or functions cannot be covered in a general
publication, such as this handbook.
Miscellaneous
functions (M-functions) are not covered here at all, as they are often very
much dependent on the machine tool manufacturer - for that reason, they are not
part of this chapter. The situation is much different with various G-codes,
some standard, some optional - they are covered here.
These
special and less frequently used G-codes are as important as those used on a
daily basis, even if only as accepting them for possible future use.
Programmers often forget that there are many preparatory commands available
that are not used very frequently. In this chapter, the focus will be on those
G-codes that may sometimes become the key to solving a particular problem or
achieving a particular programming goal. Some of these preparatory G-codes have
a direct relationship with each other, in which case, all related commands will
be considered together and explained together.
Divided
into seven groups, seventeen preparatory commands covered in this chapter are:
I
n the
earlier section describing the G27 command, a small example of the G92 command
was presented. On the lathes, the most common equivalent command is G50. Both
these commands are considered obsolete by any modern standards - they have been
replaced by the much more flexible work offsets G54-G59. The reason there is at
least a miniature version of these commands described here, came from the many
requests to cover this feature for the users who still work with older
controls.
All
machines that support work offsets also support G92, mainly for the
compatibility with older programs. This statement - while correct - also
requires a word of caution first:
Yes,
it is possible to mix work offsets with position register commands in the same
program, but it can cause more headaches than it's worth. The most common
definition for G92/G50 is
position
register command
. What does it
really mean? Keep in mind these commands are dated
before
any work offsets existed, although the G43
command for tool length offset was already available. While work offset is
always measured from machine zero to part zero along an axis (usually as a
negative dimension), position register is measured from part zero to machine
zero (usually as a positive dimension). That is an important difference, but
not really the major difference between the two methods of coordinate setting.
The major difference is in the respective applications of both command types:
•
Position register G92/G50 is set in the program for each tool
…actual dimensions
for each axis must be known during program development
•
Work offsets G54-G59 are set at the machine and only called by
the program
…actual dimensions
are not known during program development
•
Tool length offset G43 is set in the program for both G92 and
G54-G56 (mill controls only)
... actual
dimensions are not known during programming
In
summary, there is only one -
and
only one
- reason for either
G92 or G50 command in the program:
G92 X195.0 Y88.0 Z20.0 (POSITION REGISTER COMMAND
- THREE AXES SELECTED)
In
this block, the programmed data
'tell'
the control that the tool
current position is located 195 mm from the part zero along the X-axis, 88 mm
along the Y-axis, and 20 mm along the Z-axis.
The
major problem with position register commands is the fact that for most setups,
the programmer has no way of knowing where exactly the tool is located. In
order to make this feature work, several rather elaborate methods have been
devised, to shorten the setup time. Programmers soon found out that it is
easier to leave the G92 block in the program empty and let the operator to
fill-in the data, based on actual setup. However, this method had only been
possible when software based CNC systems replaced the hardwired NC systems. Of
course, work offsets have solved this problem for all but those users who still
have no choice but to program in the very old fashioned way.
G92 Position Register for Milling
Some
older CNC lathes also accept G92 as the position register command, but
generally G92 is used for milling, while G50 is used for turning. The best way
to illustrate the G92 command is to use it in a program with two tools and
follow its settings from one tool to the next. The illustration below shows top
and front setup of a simple part.
Note
the arrow directions and the dimensions required by setup.
A
suitable spot drill and a
_
5 mm drill will be programmed to machine the two
holes shown. The first tool -
spot
drill
- starts from machine
zero. This position is a normal start for any first tool, because the machine
has to be zeroed for every setup at startup. When the tool is located at
machine zero, the CNC operator must set the part zero
exactly
300 mm along the X-axis and 200 mm along the
Y-axis. These are the main conditions of G92 command -
this is how G92 works!
Based
on extensive experience of many users, this setup task is virtually impossible to
do at the machine, with any degree of precision - at least in a reasonable time
frame. However, that was -
and
still is, if necessary
- the
main drawback of G92.
The
following programming example is based on the provided setup, including both
tools, with appropriate comments:
N1 G21
N2 G17 G40 G80 G90 T01
N3 M06 (SPOT
DRILL)
N4 G92 X300.0 Y200.0 Z0 S1200 M03 T02 (CURRENT
TOOL AT MACHINE ZERO)
N5 G00 X20.0 Y15.0 (FIRST
HOLE LOCATION)
N6 G43 Z10.0 H01 M08 (TOOL
10 MM ABOVE WORK)
N7 G92 Z10.0 (CURRENT
TOOL POSITION REGISTERED)
N8 G99 G82 R2.0 Z-2.75 P200 F120.0 (SPOT
DRILL AT CURRENT LOCATION)
N9 X80.0 Y45.0 (SECOND
HOLE LOCATION)
N10 G80 Z10.0 M09 (CYCLE
COMPLETED)
N11 G28 Z10.0 M05 (ONLY
Z-AXIS TO MACHINE ZERO)
N12 M01
After
the first tool in the program (T01 is the spot drill in the example) completes the
machining operation, the location of th T01 is critical within G92 environment and
must always be known. Based on the program developed so far, the tool T01 is located
at X80.0 Y45.0, when block N12 is processed. The tool T01 is also located at
machine zero in the Z-axis.
The
illustration at right shows the
current
tool position of T02, which
replaced tool T01 during automatic tool change.
Following
the normal rules, G92 command data must contain the current tool location - as
it relates to part zero. In this programming example, the second tool T02 is
located exactly at the same XY position as the previous tool T01, so no special
programming effort is necessary. If G92 for the X and Y coordinates is used in
the program, its values will be:
G92 X80.0 Y45.0 Z0 (CORRECT BUT UNNECESSARY
SETTING)
The
remainder of the program can now be written, considering the settings described
so far:
N13 T02
N14 M06 (5
MM DRILL)
N15 G90 G92 Z0 (CANCEL
Z-AXIS SETTING)
N16 G00 G43 X80.0 Y45.0 Z10.0 H02 M08 (MOVE
TO SECOND HOLE 10 MM ABOVE)
N17 G92 Z10.0 S1350 M03 (CURRENT
TOOL POSITION REGISTERED)
N18 G99 G81 R2.0 Z-12.5 F150.0 (DRILL
AT CURRENT LOCATION)
N19 X20.0 Y15.0 (FIRST
HOLE LOCATION)
N20 G80 Z10.0 M09 (CYCLE
COMPLETED)
N21 G28 Z10.0 M05 (ONLY
Z-AXIS TO MACHINE ZERO)
N22 G28 X20.0 Y15.0 (=>
WHAT IS THE G92 AT THIS BLOCK?)
N23 M30
%
Of
course, the comment in block N22 is unnecessary, but included here anyway -
what is the current tool position?
Since the current tool T02 is located at machine
zero, it means it is located 300 mm and 200 mm respectively, along the X and Y
axes -
from part
zero.
The Z-axis is the
original setting as determined by the tool length.
G50 Position Register for Turning
The
G50 command shares most programming features with its G92 cousin - its
definition, its purpose, and its method of programming. The only visible
difference in the program is the axes designation as X and Z rather than X, Y
and Z. Although an obsolete command, many older programs do contain this type
of tool setting and still use it. The part programmer should convert the
program to the modern method, which is very easy - just eliminate the G50 X..
Z.. reference. For those who still need to work with the G50 position register,
here is an example that should make its use clearer.
To
illustrate the G50 concept, a simple drawing shown at right will be used for the
example. For actual machining, three typical and unique tools will be selected,
to show the various G50 relationships:
T01 = 80
_
Turning tool
T02 =
_
18 mm Drill
T04 =
_
16 mm Boring bar
For
simplicity (and better clarity), only the necessary toolpath will be covered in
the program. Facing and center-drilling operations have been skipped. Spindle speeds
and cutting feedrates are only reasonable and
not
important
at this time.
Tool Change Position
During
tool change, it is quite common on a CNC lathe to move the current tool to a
safe position away from the part, but not necessarily to machine zero. A
variation on the same topic will be a tool change at machine zero in the X-axis
only - but close to the part in the Z-axis. The main reason is that the X-axis
travel is much shorter than the Z-axis travel on most machines. Also, this
method adds to the safety aspects of the automatic tool change process by
adding additional clearance. This is also the programming method used in the
examples provided in this chapter.
The
above safety message applies to any type of lathe programming, not just when
the G50 is used.
Initial Data
Unlike
the modern programming method, using G50 means using several dimensions known
to the part programmer. These dimensions relate to the CNC lathe itself, as
well as to all tools used in the program. The schematic illustrations on the
next page show dimensional data for the CNC lathe used for this example, with
attached chuck, jaws and turret
without
and with
tools. The dimensions
used are realistic but
not
to scale
, and are always
known from the data supplied by the lathe manufacturer.
The
first piece of the 'puzzle' defines the fixed machine dimensions provided by
the manufacturer, when the empty tool turret is located at machine zero. If the
Z-dimension is given to the chuck face, just add the width of the standard jaws
for all related calculations. The width of the part is included in the
illustration as part of the current setup,
not
part
of the machine specifications.
When
the cutting tools are mounted in the turret, their
d
imensions must also be known
to the CNC programmer. This is the program
section that makes the G50 programming method very inconvenient and perhaps
even
hard
in some opinions (by today's standards).
As
there are three tools used by the program, the critical dimensions of each tool
must be known
before
the actual program can be
written. The illustration above shows the critical dimensions for tool T01
(turning tool) that are important to the overall setup and related program
development.
The
remaining two illustrations that follow show the equivalent
critical
dimensions -
also known when the program is written
- for the other two tools used by the program.
Note that the data for all three tools listed are dimensioned from machine
zero, and their X/Z dimensions are always known.
From
the CNC programmer's viewpoint, once the individual tool dimensions are known
relative to the provided machine and part dimensions, the program using the
position register command G50 can be written and used for tool change at any
reasonable location.
Tool Change Position
It
is not necessary to return to machine zero after each tool has completed its
work. The travel can be unnecessarily long, particularly along the Z-axis. That
means the programmer has to select a tool change position for each tool. The
basic rule (as defined earlier) is to make sure that the minimum clearance is
applied to the longest tool. If the longest tool has enough clearance, every
other tool will have even more clearance.
For
the purposes of comparison, this example will be presented in two stages - in
the first stage, each tool change will be at machine zero (easier but less
efficient), the second stage will show how the tool change can be done close to
the part in Z-axis (the shorter X-axis will still be done at machine zero position).
Tool Change at Machine Zero
In
this case, the longest tool length is not important, as machine zero position
is a fair distance from the part. The following program is listed in the order
of described tools - T01, T02, T04:
N1 G21 (METRIC
UNITS)
N2 T0100 (TOOL
01 LOCATED AT MACHINE ZERO)
N3
G50
X160.0 Z303.0
(O.D. TOOL TIP POSITION
FROM PART ZERO)
N4 G96 S120 M03 (SPINDLE
SPEED AND ROTATION)
N5 G00 G42 X52.0 Z3.0 T0101 M08 (CHAMFER
START POINT)
N6 G01 X58.0 Z-1.0 F0.125 (FRONT
CHAMFER)
N7 Z-25.0 F0.3 (OUTSIDE
DIAMETER CUTTING)
N8 X63.0 (FACE
CUTTING)
N9 X67.0 Z-27.0 F0.125 (REAR
CHAMFER)
N10 U5.0 F0.5 (CLEARANCE
RETRACT)
N11 G00 G40
X160.0 Z303.0
T0100 (RETURN TO THE MACHINE ZERO
POSITION)
N12 G27 X160.0 Z303.0 (CHECK
IF THE TOOL IS AT MACHINE ZERO)
N13 M01 (OPTIONAL
STOP)
N14 T0200 (TOOL
02 LOCATED AT MACHINE ZERO)
N15
G50
X160.0 Z263.0
(DRILL TIP POSITION FROM
PART ZERO)
N16 G97 S900 M03 (SPINDLE
SPEED AND ROTATION)
N17 G00 X0 Z5.0 T0202 M08 (START
LOCATION FOR DRILLING)
N18 G01 Z-47.0 F0.375 (END
LOCATION FOR DRILLING)
N19 G00 Z5.0 (RETURN
BACK TO START LOCATION)
N20
X160.0
Z263.0
T0200
(RETURN TO THE MACHINE ZERO POSITION)
N21 G27 X160.0 Z303.0 (CHECK
IF THE TOOL IS AT MACHINE ZERO)
N22 M01 (OPTIONAL
STOP)
N23 T0400 (TOOL
04 LOCATED AT MACHINE ZERO)
N24
G50
X182.0 Z267.0
(BORING BAR TIP POSITION
FROM PART ZERO)
N25 G96 S110 M03 (SPINDLE
SPEED AND ROTATION)
N26 G00 G41 X30.0 Z3.0 T0404 M08 (CHAMFER
START POINT)
N27 G01 X22.0 Z-1.0 F0.125 (FRONT
CHAMFER)
N28 Z-42.0 F0.25 (INSIDE
DIAMETER CUTTING)
N29 U-5.0 (CLEARANCE
RETRACT)
N30 G00 Z3.0 (RETRACT
FROM THE HOLE)
N31 G40
X182.0 Z267.0
T0400 (RETURN TO THE MACHINE
ZERO POSITION)
N32 G27 X182.0 Z267.0 (CHECK
IF THE TOOL IS AT MACHINE ZERO)
N33 M30 (END
OF PROGRAM)
%
Note
the inclusion of G27 command - it checks if the current tool position is
actually at machine zero. In a way, the command in this program is redundant,
but at least it brings some piece of mind - for example, if there is an error
in the data input (data entry error). The G27 command has been described earlier
in this chapter.
Tool Change Close to the Part
When
the tool change takes place close to the part, the longest tool length
is
important. In the example used, the longest tool
is the drill, with 47 mm overhang. The programmer selects any suitable clearance
- for the example, 50 mm Z-clearance will used for the longest tool (T02). That
means a very special care must be taken to program the G50 coordinates for all
other tools. When the G50 method was the only method available to establish the
current tool position, this particular reason was the weakest point of the
whole concept. CNC programmers often resorted to the method of returning all
tools to machine zero when each operation was completed. Convenience won over
efficiency.
As
the tool does not return back to the machine zero position, there is no need
for the G27 command in this version. Although only the Z-clearance is shown,
X-clearance will work the same way.
The
last program will not change in
any
way
that relates to the
toolpath and cutting conditions. Only the G50 will change, based on the current
tool position. Watch the underlined settings carefully - even when combined
with the illustrations, this subject may take a while to fully understand. The most
difficult part of this programming method is to determine the G50 position of
the next tool, relative to the position of the current tool. For safety reasons,
tool change position of any tool must be at least 50 mm away from the front
face of part, that is from Z0. The result is a guarantee that no tool will be
located behind the chuck during tool change, causing a possible collision.
In
a summary, each tool will make a tool change at the exact location of the
longest tool. However, because the length of each tool is different, the G50
Z-setting will also be different to maintain this minimum clearance position.
The
calculation of the G50 at the tool change position of any tool considers the
known settings:
For
the first tool, the formula can be used with exact dimensions:
G50 = 303
_
263
_
50 = 90 = G50 X..
Z90.0
The
longest tool (T02) total distance is 263 mm, and the clearance from Z0 for that
tool is 50 mm. The program for the first tool still originates at machine zero,
but terminates at a Z90.0 tool change position:
N1 G21 (METRIC
UNITS)
N2 T0100 (TOOL
01 LOCATED AT MACHINE ZERO)
N3
G50
X160.0 Z303.0
(O.D. TOOL TIP POSITION
FROM PART ZERO)
N4 G96 S120 M03 (SPINDLE
SPEED AND ROTATION)
N5 G00 G42 X52.0 Z3.0 T0101 M08 (CHAMFER
START POINT)
N6 G01 X58.0 Z-1.0 F0.125 (FRONT
CHAMFER)
N7 Z-25.0 F0.3 (OUTSIDE
DIAMETER CUTTING)
N8 X63.0 (FACE
CUTTING)
N9 X67.0 Z-27.0 F0.125 (REAR
CHAMFER)
N10 U5.0 F0.5 (CLEARANCE
RETRACT)
N11 G00 G40
X160.0 Z90.0
T0100 (RETURN TO THE TOOL
CHANGE POSITION)
N12 M01 (OPTIONAL
STOP)
The
second tool - T02 - is also the longest tool, therefore its G50 Z.. must be G50
Z50.0. The formula listed above applies equally for this tool as well:
G50 = 263
_
263
_
50 = 50 = G50 X..
Z50.0
The
program listing for the second tool shows the setting at the program beginning
(block N14) and the return motion block N19, using the same coordinates.
N13 T0200 (TOOL
02 LOCATED AT TOOL CHANGE POSITION)
N14
G50
X160.0 Z50.0
(DRILL TIP POSITION FROM
PART ZERO)
N15 G97 S900 M03 (SPINDLE
SPEED AND ROTATION)
N16 G00 X0 Z5.0 T0202 M08 (START
LOCATION FOR DRILLING)
N17 G01 Z-47.0 F0.375 (END
LOCATION FOR DRILLING)
N18 G00 Z5.0 (RETURN
BACK TO START LOCATION)
N19
X160.0
Z50.0
T0200
(RETURN TO THE TOOL CHANGE POSITION)
N20 M01 (OPTIONAL
STOP)
When
the original drawing was presented and three tools had been selected, there was
a good reason for such a selection. In terms of the program structure, every
first tool of the program represents program formatting at beginning (of the
first tool), every second tool represents the formatting for all tools between
the first one and the last one (the second tool), and the third tool represents
the last tool format.
When
this method is applied to the G50 X.. Z.. position register command, the
original intent remains the same - the G50 for any middle tool (all tools after
the first and before the last) will start and end at the same position - see
above illustration.
The
last tool (see program and illustration on the next page) is always treated
somewhat differently, and programmer's preferences may not work here very well.
When the last tool has completed all machining, the programmer may choose to
return the tool to the tool change position, as any previous tool -
this is a wrong decision
. Returning the tool to a position other than
machine zero means inconsistency between the position of the last tool for one
part, and the position of the first tool for the next part. Since the program
is written in such a way that the first tool starts from machine zero, the last
tool
must
return to the same position - that means to
machine zero. The suggestion is simple:
Based
on the explanation for programming the first and last tool, the boring bar
(T04) - the last tool from the example - can be programmed.
N21 T0400 (TOOL 04 LOCATED AT TOOL CHANGE
POSITION)
N22
G50
X182.0 Z54.0
(BORING
BAR TIP POSITION FROM PART ZERO)
N23 G96 S110 M03 (SPINDLE SPEED AND ROTATION)
N24 G00 G41 X30.0 Z3.0 T0404 M08 (CHAMFER START
POINT)
N25 G01 X22.0 Z-1.0 F0.125 (FRONT CHAMFER)
N26 Z-42.0 F0.25 (INSIDE DIAMETER CUTTING)
N27 U-5.0 (CLEARANCE RETRACT)
N28 G00 Z3.0 (RETRACT FROM THE HOLE)
N29 G40
X182.0 Z267.0
T0400 (RETURN TO THE MACHINE ZERO POSITION)
N30 G27 X182.0 Z267.0 (CHECK IF THE TOOL IS AT
MACHINE ZERO)
N31 M30 (END OF PROGRAM)
%
Only
the last tool returns to the machine zero position, so the G27 command is
justified, if required.
Conversion of G50 to Geometry Offset
Although
the word 'conversion' in the title may seem a bit overstated (there is no
actual conversion), how do we change a program listing that contains G50 to the
modern method of programming, using
Geometry
and
Wear
offsets? Simple - take the G50 and its related
blocks out of the program altogether. Here is the same program as listed above,
but using the modern method -
no
G50 at all
. Study it carefully,
particularly the tool position at the end of each tool - it offers a reasonable
position to provide a clearance for the tool change, considering all tools.
N1 G21 (METRIC
UNITS)
N2 T0100 (TOOL
01 LOCATED AT MACHINE ZERO)
N3 G96 S120 M03 (SPINDLE
SPEED AND ROTATION)
N4 G00 G42 X52.0 Z3.0 T0101 M08 (CHAMFER
START POINT)
N5 G01 X58.0 Z-1.0 F0.125 (FRONT
CHAMFER)
N6 Z-25.0 F0.3 (OUTSIDE
DIAMETER CUTTING)
N7 X63.0 (FACE
CUTTING)
N8 X67.0 Z-27.0 F0.125 (REAR
CHAMFER)
N9 U5.0 F0.5 (CLEARANCE
RETRACT)
N10 G00 G40 X150.0 Z100.0 T0100 (RETURN
TO A SAFE TOOL CHANGE POSITION)
N11 M01 (OPTIONAL
STOP)
N12 T0200 (TOOL
02 LOCATED AT TOOL CHANGE POSITION)
N13 G97 S900 M03 (SPINDLE
SPEED AND ROTATION)
N14 G00 X0 Z5.0 T0202 M08 (START
LOCATION FOR DRILLING)
N15 G01 Z-47.0 F0.375 (END
LOCATION FOR DRILLING)
N16 G00 Z5.0 (RETURN
BACK TO START LOCATION)
N17 X150.0 Z50.0 T0200 (RETURN
TO A SAFE TOOL CHANGE POSITION)
N18 M01 (OPTIONAL
STOP)
N19 T0400 (TOOL
04 LOCATED AT MACHINE ZERO)
N20 G96 S110 M03 (SPINDLE
SPEED AND ROTATION)
N21 G00 G41 X30.0 Z3.0 T0404 M08 (CHAMFER
START POINT)
N22 G01 X22.0 Z-1.0 F0.125 (FRONT
CHAMFER)
N23 Z-42.0 F0.25 (INSIDE
DIAMETER CUTTING)
N24 U-5.0 (CLEARANCE
RETRACT)
N25 G00 Z3.0 (RETRACT
FROM THE HOLE)
N26 G40 G28 U0 W0 T0400 (RETURN
TO THE MACHINE ZERO POSITION)
N27 M30 (END
OF PROGRAM)
%
Summary
In
a summary, the G50 command is very impractical and inefficient but it reflect
the progress of its time - yes, it was a great progress, in spite of the
appearances. Its main disadvantage is quite obvious - many dimensions must be
known to the part programmer at the time of program development, which creates
a situation not always practical or even possible. Repeating a tool is often
very difficult and the whole concept is prone to many errors. Yet, millions of
parts have been machined with the G50 used in the program.
Copyright © 2006
Industrial Press Inc.