0% found this document useful (0 votes)
95 views

05 CNC Milling Programming 4 in 1 Page

The document discusses five categories of programming commands and techniques for maximizing the power of modern CNC milling machines: 1. Basic programming commands such as motion, plane selection, positioning, and unit selection. 2. Compensation and offset functions used to define work coordinate systems and accommodate tool differences. 3. Fixed cycles that execute repetitive machining operations with a single block command in standard, special, and user-defined cycles. 4. Macro and subroutine programming features that allow implementing repetitive patterns and complex shapes through variables, arithmetic, and logic. 5. Advanced programming features like scaling, rotation, and mirroring to simplify programming effort and reduce time and size.

Uploaded by

dsdvd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

05 CNC Milling Programming 4 in 1 Page

The document discusses five categories of programming commands and techniques for maximizing the power of modern CNC milling machines: 1. Basic programming commands such as motion, plane selection, positioning, and unit selection. 2. Compensation and offset functions used to define work coordinate systems and accommodate tool differences. 3. Fixed cycles that execute repetitive machining operations with a single block command in standard, special, and user-defined cycles. 4. Macro and subroutine programming features that allow implementing repetitive patterns and complex shapes through variables, arithmetic, and logic. 5. Advanced programming features like scaling, rotation, and mirroring to simplify programming effort and reduce time and size.

Uploaded by

dsdvd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

To maximize the power of modern CNC

‫دا ه ﯽ اراک‬
milling machines, a programmer has to
master the following five categories of
‫ وه ﺳﺎ ﺖ و ﻮ ﯿﺪ‬-‫دا ه ﻣ ﮑﺎ ﯿﮏ‬
programming command codes and
techniques:
1. Basic programming commands.

CNC Milling Programming 2. Compensating an offset.


3. Fixed cycles.
4. Macro and subroutine programs.
5. Advanced programming features.

‫ک‬1 ‫دا ه ﯽ ارا‬ 2

1. BASIC PROGRAMMING COMMANDS. 2. COMPENSATION AND OFFSET. The use of


compensation and offset functions in defining work
• Motion commands (G00, G01, G02, G03) coordinate systems, performing tool diameter
• Plane selection (G17, G18, G19) compensations, and accommodating tool length differences
often results in reduced programming effort. The main
• Positioning system selection (G90, 091) compensation and offset functions are
• Unit selection (G70 or G20, G71 or G21)
• Work coordinate compensation (G54-G59)
• Work coordinate setting (G92)
• Tool diameter (radius) compensation (G40, G41, G42)
• Reference point return (G28, G29, G30)
• Tool length offset (G43, G44, G49)
• Tool selection and change (Txx M06) 3. FIXED CYCLES. The purpose of a fixed cycle is to
• Feed selection and input (Fxxx.xx, G94, 095) execute a series of repetitive machining operations with a
single block command. Fixed cycles may be classified into
• Spindle speed selection and control (Sxxxx, M03, M04, the following three categories:
M05)
• Standard fixed cycles (G80-G89)
• Miscellaneous functions (M00, M01, M02, M07, M08, M09,
M30) • Special fixed cycles
3 • User-defined fixed cycles 4
4. MACRO AND SUBROUTINE PROGRAMMING. Most
modem CNC controls furnish the power of computer CNC MILLING G-CODES
programming to define variables, perform arithmetic
operations, execute logical decisions, and so on. These
features allow easy implementation of repetitive
machining patterns and complex workpiece shapes that G-codes are preparatory functions that involve actual
can be defined mathematically. tool moves (for example, control of the machine). These
include rapid moves, feed moves, radial feed moves,
5. ADVANCED PROGRAMMING FEATURES. These
dwells, and roughing and profiling cycles.
commands are dependent on user control. They are
used to simplify programming effort and reduce
programming time and program size. Typical features Most G-codes described here are modal, meaning that
include scaling, rotation, and mirror image. they remain active until canceled by another G-code.
The following codes are described in more detail in the
following sections.

5 6

CNC MILLING G-CODES CNC MILLING G-CODES


G00 Positioning in rapid Modal G21/G71 Metric units Modal
G01 Linear interpolation Modal G28 Automatic return to reference point
G02 Circular interpolation (CW) Modal G29 Automatic return from reference point
G03 Circular interpolation (CCW) Modal G40 Cutter compensation cancel Modal
G04 Dwell G41 Cutter compensation left Modal
G17 XY plane Modal G42 Cutter compensation right Modal
G18 XZ plane Modal G43 Tool length compensation (plus) Modal
G19 YZ plane Modal G44 Tool length compensation (minus) Modal
G20/G70 Inch units Modal G49 Tool length compensation cancel Modal

7
G54-G59 Workpiece coordinate settings Modal 8
CNC MILLING G-CODES CNC MILLING G-CODES
G73 High-speed peck drilling Modal
G94 Feed per minute
G80 Cancel canned cycles Modal
G95 Feed per revolution
G81 Drilling cycle Modal G98 Set initial plane default
G82 Counter boring cycle Modal G99 Return to retract (rapid) plane
G83 Deep hole drilling cycle Modal
G84 Tapping cycle
G85 Boring cycle Modal
G90 Absolute positioning Modal
G91 Incremental positioning Modal
G92 Reposition origin point
9 10

CNC Milling M-CODES


