Digital Manufacturing Laboratory
CNC Programming
CNC Machine
CNC machine Tool
• Numerical control is a
programmable automation in
which process is controlled by
Numbers, Letters, and symbols
• CNC Machining is a process
used in the manufacturing
sector that involves the use of
computers to control machine
tools like lathes, mills, drills,
grinders etc.
CNC machine Tool
CNC machine Tool
CNC machine Tool - Machine Control unit
The machine control unit is called the heart of the CNC
machine.
• It reads the coded instructions given in it.
• Machine control unit decodes the coded instruction.
• This axis implements interpolation (linear, circular
and helical) to generate motion commands.
• Machine control unit feeds the axis motion
command to the amplifier circuit to drive the axis
mechanism.
• It takes a feedback signal of position and speed for
each drive axis.
• It implements the auxiliary control functions such as
coolant or spindle on/off and tool change.
CNC machine Tool - Machine Control unit
Simplified operation procedures of CNC Machine)
Turning and Milling
CNC turning centre
Horizontal CNC Milling Machine Vertical CNC Milling Machine
Coordinate system
X - Primary Feed axis Z - Spindle axis Y - Remaining axis
Coordinate system
X - Primary Feed axis Z - Spindle axis Y - Remaining axis
Coordinate system
Programming Systems
• Both systems have applications in CNC programming, and
no system is either right or wrong all the time.
• Most controls on machine tools today are capable of
handling either incremental or absolute programming.
Incremental program
• locations are always given as the distance and direction from
the immediately preceding point
Absolute program locations
• always given from a single fixed zero or origin point
• According to the type of
motion
✔ Point-to-point systems:
• the cutting tool moves to a
numerically defined location,
the motion is stopped and the
task is performed.
• After completing the task, the
tool moves to the next point
and the cycle is repeated.
• the path of movement of the
tool and its velocity, when the
tool moves from one point to
another, is of no significance.
Contouring or continuous systems
• The tool has to move in a predetermined
path in the case of contouring or
continuous systems.
• involves work such as that produced on
a lathe or milling machine, where the
cutting tool is in contact with the
workpiece as it travels from one
programmed point to the next.
• Continuous path positioning is the
ability to control motions on two or
more machine axes simultaneously to
keep a constant cutter-workpiece
relationship
Programming fundamentals
Reference Points
1. Machine Origin
2. Program Origin
3. Part Origin
Part program
• A series of coded instructions required to produce a part
• The coded instructions are composed of letters, numbers and symbols
• Controls the movement of the machine tool and on/off control of auxiliary
functions such as spindle rotation and coolant
▪ Types:
1. Manual Part Programming
2. Computer Aided Part Programming
23
Steps in Part Programming
•Study of Drawing
•Identify Machine Tool
•Identify Operations
•Select Cutting Tool
•Determine Spindle Speed, Feed, etc.
•Decide Other Parameters
•Prepare Job and Tool Setup Plans
•Part Program
• Test Part Program
• Prepare Job and Tool Setup Plans
25
CNC Program Structure
Character Word Block Program
• Character is the smallest unit of CNC program. It can have Digit / Letter / Symbol.
• Word is a combination of alpha-numerical characters. This creates a single instruction to
the CNC machine. Each word begins with a capital letter, followed by a numeral. These
are used to represent axes positions, federate, speed, preparatory commands, and
miscellaneous functions.
• A program block may contain multiple words, sequenced in a logical order of processing.
• The program comprises of multiple lines of instructions, ‘blocks’ which will be executed
by the machine control unit (MCU).
26
EIA RS-274 standard
• Fixed Block format
N X Y M F S
001 10 10 03 200 500
002 20 10 03 200 500
• Tab sequential format
T0010 T01 T07500 T06250 T T612
• Word-address format
N001 G01 X10 Y10 S612 T0101 M30 ;
N002 X20;
CNC Program Structure
N10 G01 X20 Y10 F50 S200 T01 M06
N -Sequence number (Used for line identification)
G -Preparatory function
X Y Z A B C I J K-Coordinate designation
F –Feed rate designation
S -Spindle speed designation
T -Tool Designation
M -Miscellaneous function
28
Common G Codes
G00 Rapid traverse G40 Cutter compensation cancel
G01 Linear interpolation G41 Cutter compensation left
G02 Circular interpolation G42 Cutter compensation right
clockwise (CW) G43 Tool length compensation (+)
G03 Circular interpolation G44 Tool length compensation (-)
counterclockwise (CCW) G49 Tool length compensation
G20 Inch input (in.) cancels
G21 Metric input (mm) G 53 Zero offset or M/c reference
G24 Radius programming G54 Settable zero offset
G28 Return to reference point G80 Canned cycle cancel
G29 Return from reference point G90 Absolute programming
G32 Thread cutting G91 Incremental programming
30
Common M Codes
Code Function
M00 Program stop
M02 End of program
M03 Spindle start (CW)
M04 Spindle start (CCW)
M05 Spindle stop
M06 Tool change
M08 Coolant on
M09 Coolant off
M30 End of program (Reset) 31
Fanuc G-Code List (Lathe)
G Description
G code Description
code
G00 Rapid traverse G40 Tool nose radius compensation cancel
G01 Linear interpolation G41 Tool nose radius compensation left
G02 Circular interpolation CW G42 Tool nose radius compensation right
G03 Circular interpolation CCW G70 Finish machining cycle
G04 Dwell G71 Turning cycle
G09 Exact stop G72 Facing cycle
G10 Programmable data input G73 Pattern repeating cycle
G20 Input in inch G74 Peck drilling cycle
G21 Input in mm G75 Grooving cycle
G22 Stored stroke check function on G76 Threading cycle
G23 Stored stroke check function off G92 Coordinate system setting or
G27 max. spindle speed setting
Reference position return check
G28 G94 Feed Per Minute
Return to reference position
G32 G95 Feed Per Revolution
Thread cutting
G96 Constant surface speed control
G97 Constant surface speed control cancel 32
Fanuc G-Code List (Mill)
G code Description G code Description
G00 Rapid traverse G68 Coordinate rotation
G01 Linear interpolation G69 Coordinate rotation cancel
G02 Circular interpolation CW G73 Peck drilling cycle
G03 Circular interpolation CCW G74 Left-spiral cutting circle
G04 Dwell G76 Fine boring cycle
G17 X Y plane selection G80 Canned cycle cancel
G18 Z X plane selection G81 Drilling cycle, spot boring cycle
G19 Y Z plane selection G82 Drilling cycle or counter boring cycle
G28 Return to reference position G83 Peck drilling cycle
G84 Tapping cycle
G30 2nd, 3rd and 4th reference position return
G85 Boring cycle
G40 Cutter compensation cancel
G86 Boring cycle
G41 Cutter compensation left
G87 Back boring cycle
G42 Cutter compensation right
G88 Boring cycle
G43 Tool length compensation + direction
G89 Boring cycle
G44 Tool length compensation – direction G90 Absolute command
G49 Tool length compensation cancel G91 Increment command
G53 Machine coordinate system selection G92 Setting for work coordinate system or clamp at maximum
G54-G59 Work piece coordinate system 1,2,3,4,5,6 selection spindle speed
G98 Return to initial point in canned cycle
G99 Return to R point in canned cycle 33
Fanuc M-Code List (Lathe) Fanuc M-Code List (Mill)
M code Description M code Description
M00 Program stop M00 Program stop
M01 Optional program stop M01 Optional program stop
M02 End of program M02 End of program
M03 Spindle start forward CW M03 Spindle start forward CW
M04 Spindle start reverse CCW M04 Spindle start reverse CCW
M05 Spindle stop M05 Spindle stop
M08 Coolant on M06 Tool change
M09 Coolant off M07 Coolant ON – Mist coolant/Coolant thru spindle
M29 Rigid tap mode M08 Coolant ON – Flood coolant
M30 End of program reset M09 Coolant OFF
M40 Spindle gear at middle M19 Spindle orientation
M41 Low Gear Select M28 Return to origin
M42 High Gear Select M29 Rigid tap
M68 Hydraulic chuck close M30 End of program (Reset)
M69 Hydraulic chuck open M41 Low gear select
M78 Tailstock advancing M42 High gear select
M79 Tailstock reversing M94 Cancel mirrorimage
M94 Mirrorimage cancel M95 Mirrorimage of X axis
M95 Mirrorimage of X axis M96 Mirrorimage of Y axis
M98 Subprogram call M98 Subprogram call 34
M99 End of subprogram M99 End of subprogram
Part Programming for
Turning
Typically, Programs are Arranged in the Following order:
1) Program Start
2) Load Tool
3) Spindle On
4) Coolant On
5) Rapid to position above part
6) Machining operation
7) Coolant Off
8) Spindle Off
9) Move to safe position
10) End program
37
Command G-code
Function and Command Statement
group
Rapid traverse
G00
G00 Xx Zz
Linear interpolation
G01 G01 Xx Zz
Circular Interpolation in clock-wise direction
G02 Xx Zz Ii Kk
Tool motion G02 (or)
G02 Xx Zz Rr
Circular interpolation in counter- clockwise direction
G03
G03 Xx Zz Ii Kk
(or)
G03 Yy Zz Rr
38
Rapid traverse
39
Linear interpolation
40
Circular interpolation (CW)
Circular interpolation (CCW)
41
Points Coordinates
X Z
P0 25 0
P1 25 -7.5
P2 40 -15
P3 40 -25
P4 60 -35
42
FANUC Control
%; Symbol
O0001; Program no. & ID
N1 G90 G21 G96 G94 ; Absolute, Metric, Constant speed, feed mm/min
N2 G28 U0 W0 ; Move to reference position
N3 M06 T01 ; Tool change T1 turning tool
N4 M03 S500 ; Spindle rotation clockwise with 500 RPM
N5 G42 G00 X0 Z0 ; tool nose radius compensation active, Part origin
N6 G01 X25 F0.3 ; P0
N7 G01 Z-7.5 ; P1
N8 G01 X40 Z-15 ; P2
N9 G01 Z-25 ; P3
N10 G01 X60 Z-35 ; P4
N11 G40 G00 X200 Z100 ; Tool nose radius compensation cancel
N12 M05 M09 M02 M30; Spindle off, coolant off , Program end, END of Tape & Rewind
43
G72 Facing Cycle
G72 P… Q… U… W… D… F… S…
Parameter Description
P Contour start block number.
Q Contour end block number.
U Finishing allowance in x-axis.
W Finishing allowance in z-axis.
D Depth of cut.
F Feed-rate (overrides the feed-rates given between P
block and Q block)
S Spindle Speed (overrides the spindle speed given
between P block and Q block)
N011 G50 X220.0 Z190.0
N012 G00 X176.0 Z132.0
N013 G72 P014 Q019 …
U4.0 W2.0 D7000 F0.3 S550
N014 G00 Z56.0 S700
N015 G01 X120.0 W14.0 F0.15
N016 W10.0
N017 X80.0 W10.0
N018 W20.0
N019 X36.0 W22.0
N020 G70 P014 Q019
G71 Turning/Roughing Cycle
Programming
G71 U... R...
G71 P... Q... U... W... F... S…
First block Second block
Parameter Description
Parameter Description P Contour start block number.
U Depth of cut. Q Contour end block number.
R Retract height. U Finishing allowance in x-axis.
W Finishing allowance in z-axis.
F Feedrate during G71 cycle.
S Spindle speed during G71 cycle.
G71 Turning Cycle
N50 G00 X106 Z5 M3 S800 N50 G00 X106 Z5 M3 S800
N60 G71 U10 R10
N60 G71 U10 R10 N70 G71 P80 Q90 U3 W0 F0.25
N80 G00 X60
N90 G01 Z-75 F0.15
N70 G71 P80 Q90 U3 W0 F0.25 N100 G00 X200 Z100
N110 G92 S1200
N80 G00 X60 N120 T3 G96 S150 M03
N130 G00 X106 Z5
N140 G70 P80 Q90
N90 G01 Z-75 N150 G00 X200 Z100
N160 M30
G70 Finishing Cycle
O0004
G00 X200 Z10 M3 S800
G71 U2 R1 F200
G71 P80 Q120 U0.5 W0.2
N80 G00 X40 S1200
G01 Z-30 F100
X60 W-30
W-20
N120 X100 W-10
G70 P80 Q120 M30
G75 Grooving Cycle
G75 R
G75 X Z P Q R
G75 First CNC Programming Block
R = Return amount
G75 Second CNC Programming Block
X = Groove Depth.
Z = Last groove position in z-axis.
P = Peck increment in x-axis
Q = Stepping in z-axis.
R = Relief amount at end of the cut.
N10 G50 S500 T0100
N20 G97 S400 M03
N30 G00 X90.0 Z1.0 T0101
N40 X82.0 Z-60.0
N50 G75 R1.0
N60 G75 X60.0 Z-20.0 P3000 Q20000 F0.1
N70 G00 X90.0
N80 X200.0 Z200.0 T0100
N90 M30
N5 G76 P010060 Q100 R0.05 G76 Threading Cycle
N6 G76 X30 Z-20 P1024 Q200 F2
First block of the G76 Threading cycle
Second block of the G76 Threading cycle
G76 : G code for threading cycle.
G76 : G code of the threading cycle.
P : P actually consists of multiple values which control the
X : The end value in x-axis.
thread behavior,
01 : Number of spring passes or spring cuts. Z : The end value in z-axis.
00 : Thread run out at 45 degree P : Thread depth ( as radius value ).
60 : Flank angle or Infeed angle Q : Depth of first cut.
Q : Depth of normal cut F : Thread Pitch
( these values are given in hundreds, so the depth of cut R : Thread Taper
will be 0.1 ).
R : Depth of Last or Finish cut
N10 T3
N20 G97 S800 M03
N30 G00 X30 Z5 T0303
N40 G76 P021060 QI00 R100
N50 G76 X18.2 Z-20 P900 Q200 FI.5
N60 G00 X50 Z-20
N70 G76 P021060 Ql00 R100
N80 G76 X38.2 Z-52 P900 Q200 FI .5
N90 G00 X200 Z200
N100 M30
Part Programming for
Milling
PLANE SELECTION (G17, G18, G19)
To select the XY-plane as active, program: G17
To select the XZ-plane as active, program: G18
To select the YZ-plane as active, program: G19
The active plane determines how the tool path of an arc (G02 or G03) or canned
cycle (G73, G81 through G89) is interpreted.
56
G43 G44 G49 Tool Length Compensation
G43 Tool Length Compensation positive
With G43 a value from the offset register (OFFSET) can be called up and added
to tool length to all following Z movements (with active XY plane – G17) in the
program
N... G43 H05
G44 Tool Length Compensation negative
With G44 a value from the offset register (OFFSET) can be called up and
subtracted from tool length to all following Z movements (with active XY
plane – G17) in the program
G49 Cancel Tool Length Compensation
The positive (G43) or negative (G44) shift will be cancelled.
G90 G00 X-1.0 Y-1.0 ; point S
G01 X0 Y0 F7.5 ; point A
Y2.134 ; point B
G03 X0.5 Y3.0 I-0.5 J0.866 ; point C
X0. Y3.866 I-1. J0 ; point D
G01 Y5.5 ; point E
G02 X0.5 Y6.0 I0.5 J0 ; point F
G01 X4.5 ; point G
G02 X6.0 Y4.5 I0 J-1.5 ; point H
G01 Y0 ; point I
X0 ; point A
G00 X-1.0 Y-1.0 ; point S
N5 G00 G54 G64 G90 G17 X-20 Y-20 Z50;G54 : Zero Offset no. 1.G64 :
Continuous-path mode.
N10 S450 M03 F250 D01 (12.5 MM DIA)
N15 G00
N20 Z5
N25 G01 Z0
N30 Z-5
N35 G42 X0 Y0 M08 (Liner motion)
N40 X60 Y0 (Liner motion)
N45 X85 Y30 (Liner motion)
N50 X85 Y50 (Liner motion)
N55 G03 X70 Y65 U15 (Circular motion G03 for Counter Clockwise motion and
U for arc radius)
N60 G01 X45 Y65 (Liner motion)
N65 G02 X30 Y50 U15 (Circular motion G02 for Clockwise motion and U for
arc radius)
N70 G01 X10 Y50 (Liner motion)
N75 X0 Y0 (Liner motion)
N80 G40 X-20 Y-20
N85 G00 Z50 M09
N90 Y100
N95 M30
N05 G0 G90 X40 Y48 Z2 S500 M3
N10 G1 Z-12 F100
N15 X20 Y18 Z-10
N20 G0 Z100
N25 X-20 Y80
N30 M2
N40 M30
G82 counter boring cycle.
G82 X... Y... Z... R... P... F... K...
Parameter Description
X Hole position in x-axis.
Y Hole position in y-axis.
Z Depth, tool will travel with feed to Z-depth starting
from R plane.
R Position of the R plane.
P Dwell at the bottom of hole.
K Number of cycle repetitions (if required)
F Feed rate.
Working
How G82 drilling cycle works
1- Rapid traverse to x, y position
2- Rapid traverse to R-plane position
3- Drilling with feed from R-plane to Z-depth position.
4- Dwell for specified time at hole bottom.
5- Rapid traverse to R-plane or Initial-level depends on G99, G98
mode.
Figure shows the final profile required to be finish-contoured and the holes to be drilled by using a CNC Vertical
Machining Center. Write an EFFICIENT CNC part program for the same.
Assume the finishing allowance of about 2 mm.
Points Coordinates
X Y
P2 P3 P6 P7 P0 0 0
P1 P4 P5
P8 P1 0 110
P2 15 125
P3 55 125
P4 55 110
P9 P5 95 110
P10 P6 95 125
P0 P7 125 125
P8 150 100
P9 150 35
P10 135 0
%
N230 G90 X 25 Y100
O0001
N10 G21 G90 G17 G40 G80 N240 M98 P0002
N20 G92 X.. Y.. Z.. N250 G90 X125 Y70
N30 M06 T01 N260 M98 P0002
N30 G00 X0 Y0 N270 G80 M09
N40 G43 Z10 H01 M08 N280 G28 Z10 M05
N50 M03 S1000 N290 G28 X0Y0
N60 G01 Z-20 F50
N70 G41 X0 D01 F25
N300 M06 T02
N80 Y110 N310 G00 X75 Y30
N90 G02 X15 Y125 R15 N320 G43 Z10 H02 M08 SUB PROGRAM
N100 G01 X55 N330 M03 S800 %
N110 Y110 N340 G99 G81 R10 Z-20 N350 F30
N120 X95
O002
N360 Y60
N130 Y125
N370 Y90
N10 G91 X15
N140 X125
N150 G03 X150 Y100 R25 N380 G40 G80 M09 N20 X-15 Y0
N160 G01 Y35 N390 G28 Z10 M05 N30 X0 Y-15
N170 X135 Y0 N400 G28 X0Y0
N180 X-20 N410 M02
N40 X0 Y15
N190 G00 Z10 N420 M30 N50 M99
N200 X25 Y40
N210 G99 G81 R10 Z-20 F30
N220 M98 P0002
G83 peck drilling cycle
Parameter Description
X Hole position in x-axis.
Y Hole position in y-axis.
Z Depth, tool will travel with feed to Z-depth starting
from R plane.
R Position of the R plane.
Q Depth of cut for each cutting feed (Peck).
K Number of cycle repetitions (if required)
F Feed rate.
Working
1- Rapid traverse to X, Y drilling
position.
2- Rapid traverse to R-plane.
3- Drilling with feed Q deep.
4- Retraction with Rapid traverse to
R-plane.
5- Rapid traverse to Q-d deep (d value
is specified in parameters).
6- Drilling with feed Q+d deep.
7- Retraction with Rapid traverse to
R-plane
– this whole procedure is repeated
until drill reaches Z-depth position,
– then drill is retracted to R-plane or
Initial-level depends on G99 or G98
which one is given in program.
G84 tapping cycle
Parameter Description
X Hole position in x-axis.
Y Hole position in y-axis.
Z Depth, tapping from R-plane to Z-depth.
R Position of the R plane.
P Dwell time.
K Number of cycle repetitions (if required)
F Feedrate.
0- CW Spindle rotation command (M03)
must be given in part-program.
1- Rapid traverse to X, Y position (pre-drill
hole position).
2- Rapid traverse to R-plane.
3- Tapping operation is done till Z-depth
(with tapping feed given with G84).
4-1- Dwell for time specified with P
4-2- Spindle is rotated CCW
5- Tap is Retracted with the specified feed.
At R-plane spindle is rotated CW.
If G99 is specified then tapping for this hole
ends here,
6- if G98 is given in program then tap is
moved to Initial-level
CNC Pocket Milling Program
Main Program Subprogram
Milling cutter diameter: 10mm O0035
N05 G55 N05 G1 Z-2 G91 F30
N10 M6 T2 H3 G43 M3
N10 X10 F100
N15 S1000 F60
N20 G0 X9 Y9 Z1
N15 Y36
N25 G1 Z0 N20 X-10
N30 M98 P030035 N25 Y-36
N35 G0 Z1 G90 N30 M99
N40 X42 Y38
N45 G1 Z-2 F30
N50 X47 F300
N55 G3 X47 Y38 I-5 J0
N60 G0 Z100
N65 G49
N70 M30
NUM CNC Mill Program Example Outer Contour Cutting with through Drilling and
Counterbore to a depth of 5 mm.
%358
N1 (BRIDE)
N10 G90 G71 G80 G40
N20 G0 G52 Z0
(Contour)
N30 T4 D4 M6
N40 G97 S345
N50 G94 F110
N60 G0 X62 Y-18
N70 Z-5 M3 M41
N80 G1 G42 X50 M8
N85 G1 Y33
N90 G3 X38 Y45 R12
N100 G1 X-35 Y45
N110 G2 X-50 Y 30 R15
N120 G1 X-50 Y25
N130 G1 X-35 Y0
N140 G1 X-25 Y0
N150 G2 X25 Y0 R25
N155 G1 X50
N160 G1 G40 X68 Y-12 M9
N170 G0 G52 Z0 M5
(Drilling)
N180 T6 D6 M6
N190 G97 S1061
N200 G94 F74
N210 G0 X38 Y33
N220 Z3 M3 M42
N230 G1 Z-18 M8 (5+10+3)
N240 G0 Z3 M9
N250 G0 G52 Z0 M5
(Counterbore)
N260 T7 D7 M6
N270 G97 S530
N280 G94 F106
N290 G0 X38 Y33
N300 Z3 M3 M40
N310 G1 Z-5 M8
N320 G0 Z3 M9
N330 G0 G52 Z0 M5
N340 M2