Parts of a CNC program
•Just like a written letter to a friend or business
contact is comprised of three main parts
•salutation,
•body, and
•closing,
a CNC program is essentially broken into three similar
main parts:
•the salutation “program safe-start,”
•the body “material removal,”
•and the closing “program ending.”
CNC Programming
•There is no standardized format for writing a CNC
program that is compatible with all machine control
models.
•Each MCU manufacturer has developed its own
unique programming format.
•Each one has minor differences, but the principles
contained in the context of a program are the same
among them all.
•The programming examples provided in these slides
will relate the most closely to Fanuc-type controllers;
however, the principles may be applied to any
manufacturer’s programming format (see the
specific machine’s programming manual).
CODES
•Along with telling the machine what position to go to, the
programmer must also provide the machine with instructions
telling it what to do at that position.
CODES
G codes
M codes
Preparatory codes
Miscellaneous codes
CODES
G codes
M codes
Carry out machining
operations
Establish machine
settings
Control the machine
functions other than
tool movements
CODES
G codes
Carry out machining
operations
Establish machine
settings
G Codes - Axial Movements
G00Rapid traverse
Moves the tool at a very fast rate to a
specified point
G01
Linear
interpolation
Machining in a straight line at a feed
rate
G02
Clockwise Circular
interpolation
Machining in a clockwise circular arc
at a given feed rate
G03
Counter-clockwise
Circular
interpolation
Machining in a counter-clockwise
circular arc at a given feed rate
G28
Return to machine
home position
(Rapid traverse) Moves the tool at a
very fast rate to the home position
Coordinate positioning : Radial
+X
- X
+Z
- Z
We will NOT use Radial
system for this course
Coordinate positioning : Diametral
+X
- X
+Z
- Z
We will use Diametral
system for this course
G Codes - Axial Movements
T
o
o
l
G00Rapid traverse
Moves the tool at a very fast rate to a
specified point
G00X30Z5
Home Position
X30 Z5
40
+X
- X
+Z
- Z
G Codes - Axial Movements
T
o
o
l
G01
Linear
interpolation
Machining in a straight line at a feed
rate (one or more axes)
G01X30Z-20F40
G00X30Z5
X30 Z-20
40
+X
- X
+Z
- Z
X30 Z5
Feed rate
G Codes - Axial Movements
Ø40 Ø30
35
G00X30Z5
G01X30Z00F40
X40Z-35
12
3
(Home 1)
(1 2)
(2 3)
Home
Position
+X
- X
+Z
- Z
G Codes - Axial Movements
G02
Clockwise Circular
interpolation
Machining in a clockwise circular arc
12
+X
- X
+Z- Z
G02X40Z-25R10
15
25
3
R10
G00X20Z5
G01X20Z-15F40
Ø40 Ø20
Clockwise
Radius
G Codes - Axial Movements
G03
Counter-clockwise
Circular
interpolation
Machining in a counter-clockwise
circular arc
12
G03X40Z-25R10
15
3
R10
G00X20Z5
G01X20Z-15F40
Ø40 Ø20
25
Ø40 Ø20
+X
- X
+Z- Z Counter-
clockwise
Radius
G Codes – Machine Setup
For Milling ONLY
G90Absolute positioning
All coordinates are relative to the
reference position
(i.e. Workpiece Origin)
G91Incremental positioning
All coordinates are relative to the
current position
For Turning ONLY
No need to write G code for the following in Turning
×
Absolute positioning
Machine will run on Absolute Mode by
default
×
Incremental positioning
U Incremental mode in X axis
W Incremental mode in Z axis
G Codes - Axial Movements
G28
Return to machine
home position
(Rapid traverse) Moves the tool at a
very fast rate to the home position
G28U00W00
Tool will
•move 00 in the X direction
and 00 in the Z direction
(incremental mode)
•and then will return to the
Home position
Incremental
mode in
X axis
Incremental
mode in
Z axis
Important point
T
o
o
l
Home
Position
40
+X
- X
+Z
- Z
G Codes – Machine Setup
G20Imperial input Inch programming units
G21Metric input
Millimetre programming units
G98Feed per minute inches/millimetres per minute
G99Feed per revolutioninches/millimetres per rev
A
B
C
D
0
0
+Y
-Y
+X-X
X Y
A
B
C
D
CODES
M codes
Control the machine
functions other than
tool movements
M codes : Group 1
M00Program Stop utility stop for operator actions
M01Optional Program Stopoperator selected or ignored
M02Program End
needs manual reset to start
again from the beginning
M30
Program End and
Rewind
stop and automatic reset
M codes : Group 2
M03 Spindle ON (Clockwise)
M04 Spindle ON (Anti-Clockwise)
M05 Spindle OFF
M06 Tool Calling
M08 Coolant ON
M09 Coolant OFF
Ø50 Ø40
Ø20
10
30
45
50
AB
C
D
E
+Z
-Z
-X
+X
X40Z-30
G00X20Z5
G01X20Z-10F40
X40Z-45
G02X50Z-50R5
+Z
-Z
-X
+X
+Z
-Z
-X
+X
Roughing depth of
Cut
+Z
-Z
-X
+X
+Z
-Z
-X
+X
+Z
-Z
-X
+X
+Z
-Z
-X
+X
+Z
-Z
-X
+X
+Z
-Z
-X
+X
Material to be left
for finish pass
+Z
-Z
-X
+X
Material being
removed by
finishing pass
+Z
-Z
-X
+X
Roughing depth of
Cut
Material to be left
for finish pass
Canned Cycles
•Many turning operations require tedious and
redundant motions, such as the multiple passes
performed during a rough turning operation or
multiple pecks required for deep hole-drilling
operations.
•Machine control manufacturers have equipped the
controls with features that make these tedious
operations easier and faster to program.
•These machining routines can be packaged or
“canned” into one or two blocks of code and are
called canned cycles.
Stock Removal Turning Cycle : G71
•Function G71 is the stock removal cycle for turning
that removes metal along the direction of the Z axis.
In a case where there is a lot of material to be
removed, this cycle provides an easy method for
programming.
•There are two program blocks required for function
G71.
G71U R
G71P Q U W F
Block 1
Block 2
Stock Removal Turning Cycle : G71
G71U R
G71P Q U W F
Block 1
Block 2
depth of
roughing cut
(no sign)
amount of retract, along
the X axis, for each cut
block number where the
code for the contour
begins
block number where the
code for the contour
ends
amount of material for
finishing to be left on
all diameters
(X axis)
amount of material for
finishing to be left on
all faces
(Z axis)
roughing feed rate
Stock Removal Turning Cycle : G71
Depth of Cut U
Retract amount R
finish amount to be left
on the diameter U
finish amount to be left
on Z-axis faces W
+Z- Z
+X
-X
10
25
75
5090
R12.5
Rough Stock
diameter
62.5
Stock Removal Turning Cycle : G71
N30G71P40Q80U1W1F30
N10G00X95Z5
N20G71U5R0.5
N40G00X10Z5
N50G01X10Z-25
N60 X50Z-62.5
N70G02X75Z-75
N80G01X95Z-75
Block 1
Block 2
C
y
c
le
B
lo
c
k
s
Finishing Cycle : G70
G70P Q F S
block number where the
code for the finishing contour
begins
block number where the
code for the finishing contour
ends
feed rate, effective for
blocks P through Q
spindle speed,
effective for blocks P
through Q
Stock Removal Turning Cycle : G71 and Finishing
Cycle G70
N30G71P40Q80U1W1F30
N10G00X95Z5
N20G71U5R0.5
N40G00X10Z5
N50G01X10Z-25
N60 X50Z-62.5
N70G02X75Z-75
N80G01X95Z-75
Block 1
Block 2
C
y
c
le
B
lo
c
k
s
G70P40Q80F10S1500
Finishing Cycle
Examples of Stock Removal Turning Cycle G71
program
•Refer to “CNC Lab Qs” pdf file
20
+X
- X
+Z- Z
X12 Z2
Ø10
G21 G98 (Metric unit and feed in mm/min)
G28 U0 W0 (Go to home position)
M06 T0101 (Tool 1 & Offset 1)
M03 S2500 (Clockwise spindle at 2500rpm)
G00 X12 Z2 (Go to home position)
G94 X0 Z-2 F100 (Facing cycle)
Z-4
G28 U0 W0 (Go to home position)
M05 (Spindle stop)
M30 (Program end and rewind)
Facing Cycle : G94
P
( Home → P )
20
18
+X
- X
+Z- Z
Z-2
X12 Z2
Ø10
G21 G98 (Metric unit and feed in mm/min)
G28 U0 W0 (Go to home position)
M06 T0101 (Tool 1 & Offset 1)
M03 S2500 (Clockwise spindle at 2500rpm)
G00 X12 Z2 (Go to home position)
G94 X0 Z-2 F100 (Facing cycle)
Z-4
G28 U0 W0 (Go to home position)
M05 (Spindle stop)
M30 (Program end and rewind)
Facing Cycle : G94
P
( Home → P )
20
18
+X
- X
+Z- Z
Z-2
X12 Z2
Ø10
G21 G98 (Metric unit and feed in mm/min)
G28 U0 W0 (Go to home position)
M06 T0101 (Tool 1 & Offset 1)
M03 S2500 (Clockwise spindle at 2500rpm)
G00 X12 Z2 (Go to home position)
G94 X0 Z-2 F100 (Facing cycle)
Z-4
G28 U0 W0 (Go to home position)
M05 (Spindle stop)
M30 (Program end and rewind)
Facing Cycle : G94
P
( Home → P )
20
18
16
+X
- X
+Z- Z
Z-2
Z-4
X12 Z2
G21 G98 (Metric unit and feed in mm/min)
G28 U0 W0 (Go to home position)
M06 T0101 (Tool 1 & Offset 1)
M03 S2500 (Clockwise spindle at 2500rpm)
G00 X12 Z2 (Go to home position)
G94 X0 Z-2 F100 (Facing cycle)
Z-4
G28 U0 W0 (Go to home position)
M05 (Spindle stop)
M30 (Program end and rewind)
Facing Cycle : G94
P
( Home → P )
Peck Drilling Canned Cycle G74
G74R
G74X Z Q F
total absolute Z-depth
amount of retract
peck increment
or
depth of cut in Z axis
Micrometre (µm)
Feed rate
X-axis hole location
(part centerline)
Clearance
Z
Q
R
Clearance
G74R
G74X Z Q F
Micrometre (µm)
Micrometre (µm)
Threading Cycle : G76
G76P000000 Q R
G76X Z P Q F
Block 1
Block 2
number of
finishing cuts
angle of
the thread
minor diameter
(Major Dia - 2*Thread Height)
Final end position of the
thread along the Z axis
Height of thread in
micron
(= 0.613*Pitch)
First pass depth of cut
feed rate (normally
equal
to the thread pitch).
Relief angle (to
retract it may be
require some
angle)
minimum cut
depth for rough
cut
depth of the final
pass
(finishing
allowance)
Micrometre (µm) in software
mm in machine
Micrometre (µm) in software
mm in machine
Micrometre (µm) in
software
mm in machine