M05 Spindle stop
CNC Milling M-CODES M06 Tool change
M-codes are miscellaneous functions that include actions necessary fo
M08 Coolant on
machining but not those that are actual tool movements. That is, they are
auxiliary functions, such as spindle on and off, tool changes, coolant on M09 Coolant off
and off, program stops, and similar related functions. The following code M10 Clamps on
are described in more detail in the following sections. M11 Clamps off
M00 Program stop
M30 Program end, reset to start
M01 Optional program stop M98 Call subroutine command
M02 Program end M99 Return from subroutine command
M03 Spindle on clockwise
Block Skip Option to skip blocks that begin with ‘/’
M04 Spindle on counterclockwise
Comments Comments may be included in blocks
with round brackets ‘(’ ‘)’
11 12
Tool Motion Command - G00 Positioning in Rapid
Format: N_ G00 X_ Y_ Z_
The G00 command is used to move the tool
quickly from one point to another without cutting,
The G00 command is a
rapid tool move. A rapid tool
thus allowing for quick tool positioning.
move is used to move the
tool linearly from position to
position without cutting any
material. This command is
not to be used for cutting
any material, as to do so
would seriously damage the
tool and ruin the workpiece.
It is a modal command,
remaining in effect until
canceled by another G-Code
command
13 14

The G00 rapid move should have two distinct As this diagram shows, if the basic rules are not
movements to ensure that vertical moves are always followed, an accident can result. Improper use of
separate from horizontal moves. In a typical rapid move
G00 often occurs because clamps are not taken
toward the part, the tool first rapids in the flat,
horizontal XY plane. Then, it feeds down in the Z axis. into consideration. Following the basic rules will
When rapiding out of a part, the G00 command always reduce any chance of error.
goes up in the Z axis first, then laterally in the XY plane.

