CNC Milling Programing Guide
CNC Milling Programing Guide
CNC Milling Programing Guide
MILLING
Foreword
The purpose of this guide is to help faculty teach CNC programming without tears. Most books
currently available on CNC programming are not only inadequate, but also specific to certain CNC
control systems and aimed at the professionals in industry. Such manuals only have very basic
explanations on various codes, without adequate pictures and program examples. Therefore, they do
not help in teaching the fundamentals of CNC programming.
My company Cadem strongly believes in doing its best to bridge the gap between education and
industry, and consistently works on a lot of initiatives to achieve this. This handbook and the
attendant material is one such initiative, to provide a clear set of training material to teach CNC
programming effectively. This handbook comes free of cost to you. You can print and use it, or freely
distribute soft copies.
It is part of a package of free CNC Learning Kit CD-ROM that includes the following for both CNC
milling and turning:
-
I hope you enjoy teaching or learning using the Free CNC Learning Kit as much as I enjoyed making
it.
G.V.Dasarathi
Director, CADEM
10 December 2012
Bangalore
Page 1 of 50
Table of Contents
Program format .......................................................................................................... 3
Coordinate system ..................................................................................................... 4
Axes convention..................................................................................................... 4
Absolute, incremental coordinates ......................................................................... 6
Basic motion commands ............................................................................................ 7
G00 - Rapid traverse.............................................................................................. 7
G01 - Linear interpolation....................................................................................... 9
G02 / G03 - Circular interpolation ........................................................................ 10
G04 Dwell ......................................................................................................... 13
F, S, T commands .................................................................................................... 14
Feedrate............................................................................................................... 14
Spindle rotation .................................................................................................... 14
Tool change.......................................................................................................... 14
Cutter radius compensation (CRC) .......................................................................... 15
Necessity of CRC................................................................................................. 15
CRC Left and Right .............................................................................................. 16
Tool length compensation......................................................................................... 18
Program structure..................................................................................................... 19
Subprograms............................................................................................................ 22
Canned cycles.......................................................................................................... 25
Drilling cycle - G81 ............................................................................................... 26
Counterboring cycle - G82 ................................................................................... 28
Peck drilling cycle - G73....................................................................................... 30
Deep drilling cycle - G83 ...................................................................................... 32
Finish boring cycle - G76 ..................................................................................... 34
Tapping RH cycle - G84 ....................................................................................... 36
Tapping LH cycle - G74........................................................................................ 38
Reaming cycle - G85............................................................................................ 40
Back boring cycle - G87 ....................................................................................... 42
Return after cycle G98, G99 ............................................................................. 44
Typical G and M codes............................................................................................ 46
Full sample program................................................................................................. 48
Drawing to machined part - steps............................................................................. 50
Page 2 of 50
Program format
Program formats and commands explained in this chapter relate to the Fanuc 0MD
controller.
A CNC program consists of a number of lines, called blocks. Each block contains a
number of commands.
G01 X100.0 Y50.0 F450 is a block. It tells the tool to move along a straight line to
X100.0 Y50.0 at a feed rate of 450 mm/min.
A block consists of a set of words. Each word is a command. E.g., X100.0 is a word.
A word consists of an alphabet called the address, followed by a number. In X100.0, X is
an address.
Other than coordinates, the most commonly used words in a program are the G-codes
and M-codes.
G codes mostly involve tool motion commands like rapid motion, feed motion, circular
motion, dwell, and canned cycle codes.
M codes mostly involve machine actions like spindle on / off, tool change and coolant on
/ off.
Typical addresses
N
Block number - specifies the start of the block
G
Preparatory functions
M
Miscellaneous functions
X
X-axis coordinate
Y
Y-axis coordinate
Z
Z-axis coordinate
I
X-axis location of arc center
J
Y-axis location of arc center
K
Z-axis location of arc center
R
Radius of arc
S
Spindle speed or Cutting speed
F
Feed rate
T
Tool number
Page 3 of 50
Coordinate system
Axes convention
The axes and their directions are defined by the Right hand rule. The Z axis is along the
spindle. +Z is from the part looking towards the spindle. The thumb points in the +X
direction, while the index finger points towards +Y. The program zero is the intersection
of the axes. All coordinates in a program are referenced from this point.
Rotary axes about X,Y and Z are called A, B and C respectively. The sign of a rotary axis
is determined by the thumb and curled fingers of the right hand. If the thumb points in
the + direction of the linear axis, the other fingers point in the + direction of the
corresponding rotary axis.
Page 4 of 50
Page 5 of 50
Page 6 of 50
Format
G00 X_ Y_ Z_
X, Y, Z = coordinates of destination point
The block consists of the rapid traverse command G00 followed by the destination
coordinates.
Example
Page 7 of 50
Page 8 of 50
Format
G01 X_ Y_ Z_ F_
X, Y, Z = coordinates of destination point
F = Feed rate
The block consists of the linear interpolation command G01 followed by the destination
coordinates and the feed rate.
Example
Page 9 of 50
Clockwise - G02
Counterclockwise - G03
An arc can be programmed using its radius or the coordinates of its center point.
Format
Command format using arc radius:
G02/03 X__ Y__ R__ F__
X, Y = coordinates of destination point
R = radius of arc
F = feed rate
Page 10 of 50
Page 11 of 50
Page 12 of 50
G04 Dwell
A dwell command results in a temporary stoppage of all axis motions for a specified
duration. The spindle motion is not affected. It is typically used when the tool has
reached the final position in an operation and needs to stay there for a few spindle
rotations to obtain good dimensional accuracy or surface finish. For example, in a
countersinking operation when the tool reaches the final position and needs to stay there
for at least one full revolution.
Format
G04 X_
X is the dwell time in seconds.
Example
G04 X1.0
This results in a dwell of 1 second.
Page 13 of 50
F, S, T commands
Feedrate
The feed rate is specified in mm. per minute.
Format
F_
F is specfied in mm. per minute.
Example
F250.0
This means a feed rate of 250 mm/min.
Spindle rotation
Spindle rotation is started by specifying a spindle direction command and a spindle
speed command.
Spindle direction:
This is specified by an M code.
M03 : Spindle clockwise (CW)
M04 : Spindle counter-clockwise (CCW)
M05 : Spindle stop
Spindle speed:
The spindle speed is specified in rpm with the address S.
Example
S1250 M03
This block commands a spindle speed of 1250 rpm with the spindle rotating clockwise.
Tool change
The tool change command typically has the tool number and a tool change command.
When the command is executed, the tool changer causes the commanded tool to come
to the spindle.
Format
Taa M06
aa is the tool number
M06 is the tool change command
Example
CAMLab - Milling Programming Guide
Page 14 of 50
T23 M06
Necessity of CRC
The compensated tool path must be either to the left or the right of the tool path
programmed with the coordinates from the part drawing. The direction of compensation
depends on the direction of motion and whether the tool is cutting on the inside or
outside of the part. The tool diameter too must be specified in a separate area of the
memory.
The commands are:
G41 Cutter radius compensation Left
G42 Cutter radius compensation Right
G40 Cutter radius compensation Cancel
Page 15 of 50
Format
G00 / G01 G41 Dnn X_ Y_ for compensation Left
G00 / G01 G42 Dnn X_ Y_ for compensation Right
G00 / G01 G40 X_ Y_ for compensation Cancel
H is the tool offset number, under which the tool's radius is stored in the memory.
The command is initiated or cancelled with a G00 or G01 motion.
Page 16 of 50
Example
Page 17 of 50
Format
G00 / G01 G43 Hnn
G43 is the length compensation activation command.
H is the tool offset number, under which the tool's length is stored in the memory.
G43 is initiated or cancelled with a G00 or G01 motion.
The tool length compensation must be activated with the first motion after every tool
change.
Example
G00 G43 H16
CAMLab - Milling Programming Guide
Page 18 of 50
Program structure
Start
The first line is the % character.
The second line is the program number, written as Onnnn. E.g., O2345 means program
number 2345.
End
The last but one line is the program end command (M02 or M30).
The last line is the % character.
Block numbers
Block numbers add clarity to the program. They are written as N_
E.g.,
--N0123 G00 G90 X100.0 Y150.0
N0124 G01 Z-10.0 F250.0
N0125 X120.0
--Block numbers are optional. They can be omitted from all blocks or included in some
blocks only. Quite often block numbers are used only in tool change blocks. The leading
zero is optional. E.g., N0005 and N5 mean the same.
Comments
Comments can be inserted to add clarity to the program. They can be operation names,
tool names, instructions to the operator, etc. Comments are inserted within brackets.
Without comments a program is just a mass of alphabets and numbers and it is difficult
to figure out what each section of the program is doing. A comment can be in a separate
block by itself, or after a set of commands, as shown below.
(RAPID TO TOOL CHANGE POSITION)
G00 X200.0 Z150.0 M05
T0202 (GROOVING TOOL)
Modal commands
A Modal command is a command that remains active till it is canceled or changed by
another command of the same family.
E.g.,
G01 X50.0 F225.0
G01 Y-5.0 F225.0
G01 X60.0 F225.0
G00 X100.0
G01 Y-80.0 F225.0
G01 X120.0 F225.0
CAMLab - Milling Programming Guide
Page 19 of 50
Here G01 and F are modal, and need not be repeated in every block. G01 remains active
till it is changed by G00. The block after G00 has it, but here F need not be repeated.
The blocks can be written as:
G01 X50.0 F225.0
Y-5.0
X60.0
G00 X100.0
G01 Y-80.0
X120.0
Sample program
This sample program is a simple full program that does a drilling operation followed by a
grooving operation.
Program block
Explanation
O998
T01 M06
S500 M03
G43 H1 Z-3.0
Page 20 of 50
Cut 1
G00 Z-6.0
G01 Y-40.0
Cut 2
M09
Coolant OFF
T02 M06
S1400 M03
G00 X0 Y0 M08
G43 H2 Z3.0
G00 3.0
G00 X-64.0 Y0
G00 3.0
M05
Spindle OFF
M02
Program end
End character
Page 21 of 50
Subprograms
A tool path pattern that is repeated can be stored as a subprogram and called multiple
times. Using a subprogram reduces the program length and programming time, and
makes the program more readable. A subprogram looks like a normal program, but is
terminated with an M99 command at the end instead of M02 or M30. It is called from the
main program by a subprogram call command.
Format subprogram call:
M98 Paaabbbb
M98 = subprogram call command
aaa = number of subprogram repetitions, written as a 3 digit number
bbbb = subprogram number, written as a 4 digit number
aaa and bbbb MUST be written as 3 and 4 digit numbers respectively, if necessary by
padding them with leading zeros.
E.g., M98 P0051234.
This command calls subprogram 1234, 5 times.
If a subprogram is only called once, the aaa parameter can be omitted.
E.g., M98 P1234
This calls subprogram 1234 just once.
Example:
Since the tool diameter is 80 mm. and the width of the plate is 100 mm., two cuts are
required at each depth. The tool path at each cut is:
Page 22 of 50
The program segment to face mill this part would look like this (the text in brackets is
comments, and this is exactly how you can insert comments in an actual program):
--------G00 X-45.0 Y35.0 (RAPID TO BOTTOM LEFT OF PART)
Z4.0 (RAPID TILL TOP OF PART)
(CUT 1)
G91 G00 Z-1.0 (MOVE 1 MM. DOWNWARDS)
G90 G01 X165.0 F300.0
Y70.0
X-45.0
G00 Y35.0
(CUT 2)
G91 G00 Z-1.0 (MOVE 1 MM. DOWNWARDS)
G90 G01 X165.0 F300.0
Y70.0
X-45.0
G00 Y35.0
(CUT 3)
G91 G00 Z-1.0 (MOVE 1 MM. DOWNWARDS)
G90 G01 X165.0 F300.0
Y70.0
X-45.0
G00 Y35.0
(CUT 4)
G91 G00 Z-1.0 (MOVE 1 MM. DOWNWARDS)
G90 G01 X165.0 F300.0
Y70.0
X-45.0
G00 Y35.0
--------Note that the tool path is the same for each cut. This segment can be put in a
subprogram that is called 4 times from the main program. The main program and
subprogram can be written like this:
Main program:
--------G00 X-45.0 Y35.0
Z4.0
G01 Z0 F250.0
M98 P0042456 (CALL SUBPROGRAM 2456, 4 TIMES)
CAMLab - Milling Programming Guide
Page 23 of 50
--------Subprogram:
%
O2456 (SUBPROGRAM 2456)
G91 G00 Z-1.0
G90 G01 X165.0 F300.0
Y70.0
X-45.0
G00 Y35.0
M99 (END OF SUBPROGRAM)
Page 24 of 50
Canned cycles
A canned cycle is a single command that executes a machining operation that is a
sequence of tool motions. The cycle typically consists of a block with data defining the
operation, like the safe approach position, final depth, etc. Once a cycle is programmed,
it is executed automatically at whichever X,Y position the tool is moved to. There is no
need to repeat the cycle at each position. The cycle is canceled with a specific cancel
command.
Canned cycles in Fanuc
G81
G82
G73
G83
G76
G84
G85
G87
G80
Drilling
Counterboring
Peck drilling
Deep drilling
Finish boring
Tapping
Reaming
Back boring
Cancel cycle
Page 25 of 50
Tool path
Page 26 of 50
Example
Page 27 of 50
Tool path
1.
2.
3.
4.
Format
G82 X_ Y_ Z_ R_ P_ F_
X, Y = Hole position
Z = Hole depth
R = Initial safe position
P = Dwell time at bottom of hole, seconds x 1000
F = Feed rate
Example
CAMLab - Milling Programming Guide
Page 28 of 50
Page 29 of 50
Tool path
1.
2.
3.
4.
5.
Format
G73 X_ Y_ Z_ R_ Q_ F_
X, Y = Hole position
Z = Hole depth
R = Initial safe position
Q = Depth of each peck
F = Feed rate
Example
CAMLab - Milling Programming Guide
Page 30 of 50
Page 31 of 50
Tool path
1.
2.
3.
4.
5.
6.
7.
Format
G83 X_ Y_ Z_ R_ Q_ F_
X, Y = Hole position
Z = Hole depth
R = Initial safe position
Q = Depth of each peck
F = Feed rate
Page 32 of 50
Example
Page 33 of 50
Tool path
1.
2.
3.
4.
5.
6.
Format
G76 X_ Y_ Z_ R_ Q_ P_ F_
X, Y = Hole position
Z = Hole depth
R = Initial safe position
Q = Shift amount at bottom of hole
P = Dwell time at bottom of hole
F = Feed rate
CAMLab - Milling Programming Guide
Page 34 of 50
Example
Page 35 of 50
Tool path
1.
2.
3.
4.
5.
6.
7.
Format
G84 X_ Y_ Z_ R_ P_ F_
X, Y = Hole position
Z = Hole depth
R = Initial safe position
P = Dwell time at bottom of hole
F = Feed rate
CAMLab - Milling Programming Guide
Page 36 of 50
Example
Page 37 of 50
Tool path
1.
2.
3.
4.
5.
6.
7.
Format
G74 X_ Y_ Z_ R_ P_ F_
X, Y = Hole position
Z = Hole depth
CAMLab - Milling Programming Guide
Page 38 of 50
Page 39 of 50
Tool path
Page 40 of 50
Example
Page 41 of 50
Tool path
Page 42 of 50
Page 43 of 50
Example
Page 44 of 50
Page 45 of 50
Absolute mode
Incremental mode
Feed per minute
Feed per revolution
Return to initial point in canned cycle
Return to safe position point in canned cycle
M-codes
Most M codes activate machine functions like the coolant, spindle, etc. These are decided by the
machine manufacturer, and depend on the features that are available on the machine. E.g., a
machine with a pallet changer will have an M code for pallet change. A few (like M00, M01, M02, M98,
etc. in the list below) are fixed and based on the controller.
Sample list of M codes
M00 Program stop
M01 Optional program stop
M02 Program end
M03 Spindle ON clock wise (CW)
CAMLab - Milling Programming Guide
Page 46 of 50
M04
M05
M06
M08
M09
M30
M98
M99
Page 47 of 50
%
O1234
G21 G94
N1 G0 G90 G53 G49 Z0 H0
T1 M6 (50.00 MM. DIA. ROUND INSERT - FACE MILL)
(FACE MILLING)
S803 M3
G90 G00 G54 X-30. Y22.
G43 H1 Z100. M08
Z8.
G01 Z5. F315
M98 P0020055
G90 G00 Z8.
M5
Z100. M09
N2 G0 G90 G53 G49 Z0 H0
T2 M6 (10.00 MM. DIA. SPOT DRILL)
(CENTER DRILLING)
G54 X20. Y25. S891 M3
G43 H2 Z100. M08.
CAMLab - Milling Programming Guide
Page 48 of 50
Page 49 of 50
The complete sequence of steps involved in generating a machined part from the
drawing is:
Page 50 of 50
About Cadem
Cadem is a 20 year old company, India's leading provider of productivity solutions for the manufacturing industry. Its
range of industrial products for CAD/CAM and DNC are enabling shop floors to improve the productivity of their CNC
machines. Many of India's best known CNC shop floors use the products. Cadem's products are exported to 30 countries,
in 4 languages. Premier CNC machine tool companies endorse and recommend Cadem's software to their customers.
Cadem's CNC educational products are the first-choice for Engineering Institutes in India. The products form the mainstay
of CAD/CAM labs in most of India's best known institutes, and in in-house tech centers and training centers of industries.
The Productivity Institute of the IMTMA (Indian Machine Tool Manufacturers' Association) uses Cadem software and
know-how for training engineers from industry around the country.
Cadem has won the coveted CMTI-PMT Trust award for Best Design Innovation Award 3 times and was named as one of
the TOP 100 Innovators in 2007 by NASSCOM.
CADEM
effiCNC
TM