Professional Documents
Culture Documents
CNC Programming Guide TURNING
CNC Programming Guide TURNING
TURNING
Forew ord
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 specif ic 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.
I t 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
Block for m a t
G01 X100.0 Z50.0 F0.2 is a block. I t t ells t he t ool t o m ove along a st raight line t o
X100.0 Z50.0 at a feed rat e of 0.2 m m / revolut ion.
A block consist s of a set of words. Each word is a com m and. E.g., X100.0 is a word.
A word consist s of an alphabet called t he address, followed by a num ber. I n X100.0, X is
an address.
Ot her t han coordinat es, t he m ost com m only used words in a program are t he G- codes
and M- codes.
G codes m ost ly involve t ool m ot ion com m ands like rapid m ot ion, feed m ot ion, circular
m ot ion, dwell, and canned cycle codes.
M codes m ost ly involve m achine act ions like spindle on / off, t ool change and coolant on
/ off.
Ax e s con ve n t ion
The Z axis is along t he spindle, while t he X axis is perpendicular t o it . The program zero
is t he int ersect ion of t hese axes. All coordinat es in a program are referenced from t his
point .
Axes on a lat he
Ex a m ple
G0 0 - Ra pid t r a ve r se
When t he t ool is m oving t o a posit ion preparat ory t o execut ing a cut t ing m ot ion or when
it is m oving t o t he t ool change posit ion, t he m ot ion is a essent ially a wast e of t im e and is
execut ed as fast as possible. The m ot ion is called Rapid t raverse. The t im e t aken t o
execut e a rapid m ot ion is also called t he Air cut t im e.
Typical rapid t raverse rat es are 20 t o 40 m / m in., but can be as high as 80 m / m in.
For m a t
G00 X_ Z_
X, Z are t he dest inat ion coordinat es
Ex a m ple
Rapid m ot ion t o P1
G00 X20.0 Z0.0
The t ool m oves along a st raight line in one or t wo axis sim ult aneously at a program m ed
linear speed, t he feed rat e.
For m a t
G01 X__ Z__ F__
X, Z are t he dest inat ion coordinat es
F is t he feed rat e, t he speed of t he linear m ot ion
Ex a m ple
G01 need not be repeat ed in t he second line because it is a 'm odal com m and' – it st ays
act ive t ill it is changed by a different m ot ion com m and.
Mot ion along a circular arc at a program m ed linear speed, t he feed rat e. G02 m oves
along a Clockwise ( CW) arc, G03 m oves along a Count erclockwise ( CCW) arc.
For m a t
A t hreading m ot ion is a m ot ion along a st raight line, but is NOT a linear int erpolat ion
m ot ion. The t ool m ot ion does not st art im m ediat ely when t he com m and is encount ered.
I t is coordinat ed wit h t he rot at ion of t he spindle - t he t ool st art s m oving when an index
pulse is received from t he spindle encoder. This pulse occurs at a specific angular
posit ion of t he spindle, once in each spindle rot at ion. This ensures t hat each t hread
st art s at t he sam e angular posit ion, and each cut follows t he pat h of t he earlier cut .
The Lead is t he axial dist ance t he nut advances in one revolut ion of t he screw, while t he
pit ch is t he dist ance bet ween adj acent t hreads. Lead = Pit ch x No. of st art s. I n a single
st art t hread t he lead is equal t o t he pit ch.
When cut t ing a t hread, for every revolut ion of t he part t he t ool m oves axially by a
dist ance equal t o t he Lead of t he t hread.
For m a t
G32 X__ Z__ F__
The following program segm ent cut s a t hread of 2 m m . pit ch t o a dept h of 0.6 m m .,
from point P1 t o 2 m m . before point P2:
G00 X19.6 Z2.0
G32 Z- 8.0 F2.0
G00 X22.0
Z2.0
The G32 com m and is seldom used. The G76 canned cycle is com m only used because it
can cut a t hread wit h m ult iple cut s at various dept hs by specifying t he pit ch, t hread
dept h, et c. in t wo lines.
A dwell com m and result s in a t em porary st oppage of all axis m ot ions for a specified
durat ion. The spindle m ot ion is not affect ed. I t is t ypically used when t he t ool has
reached t he final posit ion in an operat ion and needs t o st ay t here for a few spindle
rot at ions t o obt ain good dim ensional accuracy or surface finish. For exam ple, in a
grooving operat ion when t he t ool reaches t he bot t om of t he groove it needs t o st ay t here
for at least one full revolut ion. Wit hout a dwell it would ret ract back inst ant aneously and
result in a non- circular cross sect ion at t he groove bot t om .
For m a t
G04 X_
X is t he dwell t im e in seconds.
Ex a m ple
G04 X1.0
Fe e dr a t e
The feed rat e is specified in m m . per revolut ion.
For m a t
F_
F is specfied in m m . per revolut ion.
Ex a m ple
F0.25
Spindle rot at ion is st art ed by specifying a spindle direct ion com m and and a spindle
speed com m and.
Spindle speed:
The spindle speed is specified eit her as a const ant surface speed or as a const ant spindle
speed.
Con st a n t su r fa ce spe e d
This is com m anded by G96, and is always accom panied by a lim it ing spindle speed
com m and G50.
Exam ple:
G96 S225 M03
G50 S3000
The first line com m ands a const ant surface speed of 225 m ./ m in. ( m et ers per m inut e)
wit h t he spindle rot at ing CW.
The second one com m ands a lim it ing spindle speed of 3000 RPM.
Exam ple:
G97 S1350 M04
This result s in a spindle speed of 1350 RPM, spindle rot at ing CCW.
Tool ch a n ge
The t ool change com m and includes t he t ool num ber and t he t ool offset num ber of t he
com m anded t ool. When t he com m and is execut ed, t he t ool changer causes t he
com m anded t ool t o com e t o t he cut t ing posit ion. E.g., if t he t ool changer is a t urret , it
indexes so t hat t he com m anded t ool com es t o t he act ive posit ion.
For m a t
Taabb
aa is t he t ool num ber
bb is t he t ool offset num ber.
The t ool num ber and offset num ber m ust be writ t en wit h leading zeros. E.g., t ool
num ber 6 is writ t en as 06.
Ex a m ple
T0303
En d
The last but one line is t he program end com m and ( M02 or M30) .
The last line is t he % charact er.
Block n u m be r s
Block num bers add clarit y t o t he program . They are writ t en as N_
E.g.,
- -
- -
N0123 G00 G90 X100.0 Y150.0
N0124 G01 Z- 10.0 F250.0
N0125 X120.0
- -
- -
Block num bers are opt ional. They can be om it t ed from all blocks or included in som e
blocks only. Quit e oft en block num bers are used only in t ool change blocks. The leading
zero is opt ional. E.g., N0005 and N5 m ean t he sam e.
Com m e n t s
Com m ent s can be insert ed t o add clarit y t o t he program . They can be operat ion nam es,
t ool nam es, inst ruct ions t o t he operat or, et c. Com m ent s are insert ed wit hin bracket s.
Wit hout com m ent s a program is j ust a m ass of alphabet s and num bers and you cannot
figure out what each sect ion of t he program is doing. A com m ent can be in a separat e
block by it self, or aft er a set of com m ands, as shown below.
M oda l com m a n ds
A Modal com m and is a com m and t hat rem ains act ive t ill it is canceled or changed by
anot her com m and of t he sam e fam ily.
E.g.,
G01 X50.0 F0.2
G01 Z- 5.0 F0.2
G01 X60.0 F0.2
G00 X100.0
G01 Z- 80.0 F0.2
G01 X120.0 F0.2
Sa m ple pr ogr a m
This sam ple program is a sim ple full program t hat does a drilling operat ion followed by a
grooving operat ion.
G00 X200.0 Z150.0 Move t o posit ion away from part for t ool change
G97 S1200 M03 Const ant spindle speed of 1200 RPM, spindle CW
M08 Coolant ON
G00 X200.0 Z150.0 M05 Rapid t o t ool change posit ion and spindle OFF
G96 S180 M03 Const ant spindle speed 180 m / m in, spindle CW
G00 X54.0 Z- 20.0 M08 Rapid t o posit ion above groove, coolant ON
G00 X200.0 Z150.0 M05 Rapid t o t ool change posit ion and spindle OFF
% End charact er
This is t he point on t he t ool t hat is used as t he reference point for det erm ining t ool
offset s.
N e ce ssit y of TN RC
As t he t ool m oves along t he program m ed cont our, t he point on t he t ool nose radius t hat
is act ually doing t he cut t ing keeps changing. We act ually need t he nose radius t o be
t angent ial t o t he part cont our at t he point where it is cut t ing, but m oving t he Theoret ical
Tool Tip ( TTT) along t he cont our does not ensure t his. As a result , t he t ool leaves
unm achined m at erial in som e areas ( P1 t o P2 in pict ure) and digs int o t he m at erial in
som e areas ( P3 t o P4 in pict ure) .
To get an accurat e cont our during m achining, an alt ernat e t ool pat h is generat ed such
t hat t he nose radius is t angent ial t o t he cont our. This is t he pat h wit h Tool Nose Radius
Com pensat ion ( TNRC) .
G41
The com m ands are:
G42
Tool nose radius com pensat ion Left
G40
Tool nose radius com pensat ion Right
Tool nose radius com pensat ion Cancel
Ex a m ple
For m a t
Subprogram call:
M98 Paaabbbb
aaa and bbbb MUST be writ t en as 3 and 4 digit num bers respect ively, if necessary by
padding t hem wit h leading zeros.
Ex a m ple
The program segm ent t o cut t he grooves would look like t his ( t he t ext in bracket s is
com m ent s, and t his is exact ly how you can insert com m ent s in an act ual program ) :
-----
-----
G00 X44.0 Z0.0 ( MOVE TO START SAFE POSI TI ON JUST ABOVE PART)
( GROOVE 1)
W- 5.0 ( MOVE SI DEWAYS TO POSI TI ON FOR FI RST CUT)
G01 X30.0 F0.1
G00 X44.0
W- 0.5
G01 X30.0 F0.1
G00 X44.0
( GROOVE 2)
W- 5.0
G01 X30.0 F0.1
G00 X44.0
W- 0.5
G01 X30.0 F0.1
G00 X44.0
( GROOVE 3)
W- 5.0
G01 X30.0 F0.1
G00 X44.0
W- 0.5
G01 X30.0 F0.1
G00 X44.0
( GROOVE 4)
W- 5.0
G01 X30.0 F0.1
G00 X44.0
W- 0.5
G01 X30.0 F0.1
G00 X44.0
( GROOVE 5)
W- 5.0
G01 X30.0 F0.1
The t ool pat h is t he sam e for each groove. This segm ent can be put in a subprogram
t hat is called 5 t im es from t he m ain program . The m ain program and subprogram can be
writ t en like t his:
Main program :
-----
-----
G00 X44.0 Z0.0
M98 P0052253 ( CALL SUBPROGRAM 2253, 5 TI MES)
-----
-----
Subprogram :
%
O2253 ( SUBPROGRAM 2253)
W- 5.0
G01 X30.0 F0.1
G00 X44.0
W- 0.5
G01 X30.0 F0.1
G00 X44.0
M99 ( END OF SUBPROGRAM)
Tu r n in g cycle - G9 0
This cycle does a single t urning cut ( along t he part axis) .
St r a igh t t u r n in g
Tool pa t h
For m a t
G90 X_ Z_ F_
The end point can be specified by increm ent al coordinat es inst ead of absolut e
coordinat es. I n t his case:
1. Use addresses U and W inst ead of X and Z.
2. Use appropriat e signs wit h t he end point , since increm ent al coordinat es are
specified wit h reference t o t he st art point .
-----
-----
G00 X82.0 Z2.0 ( RAPI D TO I NI TI AL POSI TI ON)
G90 X75.0 Z- 50.0 F0.2 ( CUT TO DI AMETER 75)
X70.0 ( CUT TO DI AMETER 70)
G00 Z2
-----
-----
Ta pe r t u r n ing
Tool pa t h
The end point can be specified by increm ent al coordinat es inst ead of absolut e
coordinat es. I n t his case:
1. Use addresses U and W inst ead of X and Z.
2. Use appropriat e signs wit h t he end point , since increm ent al coordinat es are
specified wit h reference t o t he st art point .
Ex a m ple
-----
-----
G00 X67.0 Z1.0
G90 X65.0 Z- 50.0 R- 2.5 F0.25
-----
-----
Not e t hat t he R value has a sm all approxim at ion here since t he cut is st art ing at Z1.0
inst ead of Z0.
St r a igh t fa cin g
Tool pa t h
For m a t
G94 X_ Z_ F_
Ex a m ple
-----
-----
G00 X122.0 Z1.0 ( RAPI D TO I NI TI AL POSI TI ON)
G94 X70.0 Z- 3.0 F0.25( FACE TO Z- 3)
Z- 6.0 ( FACE TO Z- 6)
-----
-----
Ta pe r fa cin g
Tool pa t h
Ex a m ple
-----
-----
G00 X122.0 Z1.0
G94 X70.0 Z- 6.0 R- 2.0 F0.2
-----
-----
Tool pa t h
For m a t
G92 X_ Z_ F_
Ex a m ple
-----
-----
G00 X60.0 Z2.0
CAMLab - Turning Program m ing Guide Page 32 of 56 Cadem Technologies Pv t . Lt d.
G92 X59.0 Z- 65.0 F3.0
X58.4
-----
-----
The G92 com m and, Z and F are m odal values, which rem ain t ill t hey are changed. They
are t herefore om it t ed in t he t hird block.
Ca nn e d cycle s in Fa nu c
Tu r n in g cycle – G7 1
This cycle generat es a part shape from a cylindrical raw m at erial, wit h cut s along t he
axis. The cycle definit ion has t he part shape, dept h of cut , finish allowance and couple of
ot her param et ers.
Tool pa t h
For m a t
G71 U( d) _ R_
The blocks aft er t he second G71 block define t he part cont our A t o B. Param et er P has
t he num ber of t he first block Ns and Q has t he last block Ne.
Ex a m ple
-----
-----
G00 X49.0 Z5.0
G71 U3.0 R0.5
G71 P10 Q20 U1.0 W0.5 F0.2
N10 G00 X15.0 Z4.0
G01 Z- 5.0
G02 X25.0 Z- 10.0 R5.0
G03 X39.0 Z- 17.0 R7.0
G01 Z- 20.0
N20 G00 X49.0
G00 Z5.0
-----
-----
I n each of t he cases shown above, t he t ool is posit ioned at point P before calling t he
cycle and t he part profile is defined from point A t o B. The signs of t he finish allowances
U and W are as follows.
Case 1 ( Out side- Right ) : U + , W +
Case 2 ( Out side- Left ) : U +, W -
Case 3 ( I nside- Right ) : U -, W +
Case 4 ( I nside- Left ) : U -, W -
This cycle generat es a part shape from a cylindrical raw m at erial, wit h cut s perpendicular
t o t he axis. The cycle definit ion has t he part shape, dept h of cut , finish allowance and
couple of ot her param et ers.
Tool pa t h
For m a t
G72 W( d) _ R_
G72 P( s) _ Q( e) _ U( u) _ W_ F_
Ns _ _ _ _
_ _ _ _ _ _ _
_ _ _ _ _ _ _
Ne_ _ _ _
W( d) = Dept h of cut
R = Ret ract am ount , radius value
P = Num ber of t he first block of t he shape
Q = Num ber of t he last block of t he shape
U( u) = Finishing allowance in X, diam et er value
W = Finishing allowance in Z
F = Feed rat e
The blocks aft er t he second G72 block define t he part cont our A t o B. Param et er P has
t he num ber of t he first block Ns and Q has t he last block Ne.
Ex a m ple
I n t his exam ple t he st art and end point s are point s P2 and P1 respect ively, 2 m m . away
from t he raw m at erial. Not e t hat t hese are t he reverse of t he point s in t he G71 t urning
cycle.
I n each of t he cases shown above, t he t ool is posit ioned at point P before calling t he
cycle and t he part profile is defined from point A t o B. The signs of t he finish allowances
U and W are as follows.
Case 1 ( Out side- Right ) : U + , W +
Case 2 ( Out side- Left ) : U +, W -
Case 3 ( I nside- Right ) : U -, W +
Case 4 ( I nside- Left ) : U -, W -
This cycle generat es a part shape from raw m at erial t hat is t he sam e shape as t he final
part wit h cut s parallel t o t he along t he part shape. I t is used when t he raw m at erial is a
cast ing or forging. The cycle definit ion has t he part shape, dept h of m at erial t o be
rem oved, num ber of cut s and finish allowance.
Tool pa t h
For m a t
G73 U( i) _ W( k) _ R_
G73 Ps_ Qe_ U( u) _ W( w) _ F_
Ns_ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
Ne_ _ _ _ _
Ex a m ple
The t ool pat h defining t he shape ( bet ween t he blocks defined by P and Q) m ust st art and
end beyond t he raw m at erial. I n t his exam ple t he st art and end point s are point s A and
B respect ively, 2 m m . away from t he raw m at erial.
This cycle does a single finish pass along a cont our t hat has t ypically already been rough
t urned wit h a G71, G72 or G73 cycle. Nose radius com pensat ion is aut om at ically
act ivat ed in G70.
Tool pa t h
For m a t
Ns_ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
Ne_ _ _ _ _
_ _ _ _ _
_ _ _ _ _
G70 P( s) _ Q( e) _ U_ W_
Ex a m ple
This cycle does a peck drilling operat ion t o drill a hole along t he axis. The cycle can
act ually be used t o drill m ult iple axial holes at various posit ions on t he radius, on a
m achine wit h a C- axis and live t ools. The explanat ion here is rest rict ed t o drilling a single
axial hole.
Tool pa t h
For m a t
G74 R_
G74 Z_ Q_ F_
To drill t he hole in a single pass ( wit hout pecking) , set Q equal t o t he dept h of t he hole.
Ex a m ple
-----
-----
G00 X0 Z2.0
G74 R0.5
G74 Z- 30.0 Q6000 F0.15
G00 X50.0
-----
-----
This cycle does a peck drilling operat ion for grooving or drilling perpendicular t o t he axis.
The cycle can act ually be used t o cut m ult iple grooves, or ( on a m achine wit h a C- axis
and live t ools) drill m ult iple radial holes at various posit ions along t he lengt h,. The
explanat ion here is rest rict ed t o cut t ing a single groove.
Tool pa t h
G75 R_
G75 X_ P_ F_
Ex a m ple
This cycle cut s a st raight or t aper t hread wit h m ult iple cut s. The cycle definit ion has t he
t hread coordinat es, pit ch, dept h of t hread, et c.
Tool pa t h
For m a t
G76 P( m ) ( r) ( a) Q( d m in) _ R( d) _
G76X_ Z_ R( i) _ P( k) _ Q( d) _ F_
m = No.of idle passes aft er t he last cut . E.g., 02 would m ean 2 idle passes
r = Cham fer dist ance at end of t hread, fract ion of t he lead m ult iplied by 10. E.g., 12
would m ean a cham fer dist ance 1.2 t im es t he lead.
a = Angle of t ool t ip. E.g., 60 would m ean a t hread angle of 60 degrees.
Q( d m in) = Minim um dept h of cut , in m icrons. E.g., 0.1 m m . is writ t en as 100.
R( d) = Finishing Allowance, radial value, in m icrons. E.g., 0.15 m m . is writ t en as 150.
X,Z = coordinat es of end point of t hread.
R( i) = Taper value. Posit ive for ext ernal t hreads, negat ive for int ernal t hreads, 0 for
st raight t hreads.
P( k) = Thread dept h, radial value, in m icrons. E.g., 1.2 m m . is writ t en as 1200.
Q( d) = Dept h of first cut , radial value, in m icrons. E.g., 0.4 m m . is writ t en as 400.
F = Lead of t hread
I f t he dept h of cut becom es t oo low t he t ool j ust 'rubs' against t he part m at erial and
does not cut it . Specifying t he dm in. Value prevent s t his from happening. I f t he dept h of
cut is sm aller t han t he d m in. value, it is clam ped at t his value.
Ex a m ple
-----
-----
G00 X34.0 Z2.0
G76 P020060 Q100 R0
G76 X30.0 Z- 39.0 R0 P1200 Q0.5 F2.0
G00 X100.0 Z50.0
-----
-----
G codes on a m achine are decided by it s cont roller's program m ing form at . Machines of
different m akes wit h t he sam e cont roller will have t he sam e set of G codes.
M - code s
Most M codes act ivat e m achine funct ions like t he coolant , spindle, et c. These are decided
by t he m achine m anufact urer, and depend on t he feat ures t hat are available on t he
m achine. E.g., a m achine wit h a t ailst ock will have M codes for t ailst ock in/ out . A few
( like M00, M01, M02, M98, et c.in t he list below) are fixed and based on t he cont roller.
The blocks j ust before a t ool change t ypically have a num ber of codes specific t o a
part icular m achine, specifically t he t ype of it s t ool changer and it s t ool change posit ion.
They m ay appear odd and unfam iliar, and m ay be ignored for t he purpose of
underst anding t his program . The program has been generat ed by a CAD/ CAM soft ware
t hat aut om at ically considers t he t ool nose radius during cont ouring. Coordinat es in finish
t urning are calculat ed wit h nose radius com pensat ion, and will t herefore not m at ch t he
part coordinat es.
%
O1234
T0000
G0 X150.0 Z200.0
N1 T0101 (PCLNL 2525M12 R0.8)
G50 S3000
G96 S247 M03
(ROUGH FACE)
G0 X90. Z4. M07
X84.
G72 W3. R0.5
G72 P25 Q40 U0. W0.2 F0.3
N25 G0 Z0.
N30 G01 X80. Z0.
Effort in programming
The com plet e sequence of st eps involved in generat ing a m achined part from t he
drawing is a com plex process.
St e ps in m a ch in in g a pa r t
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.