15 16
Sample Program :
Workpiece Size: X6,Y4,Z1
EXAMPLE: Tool: Tool #2, 1/4" Slot Drill
N25 G00 X2.5 Y4.75 (Rapid to X2.5,Y4.75) Tool Start Position: X0,Y0,Z1
N30 Z0.1 (Rapid down to Z0.1) % (Program start flag)
:1001 (Program number 1001)
Depending on where the tool is located, there are two basic rules to N5 G90 G20 (Absolute and inch programming)
N10 M06 T2 (Tool change, Tool #2)
follow for safety’s sake:
N15 M03 S1200 (Spindle on CW, at 1200 rpm)
N20 G00 X1 Y1 (Rapid over to X1,Y1)
• If the Z value represents a cutting move in the negative direction, N25 Z0.1 (Rapid down to Z0.1)
the X and Y axes should be executed first. N30 G01 Z-0.25 F5 (Feed move down to a depth of 0.25 in.)
N35 Y3 (Feed move to Y3)
• If the Z value represents a move in the positive direction, the X N40 X5 (Feed to X5)
and Y axes should be executed last. N45 X1 Y1 Z-0.125 (Feed to X1,Y1,Z–0.125)
N50 G00 Z1 (Rapid up to Z1)
N55 X0 Y0 (Rapid over to X0,Y0)
N60 M05 (Spindle off)
17
N65 M30 (End of program) 18

G01 Linear Interpolation Linear Interpolation,


Format: N_ G01 X_ Y_ Z_ F_ or straight-line feed
The G01 command is
moves, on the flat
specifically for the XY plane (no Z
linear removal of values are
material from a specified).
workpiece, in any
combination of the X,
Y, or Z axes. The
machine tool follows a
G01 command,
linear trajectory.
The G01 is modal and using multi-axis feed
requires a user moves. All diagonal
variable feedrate feed moves are a
(designated by the result of a G01
letter F followed by a
command, where
number).
two or more axes
19 are used at once. 20
Sample Program (G01): G02 Circular Interpolation (clockwise)
Workpiece Size: X4, Y3, Z1
Tool: Tool #3, 3/8" Slot Drill Format: N_ G02 X_ Y_ Z_ I_ J_ K_ F_
Tool Start Position: X0, Y0, Z1
% (Program start flag) or N_ G02 X_ Y_ Z_ R_ F_
:1002 (Program #1002)
Circular Interpolation is
N5 G90 G20 (Block #5, absolute in inches)
more commonly known
N10 M06 T3 (Tool change to Tool #3)
as radial (or arc) feed
N15 M03 S1250 (Spindle on CW at 1250 rpm)
moves. The G02
N20 G00 X1.0 Y1.0 (Rapid over to X1,Y1)
command is specifically
N25 Z0.1 (Rapid down to Z0.1)
used for all clockwise
N30 G01 Z-0.125 F5 (Feed down to Z–0.125 at 5 ipm)
radial feed moves,
N35 X3 Y2 F10 (Feed diagonally to X3,Y2 at 10 ipm)
whether they are
N40 G00 Z1.0 (Rapid up to Z1)
quadratic arcs, partial
N45 X0.0 Y0.0 (Rapid over to X0,Y0)
arcs, or complete circles,
N50 M05 (Spindle off)
as long as they lie in any
N55 M30 (Program end)
one plane.
The G02 command is
modal and is subject to a
21 22
user-definable feed rate.

EXAMPLE: G02 X2 Y1 I0 J-1


G02 Circular Interpolation (cont'd.) The G02 command requires The G02 command requires an endpoint and a radius in order to cut the
an endpoint and a radius in arc. The start point of this arc is (X1, Y2) and the end-point is (X2, Y1). To
order to cut the arc. The start find the radius, simply measure the relative, (or incremental), distance
from the start point to the center point. This radius is written in terms of the
point of this arc is (X1,Y4) X and Y distances. To avoid confusion, these values are assigned variables
and the endpoint is (X4,Y1). called I and J, respectively.
To find the radius, simply
measure the incremental
distance from the start point
to the center point. This
radius is written in terms of
the X and Y distances. To
avoid confusion, these
values are assigned
variables, called I and J,
respectively.
23 24
Sample Program (G02):
EXAMPLE: G02 X2 Y1 R1 Workpiece Size: X4, Y3, Z1
You can also specify G02 by entering the X and Y endpoints and then R for the Tool: Tool #2, 1/4" Slot Drill
radius. Tool Start Position: X0, Y0, Z1
%
Note: The use of an R value for the radius of an arc is limited to a maximum :1003
movement of 90°. N5 G90 G20
N10 M06 T2
An easy way to determine the radius values (the I and J values) is by making a small N15 M03 S1200
chart: N20 G00 X1 Y1
Center point X1 Y1 N25 Z0.1
Start point X1 Y2 N30 G01 Z-0.1 F5
Radius I0 J-1 N35 G02 X2 Y2 I1 J0 F20 (Arc feed CW, radius I1,J0 at 20 ipm)
N40 G01 X3.5
Finding the I and J values is easier than it first seems. Follow these steps: N45 G02 X3 Y0.5 R2 (Arc feed CW, radius 2)
1. Write the X and Y coordinates of the arc’s center point. N50 X1 Y1 R2 (Arc feed CW, radius 2)
2. Below these coordinates, write the X and Y coordinates of the arc’s start N55 G00 Z0.1
N60 X2 Y1.5
point.
N65 G01 Z-0.25
3. Draw a line below this to separate the two areas to perform the subtraction. N70 G02 X2 Y1.5 I0.25 J-0.25 (Full circle arc feed move CW)
Result: G02 X2 Y1 I0 J-1 F5 N75 G00 Z1
4. To find the I value, calculate the difference between the arc’s start point and N80 X0 Y0
center point in the X direction. In this case, both X values are 1. Hence there is no N85 M05
difference between them, so the I value is 0. To find the J value, calculate25the N90 M30
26
difference between the arc’s start point and center point in the Y direction. In this
case the difference between Y2 and Y1 is down 1 inch so the J value is –1

G03 CIRCULAR INTERPOLATION (CCW) EXAMPLE: G03 X1 Y1 I0 J-1


Format: N_ G03 X_ Y_ Z_ I_ J_ K_ F_ (I, J, K specify the radius) The G03 command requires an endpoint and a radius in order to cut the
arc. (See Fig. 5.7.) The start point of this arc is (X2, Y2) and the end-point is
The G03 command is (X1, Y1). To find the radius, simply measure the incremental distance from
used for all the start point to the center point of the arc. This radius is written in terms
counterclockwise radial of the X and Y distances. To avoid confusion, these values are assigned
variables called I and J, respectively.
feed moves, whether
they are quadratic arcs,
partial arcs, or complete
circles, as long as they
lie in any one plane.
The G03 command is
modal and is subject to a
user-definable feed rate

27 28
G03 Circular Interpolation (cont'd)
EXAMPLE: G03 X1 Y1 R1
You can also specify G03 by entering the X and Y endpoints and then R for the The G03 command requires an
radius.
endpoint and a radius in order to
Note: The use of an R value for the radius of an arc is limited to a maximum cut the arc. The start point of this
movement of 90°. An easy way to determine the radius values (the I and J values) is arc is (X4,Y1) and the endpoint
to make a small chart as follows.
is(X1,Y4). To find the radius,
Center point X2 Y1 simply measure the incremental
Start point X2 Y2 distance from the start point to the
Radius I0 J-1
Finding the I and J values is easier than it first seems. Follow these steps:
center point. This radius is written
1. Write the X and Y coordinates of the arc’s center point. in terms of the X and Y distances.
2. Below these coordinates, write the X and Y coordinates of the arc’s start point. To avoid confusion, these values
3. Draw a line below this to separate the two areas to perform the subtraction.
4. To find the I value, calculate the difference between the arc’s start point and
are assigned variables I and J,
center point in the X direction. In this case, both X values are 2. Hence there is no respectively.
difference between them, so the I value is 0. To find the J value, calculate the
difference between the arc’s start point and center point in the Y direction. In this
case, the difference between Y2 and Y1 is down 1 inch, so the J value is –1.
29 30
Result: G03 X1 Y1 I0 J-1

Sample Program (G03).


Workpiece Size: X4, Y4, Z0.25
Tool: Tool #2, 1/4" Slot Drill
Tool Start Position: X0, Y0, Z1
%
:1004
N5 G90 G20
NOTE: Programming the G02 and G03 commands N10 M06 T2
N15 M03 S1200
with an R value is reserved only for arcs less than or N20 G00 X2 Y0.5
N25 Z0.125
equal to 90 degrees. The more common method N30 G01 Z-0.125 F5
N35 X3 F15
involves the use of trigonometry to solve for the I, J, N40 G03 X3.5 Y1 R0.5
N45 G01 Y3
(G03 arc using R value)

or K values. N50 G03 X3 Y3.5 I-0.5 J0


N55 G01 X2
(G03 arc using I and J)

N60 G03 X2 Y1.5 I0 J-1 (180° arc using I and J)


N65 G01 Y0.5
N70 G00 Z0.1
N75 X1.5 Y2.5
N80 G01 Z-0.25 F5
N85 G03 X1.5 Y2.5 I0.5 J0 (Full circle using I and J)
N90 G00 Z1
N95 X0 Y0
N100 M05
N105 M30
31 32
G17 = XY plane
G18 = XZ plane
Command Format with IJK Method
(GI7) G02 (or G03) Xx Yy Ii Ji Ff on XY-plane G19 = YZ plane
(G18) G02 (or G03) Xx Zz Ii Kk Ff on ZX-plane
(G19) G02 (or G03) Yy Zz Jj Kk Ff on YZ-plane

Command Format with R Method


(GI7) G02 (or G03) Xx Yy Rr Ff on XY-plane
(G18) G02 (or G03) Xx Zz Rr Ff on ZX-plane
(G19) G02 (or G03) Yy Zz Rr Ff on YZ-plane

33 34

G04 DWELL
Format: N_ G04 P_

The G04 command is


a nonmodal dwell
command that halts
all axis movement for
a specified time while
the spindle continues
revolving at the
specified rpm. A dwell
is used largely in
drilling operations and
after plunge moves,
which allows for the
35 clearance of chips . 36
G17 XY Plane
Sample Program (G04): Format: N_ G17
Workpiece Size: X3.5, Y2, Z0.5
Tool: Tool #1, 1/8" Slot Mill
Tool Start Position: X0, Y0, Z1
% (Program start flag)
:1005 (Program #1005)
N5 G90 G20 (Absolute programming in inch mode)
N10 M06 T1 (Tool change to Tool #1)
N15 M03 S1300 (Spindle on CW at 1300 rpm)
N20 G00 X3 Y1 Z0.1 (Rapid to X3,Y1,Z0.1)
N25 G01 Z-0.125 F5.0 (Feed down to Z–0.125 at 5 ipm)
N30 G04 P2 (Dwell for 2 seconds)
N35 G00 X2 Z0.1 (Rapid up to 0.1)
N33 X2 (Rapid to X2)
N40 G01 Z-0.125 F5.0 (Feed down to Z–0.125)
N45 G04 P1 (Dwell for 1 second)
N50 G00 Z1.0 (Rapid out to Z1)
N55 X0. Y0. (Rapid to X0, Y0)
N60 M05 (Spindle off)
N65 M30 (Program end)
37 38

G18 XZ Plane G19 Y Z Plane


Format: N_ G18 Format: N_ G19

39 40
G17 = XY plane G20 or G70 Inch Units
G18 = XZ plane Format: N_ G20 or G70
G19 = YZ plane The G20 or G70 command defaults the
system to inch units. When a program is
being run and the G20 command is
encountered, all coordinates are stated as
inch units. This command is usually found
at the beginning of a program. However,
on some controllers it can be used to
switch from metric units in the middle of a
program.
41 42

G21 or G71 Metric, or SI, Units G28 Automatic Return to Reference


Format: N_ G21 or G71 Format: N_ G28
N_ G28 X_ Y_ Z_
The G21 or G71 command defaults the The G28 command is
system to metric units. When a program is primarily used before
automatic tool
being run and the G21 command is changing. It allows
encountered, all coordinates are stated in the existing tool to be
positioned to the
as millimeter units. This command is predefined reference
usually found at the beginning of a point automatically
via an intermediate
program. However, it can be used to position. This ensures
switch between metric and inch units in that when the tool
changer is engaged, it NOTE: When this command is being used, it is
the middle of a program. is properly aligned advisable for safety reasons to cancel any tool 44
offset
43
with the spindle head. or cutter compensation.
G29 Automatic Return from Reference
Format: N_ G29 Cutter Compensation
N_ G29 X_ Y_ Z_

The G29 command


can be used
immediately after an Usually, CNC programs are written so that the tool
automatic tool change. center follows the toolpath. Cutter compensation is
It allows the new tool
used whenever tool centerline programming is
to be returned from
the predefined difficult. It is also used to compensate for
reference point to the significant tool wear or tool substitution.
specified point via an
intermediate point NOTE: Cutter compensation is modal, so it must be
specified by the canceled when it is no longer needed. This is the
previous G28
NOTE: When this command is being used, it is sole function of the G40 command
command. advisable for safety reasons to cancel any tool45offset 46
or cutter compensation.

G41 Cutter Compensation Left


Format: N_ G41 D_ G41 Cutter Compensation Left
Format: N_ G41 D_
The G41 command
compensates the cutter a
specified distance to the
left-hand side of the
programmed tool path. It is
used to compensate for
excessive tool wear or
substitute a tool to profile a
part.

The G41 command is


modal, so it compensates
each successive tool move
the same specified distance
until it is overridden by a Actual tool path
G40 command or receives a Programmed tool path
different offset. 47 48
N55 G01 X0.5
G42 CUTTER COMPENSATION RIGHT
Sample program (G41):
Workpiece Size: X5, Y4, Z1 N60 Y0.5 Format: N_ G42 D_
N65 G00 Z1
Tool: Tool #1, 1/4" Slot Drill N70 X0 Y0
Tool #4, 1/2" End Mill The G42 command
N75 M06 T04
Register: D11 is 0.25" compensates the cutter a
N80 M03 S1000
specified distance to the
Tool Start Position:X0, Y0, Z1 N85 G00 X0.75 Y1 right-hand side of the
N90 Z0.125
% N95 G01 Z-0.25 F5 programmed tool path. It
:1012 N100 G41 X0.5 Y0.5 D11 F20 is used to compensate for
N5 G90 G20 G40 G17 G80 N105 X2 excessive tool wear or
N10 T01 M06 N110 X2.5 Y1 substitute a tool to profile
N15 M03 S2000 N115 Y2 a part. The G42 command
N20 G00 X0.5 Y0.5 N120 G03 X2 Y2.5 R0.5 is modal, so it
N25 Z0.1 N125 G01 X0.5 compensates each
N30 G01 Z-0.25 F5 N130 Y0.5 successive tool move the
N135 G40 X0.75 Y0.75 same specified distance
N35 X2 F15 N140 G00 Z1 until it is overridden by a
N40 X2.5 Y1 N145 X0 Y0 G40 command or receives
N45 Y2 N150 M05
49 a different offset. 50
N50 G03 X2 Y2.5 R0.5 N155 M30

G42 CUTTER COMPENSATION RIGHT Sample Program (G42): N65 G00 Z1


Workpiece Size: X4, Y4, Z1 N70 X0 Y0
Format: N_ G42 D_ Tool: Tool #1, 1/4" Slot Drill N75 T04 M06
Tool #4, 1/2" End Mill N80 M03 S1000
Register: D11 is 0.25" N85 G00 X-0.5
Tool Start Position: X0, Y0, Z1 N90 Z-0.5
% N95 G01 G42 X0.5 Y0.5 Z-0.5 D11 F15
:1013 N100 X2
N5 G90 G20 G40 G17 G80
N105 X2.5 Y1
N10 T01 M06
N110 Y2
N15 M03 S2000
N20 G00 X0.5 Y0.5 N115 G03 X2 Y2.5 R0.5
N25 Z0.1 N120 G01 X0.5
N30 G01 Z-0.25 F5 N125 Y0
N35 X2 F15 N130 G01 G40 Z0.25
N40 X2.5 Y1 N135 G00 Z1
N45 Y2 N140 X0 Y0
N50 G03 X2 Y2.5 R0.5 N145 M05
N55 G01 X0.5 N150 M30
51 N60 Y0.5 52
Offset Direction = Left (G41)
G40 Cutter Compensation Cancel
Format: N_ G40

Usually, CNC programs are written so that the tool center


follows the toolpath. Cutter compensation is used whenever
Offset Direction = Right (G42)
tool centerline programming is difficult. It is also used to
compensate for significant tool wear or tool substitution.
The G40 command cancels any cutter compensation that
was applied to the tool during a program and acts as a
safeguard to cancel any cutter compensation applied to a
previous program or G-codes.
Offset Direction = Off (G40)
NOTE: Cutter compensation is modal, so it must be
canceled when it is no longer needed. This is the sole
function of the G40 command
53 54

G43 Tool Length Compensation (Plus)


Format: N_ G43 H_ G43 Tool Length Compensation (Plus)
The G43 command Format: N_ G43 H_
compensates for tool
length in a positive
direction. It is important
to realize that different
tools will have varying
lengths, and when tools
are changed in a program,
any variation in tool
length will throw the
origin out of zero. To
prevent this, the
difference in tool length
should be compensated 55 56
for.
G44 Tool Length Compensation (Minus)
G44 Tool Length Compensation (Minus)
Format: N_ G44 H_
Format: N_ G44 H_
The G44 command
compensates for tool
length in a minus
direction. It is important
to realize that different
tools will have varying
lengths, and when tools
are changed in a
program, any variation
in tool length will throw
the origin out of zero. To
prevent this, the
difference in tool length
should be compensated 57 58

for.

G54–G59 Workpiece Coordinate System


G49 Tool Length Compensation Cancel
Format: N_ G49
Format: N_ G54 through G59
The G54 – G59 commands
are used to reposition the
origin per a user- defined
The G49 command cancels all previous cutter working coordinate system.
In CNCez six register sets in
length offset commands. Because the G43 and the controller hold the values
G44 commands are modal, they will remain for the working coordinate
systems. The G54 – G59
active until canceled by the G49 command. It is commands are very useful
important to keep this in mind; forgetting that a when multiple workpiece
fixtures are used. On real
tool has been offset can cause the cutter to crash CNC controllers these values
into the workpiece. are held in parameter fields
which are normally set in the
parameters entry screen of
59
the controller. 60
• :1019
G80 Cancel Canned Cycles


N5 G90 G80 G20
N10 M06 T6 Format: N_ G80
• N15 M03 S1300
• N20 G55 G00 X1.0 Y1.0 (Rapid to X1, Y1 of work coordinate system 2)
• N25 Z0.5 The G80 command cancels all previous canned
• N30 G82 Z-0.25 R0.125 P500 F5
• N35 Y2 cycle commands. Because the canned cycles are
• N40 X2
• N45 Y1 modal (refer to the canned cycles on the
• N50 X1.5 Y1.5 (COMPENSATE TOOL 4 -- 0.25 INCHES)
• N60 G80 G00 Z1 following pages), they will remain active until
• N65 G56 G00 X1.0 Y1.0 (Rapid to X1, Y1 of work coordinate system 3)
• N70 Z0.5 canceled by the G80 command. Canned cycles
• N75 G82 Z-0.25 R0.125 P500 F5
• N80 Y2 include tapping, boring, spot facing, and
• N85 X2
• N90 Y1 drilling.
• N95 X1.5 Y1.5
• N100 G80 G00 Z1
• N102 G54 (Reset work coordinate system)
• N105 X0 Y0 Note: On most controllers the G00 command
• N110 M05
• N115 M30 61 will also cancel any canned cycles. 62

G81 Drilling Cycle G82 Spot Drilling or Counter Boring Cycle


Format: N_ G81 X_ Y_ Z_ R_ F_ Format: N_ G82 X_ Y_ Z_ R_ P_ F_
The G81 command This cycle follows the same
invokes a drill cycle at operating procedures as the
specified locations. This G81 drilling cycle, with the
addition of a dwell. The
cycle can be used for
dwell is a pause during
bolt holes, drilled which the Z axis stops
patterns, and mold moving but the spindle
sprues, among other continues rotating. This
tasks. This command is pause allows for chip
clearing and a finer finish on
modal and so remains
the hole. The dwell time is
active until overridden measured in seconds.
by another move The dwell is specified by the The same Z levels apply to the G82
Invoking the G81 command requires
command or canceled P letter address, followed by
cycle as to the G81 cycle: Z initial
invoking the Z initial plane, Z depth the dwell time in seconds.
by the G80 command. and Z retract plane parameters. 63 plane, Z depth and Z retract. 64
G83 Deep Hole Drilling Cycle G73 High-Speed Peck Drilling Cycle
Format: N_ G83 X_ Y_ Z_ R_ Q_ F_ Format: N_ G73 X_ Y_ Z_ Q_ F_
The G83 command involves During a G73 high-speed
individual peck moves in each
peck drilling cycle, the tool
drilling operation. When this
command is invoked, the tool feeds in to the peck distance
positions itself as in a or depth of cut, then retracts
standard G81 drill cycle. The a small pre-determined
peck is the only action that distance, which is the chip-
distinguishes the deep hole breaking process, and then
drilling cycle from the G81
feeds to the next peck, which
cycle. When pecking, the tool
feeds in the specified distance takes the tool deeper. This
(peck distance or depth of process is repeated until the
cut), then rapids back out to final Z depth is reached.
the Z Retract plane. The next Because the tool doesn't
peck takes the tool deeper, retract fully from the hole, as
and then it rapids out of the
hole. This process is repeated In the G83 cycle, Q is the in the G83 cycle, it minimizes
until the final Z depth is cycle time and improves total
reached.
incremental depth of cut. 65 part machining time. 66

G90 Absolute Positioning


Format: N_ G90
The G90 command defaults the system to G91 Incremental Positioning
accept all coordinates as absolute Format: N_ G91
coordinates. These coordinates are
measured from a fixed origin (X0, Y0, Z0) The G91 command defaults the system to
and expressed in terms of X, Y, and Z accept all coordinates as incremental, or
distances. relative, coordinates.

67 68
G92 Reposition Origin Point G98 Set Initial Plane Rapid Default
Format: N_ G92 X_ Y_ Z_ Format: N_ G98
The G92 command is
The G98 command
used to reposition the
forces the tool to return
origin point. The origin
to the Z initial plane a
point is not a physical
drilling operation. This
spot on the machine tool,
forces the tool up and
but rather a reference
out of the workpiece.
point to which the
This setting is normally
coordinates relate.
used when a workpiece
Generally, the origin
has clamps or other
point is located at a
obstacles that could
prominent point or object
interfere with tool
(for example, front top
movement. The G98
left corner of the part) so
command is also the
that it is easier to measure
system default.
from. 69 70

G99 Set Rapid to Retract Plane


Format: N_ G99
The G99 command forces the CNC Milling – M- Codes
tool to return to the retract
plane after a drilling
operation. This forces the
M-codes are miscellaneous functions that include actions
tool up and out of the
workpiece to the retract plane necessary for machining but not those that are actual tool
specified in the drilling cycle, movements (for example, auxiliary functions). They include
overriding the system default. actions such as spindle on and off, tool changes, coolant on
This command is usually and off, program stops, and similar related functions.
used on drilling cycles within
a pocket, or on workpieces
that do not have surface
obstacles. It is quicker than
the G98 command because
the tool moves only to the
retract plane.
71 72
M-Codes
M00 - Program stop
M00 Program stop Format: N_ M00
M01 Optional program stop The M00 command is a temporary program stop function. When
M02 Program end it is executed, all functions are temporarily stopped and will not
M03 Spindle on clockwise
M04 Spindle on counterclockwise restart unless and until prompted by user input.
M05 Spindle stop
M06 Tool change This command can be used in lengthy programs to stop the
M08 Coolant on program in order to clear chips, take measurements, or adjust
M09 Coolant off clamps, coolant hoses, and so on.
M10 Clamps on
M11 Clamps off
M30 Program end, reset to start M01 Optional Program Stop
M98 Call subroutine command Format: N_ M01
M99 Return from subroutine command If the Optional Stop switch is set to ON, the program will stop
Block Skip Option to skip blocks that begin with ‘/’
when it encounters in an M01command.
Comments Comments may be included in blocks with round
brackets ‘(’ ‘)’
73 74

M02 PROGRAM END M03 SPINDLE ON CLOCKWISE


Format: N_ M02
The M02 command indicates an end of the main program cycle operation. Upon Format: N_ M03 S_
encountering the M02 command, the MCU switches off all machine operations (for The M03 command switches the spindle on in a clockwise rotation. The spindle
example, spindle, coolant, all axes, and any auxiliaries), terminating the program. speed is designated by the S letter address, followed by the spindle speed in
This command appears on the last line of the program. revolutions per minute
Sample Program (M02):
Workpiece Size: X4, Y3, Z1
Tool: Tool #2, 1/4" Slot Drill
Tool Start Position: X0, Y0, Z1
%
:1003
N5 G90 G20
N10 M06 T2
N15 M03 S1200
N20 G00 X1 Y1
N25 Z0.1
N30 G01 Z-.125 F5
N35 X3 F15
N40 G00 Z1
N45 X0 Y0
N50 M05
N55 M02 (Program end) 75 76
M04 SPINDLE ON COUNTERCLOCKWISE M05 SPINDLE STOP
Format: N_ M04 S_ Format: N_ M05
The M04 command switches the spindle on in a counterclockwise The M05 command turns the spindle off. Although other M-codes
rotation. The spindle speed is designated by the S letter address, turn off all functions (for example, M00 and M01), this command
followed by the spindle speed in revolutions per minute. is dedicated to shutting the spindle off directly. The M05
command appears at the end of a program.

M06 TOOL CHANGE


Format: N_ M06 T_
The M06 command halts all program operations for a tool
change. It is actually a two-fold command. First, it stops all
machine operations—for example, the spindle is turned off and
oriented for the tool change, and all axes motion stops—so that it
is safe to change the tool. Second, it actually changes the tool

77 78

M06 TOOL CHANGE


Format: N_ M06 T_
M07/M08 COOLANT ON
Format: N_ M07 or N_ M08
The M07 and M08 commands switch on the coolant flow.

M09 COOLANT OFF


Format: N_ M09
The M09 command shuts off the coolant flow. The coolant
should be shut off prior to tool changes or when you are
rapiding the tool over long distances.

79 80
M10 CLAMPS ON
M08 Coolant On or M09 Coolant Off Format: N_ M10
Format: N_ M08 or N_ M09 The M10 command turns on the automatic clamps to
secure the workpiece. Automatic clamps can be
pneumatic, hydraulic, or electromechanical. Not all CNC
machines have automatic clamps, but the option exists
and the actual code will vary by machine tool make and
model.

81 82

Sample Program M11EX10:


M11 CLAMPS OFF Workpiece Size: X4, Y3, Z1
Format: N_ M11 Tool: Tool #12, 1" End Mill
Tool Start Position: X0, Y0, Z1
The M11 command releases the automatic clamps so that the %
work-piece may be removed and the next blank inserted. The :1011
N5 G90 G20
automatic clamps may be pneumatic, hydraulic, or N10 M06 T12
electromechanical, depending on the application. N15 M10 (Clamp workpiece)
N20 M03 S1000
N25 G00 X-0.75 Y1
N30 Z-0.375
N35 G01 X0 F10
N40 G03 Y2 I0 J0.5
N45 G01 X2 Y3
N50 X4 Y2
N55 G03 Y1 I0 J-0.5
N60 G01 X2 Y0
N65 X0 Y1
N70 G00 Z1
N75 X0 Y0
N80 M05
N85 M11 (Unclamp workpiece)
N90 M30
83 84
M98 CALL SUBPROGRAM
Format: N_ M98 P_
The M98 function is used to call a subroutine or subprogram.
M30 PROGRAM END, RESET TO START Execution is halted in the main program and started on the
Format: N_ M30 program referenced by the P letter address value. For
The M30 command indicates the end of the program data. example, N15 M98 P1003 would call program :1003, either
In other words, no more program commands follow it. from within the current CNC program file or from an
This is a remnant of the older NC machines, which could external CNC program file. Machine status is maintained
not differentiate between one program and the next, so an when a sub-program is called. This is especially useful in
End of Data command was developed. Now the M30 is family parts programming or when several operations are
used to end the program and reset it to the start. required on the same hole locations. In the following sample
program the subprogram is used to drill a hole pattern, using
several calls to different drill cycles. The main program
positions the machine tool at the starting location to invoke
the cycle; the subprogram then continues the pattern
85 86

Sample Program M98EX9: N60 G29 X1 Y1


Workpiece Size: X5, Y5, Z1 N65 M03 S1200
Tool: Tool #1, 3/32" Spot Drill N70 M08
Tool #2, 1/4” HSS Drill N75 G83 X1 Y1 Z-1 R0.1 Q0.1 F5.0 (Start of cycle)
Tool #3, 1/2” HSS Drill N80 M98 P1005 (Call subprogram to do rest)
Tool Start Position: X0, Y0, Z1 N85 G80
% N90 G28 X1 Y1
:1010 N95 M09
N5 G90 G20 N100 M06 T03
N10 M06 T1 N105 G29 X1 Y1
N15 M03 S1500 N110 M03 S1000
N20 M08 (Coolant on) N115 M08
N25 G00 X1 Y1 N120 G73 X1 Y1 Z-1 R0.1 Q0.1 F5.0 (Start of cycle)
N30 G82 X1 Y1 Z-.1 R.1 P0.5 F5 (Start of cycle) N125 M98 P1005 (Call subprogram to do
N35 M98 P1005 (Call subprogram to do rest) rest)
N40 G80 N130 G80
N45 G28 X1 Y1 N135 G00 Z1
N50 M09 N140 X0 Y0
N55 M06 T02 N145 M09
87 88
M99 RETURN FROM SUBPROGRAM
Format: N_ M99
The M99 function is used to end or terminate the subprogram and return to the
N150 M05
main calling program. Execution is continued at the line immediately
N155 M30
following the subprogram call. It is used only at the end of the subprogram.
O1005 (Subprogram)
N5 X2
Sample Program M99EX10:
N10 X3
Workpiece Size: X5, Y5, Z1
N15 X4
Tool: Tool #1, 3/32" Spot Drill
N20 Y2
Tool #2, 1/4” HSS Drill
N25 X3
Tool Start Position: X0, Y0, Z1
N30 X2
%
N35 X1
:1011
N40 M99 (Return from sub-
N5 G90 G20
program)
N10 M06 T1
N15 M03 S1500
N20 M08 (Coolant on)
N25 G00 X1 Y1
N30 G82 X1 Y1 Z-.1 R.1 P0.5 F5 (Start of cycle)
89 90

N35 M98 P1005 (Call subprogram to do rest)


N40 G80
N45 G28 X1 Y1
N50 M09
Examples
N55 M06 T03
N60 G29 X1 Y1 This program introduces you to the Cartesian coordinate
N65 M03 S1200
N70 M08 system and absolute coordinates. Only single-axis, linear-feed
N75 G83 X1 Y1 Z-1 R0.1 Q0.1 F5.0 (Start of cycle) moves show the travel directions of the X, Y, and Z axe
N80 M98 P1006 (Call subprogram to do rest)
N85 G80
N135 G00 Z1
N140 X0 Y0
N145 M09
N150 M05
N155 M30

O1006 (Subprogram to drill rest of square pattern)

N5 X2
N20 Y2
N25 X1
91 92
N30 M99 (Return from subprogram)
Workpiece Size: X5, Y4, Z1 EXAMPLE 2: I-part2.mil
Tool: Tool #3, 3/8" End Mill
Tool Start Position: X0, Y0, Z1 (Relative to workpiece) This next program introduces you to diagonal linear feed moves,
% where both the X axis and the Y axis are traversed
:1001
N5 G90 G20
N10 M06 T3
N15 M03 S1200
N20 G00 X1 Y1
N25 Z0.125
N30 G01 Z-0.125 F5
N35 X4 F20
N40 Y3
N45 X1
N50 Y1
N55 G00 Z1
N60 X0 Y0
N65 M05
N70 M30
93 94

Workpiece Size: X5, Y4, Z1 Example 3:


Tool: Tool #2, 1/4" End Mill
Tool Start Position: X0, Y0, Z1 (Relative to workpiece) This program introduces arcs: G02 (clockwise) and G03
% (counterclockwise). These are all simple quarter quadrant arcs
:1002 with a 1-in. radius
N5 G90 G20
N10 M06 T2
N15 M03 S1200
N20 G00 X1 Y1
N25 Z0.125
N30 G01 Z-0.125 F5
N35 X4 F10
N40 Y3
N45 X1 Y1
N50 Y3
N55 X4 Y1
N60 G00 Z1
N65 X0 Y0
N70 M05
N75 M30 95 96
Workpiece Size: X5, Y4, Z1
Tool: Tool #2, 0.25" Slot Mill EXAMPLE 4: This program cuts several G02 and G03 arcs
Tool Start Position: X0, Y0, Z1 (Relative to workpiece) (clockwise and counterclockwise) in semicircles and full
%
:1003 circles
N5 G90 G20
N10 M06 T2
N15 M03 S1200
N20 G00 X0.5 Y0.5
N25 Z0.25
N30 G01 Z-0.25 F5
N35 G02 X1.5 Y1.5 I1 J0 F10
N40 X2.5 Y2.5 R1
N45 X3.5 Y1.5 I0 J-1
N50 X4.5 Y0.5 R1
N55 G01 Y1.5
N60 G03 X3.5 Y2.5 R1
N65 X2.5 Y3.5 I-1 J0
N70 X1.5 Y2.5 R1
N75 X0.5 Y1.5 I0 J-1
N80 G01 Y0.5

97 98

Workpiece Size: X4, Y4, Z2 EXAMPLE 5:


Tool: Tool #4, 0.5" Slot Mill This program involves a simple drilling cycle with a defined
Tool Start Position: X0, Y0, Z1 (Relative to workpiece)
% retract plane. Once the G-code for the drill cycle has been
:1004 executed, only the X and/or Y location of the remaining holes
N5 G90 G20 need to be defined
N10 M06 T4
N15 M03 S1200
N20 G00 Z0.25
N25 G01 Z0 F5
N30 G18 G02 X4 Z0 I2 K0
N35 G19 G03 Y4 Z0 J2 K0
N40 G18 G03 X0 Z0 I-2 K0
N45 G19 G02 Y0 Z0 J-2 K0
N50 G00 Z0.25
N55 X1 Y2
N60 G01 Z-0.25
N65 G17 G02 I1 J0 F10
N70 G00 Z1
N75 X0 Y0
N80 M05
N85 M30 99 100
Workpiece Size: X5, Y4, Z1
Tool: Tool #7, 3/8" HSS Drill EXAMPLE 6: I-part6.mil
Tool Start Position: X0, Y0, Z1 (Relative to This program involves a drilling cycle with a dwell and
workpiece) incremental coordinates
% N55 Y1
:1005 N60 X3
N5 G90 G20 N65 X4
N10 M06 T7
N70 Y2
N15 M03 S1000
N75 Y3
N20 G00 X1 Y1
N25 Z0.25 N80 X3
N30 G98 G81 X1 Y1 Z-0.25 R0.25 F3 N85 Y2
N35 Y2 N90 G00 Z1
N40 Y3 N95 X0 Y0
N45 X2 N100 M05
N50 Y2 N105 M30 101 102

Workpiece Size: X5, Y4, Z1


Tool: Tool #8, 3/4" HSS Drill
Tool Start Position: X0, Y0, Z1 (Relative to workpiece)
%
:1006
N5 G90 G20
N10 M06 T8
N15 M03 S500
N20 G00 X1 Y1
N25 Z0.25
N30 G91 G98 G82 Z-0.5 R0.25 P1
N35 X1
N40 X2
N45 Y1
N50 Y1
N55 X-2
N60 X-1
N65 Y-1
N70 X1
N75 G80 G90 G00 Z1
N80 X0 Y0
N85 M05
103
N90 M30

You might also like