Professional Documents
Culture Documents
CNC Turning Programing Guide PDF
CNC Turning Programing Guide PDF
TURNING
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
Block format
G01 X100.0 Z50.0 F0.2 is a block. It tells the tool to move along a straight line to
X100.0 Z50.0 at a feed rate of 0.2 mm/revolution.
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.
Common addresses
N Block number - specifies the start of the block
G Preparatory functions
M Miscellaneous functions
X X-axis coordinate
Z Z-axis coordinate
I X-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
Axes convention
The Z axis is along the spindle, while the X axis is perpendicular to it. The program zero
is the intersection of these axes. All coordinates in a program are referenced from this
point.
Axes on a lathe
Example
When the tool is moving to a position preparatory to executing a cutting motion or when
it is moving to the tool change position, the motion is a essentially a waste of time and is
executed as fast as possible. The motion is called Rapid traverse. The time taken to
execute a rapid motion is also called the Air cut time.
Typical rapid traverse rates are 20 to 40 m /min., but can be as high as 80 m/min.
Format
G00 X_ Z_
X, Z are the destination coordinates
Example
Rapid motion to P1
G00 X20.0 Z0.0
The tool moves along a straight line in one or two axis simultaneously at a programmed
linear speed, the feed rate.
Format
G01 X__ Z__ F__
X, Z are the destination coordinates
F is the feed rate, the speed of the linear motion
Example
G01 need not be repeated in the second line because it is a 'modal command' – it stays
active till it is changed by a different motion command.
Motion along a circular arc at a programmed linear speed, the feed rate. G02 moves
along a Clockwise (CW) arc, G03 moves along a Counterclockwise (CCW) arc.
An arc can be programmed using its radius or the coordinates of its center point.
Format
A threading motion is a motion along a straight line, but is NOT a linear interpolation
motion. The tool motion does not start immediately when the command is encountered.
It is coordinated with the rotation of the spindle - the tool starts moving when an index
pulse is received from the spindle encoder. This pulse occurs at a specific angular
position of the spindle, once in each spindle rotation. This ensures that each thread
starts at the same angular position, and each cut follows the path of the earlier cut.
The Lead is the axial distance the nut advances in one revolution of the screw, while the
pitch is the distance between adjacent threads. Lead = Pitch x No. of starts. In a single
start thread the lead is equal to the pitch.
When cutting a thread, for every revolution of the part the tool moves axially by a
distance equal to the Lead of the thread.
Format
G32 X__ Z__ F__
The following program segment cuts a thread of 2 mm. pitch to a depth of 0.6 mm.,
from point P1 to 2 mm. before point P2:
G00 X19.6 Z2.0
G32 Z-8.0 F2.0
G00 X22.0
Z2.0
The G32 command is seldom used. The G76 canned cycle is commonly used because it
can cut a thread with multiple cuts at various depths by specifying the pitch, thread
depth, etc. in two lines.
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
grooving operation when the tool reaches the bottom of the groove it needs to stay there
for at least one full revolution. Without a dwell it would retract back instantaneously and
result in a non-circular cross section at the groove bottom.
Format
G04 X_
X is the dwell time in seconds.
Example
G04 X1.0
Feedrate
The feed rate is specified in mm. per revolution.
Format
F_
F is specfied in mm. per revolution.
Example
F0.25
Spindle rotation
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 either as a constant surface speed or as a constant spindle
speed.
Example:
G96 S225 M03
G50 S3000
The first line commands a constant surface speed of 225 m./ min. (meters per minute)
with the spindle rotating CW.
The second one commands a limiting spindle speed of 3000 RPM.
Example:
G97 S1350 M04
This results in a spindle speed of 1350 RPM, spindle rotating CCW.
Tool change
The tool change command includes the tool number and the tool offset number of the
commanded tool. When the command is executed, the tool changer causes the
commanded tool to come to the cutting position. E.g., if the tool changer is a turret, it
indexes so that the commanded tool comes to the active position.
Format
Taabb
aa is the tool number
bb is the tool offset number.
The tool number and offset number must be written with leading zeros. E.g., tool
number 6 is written as 06.
Example
T0303
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 you cannot
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.
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 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
Sample program
This sample program is a simple full program that does a drilling operation followed by a
grooving operation.
G00 X200.0 Z150.0 Move to position away from part for tool change
M08 Coolant ON
G01 Z-30.0 F0.15 Drill the hole feed rate 0.15 mm/rev.
G00 X200.0 Z150.0 M05 Rapid to tool change position and spindle OFF
G00 X200.0 Z150.0 M05 Rapid to tool change position and spindle OFF
% End character
This is the point on the tool that is used as the reference point for determining tool
offsets.
Necessity of TNRC
As the tool moves along the programmed contour, the point on the tool nose radius that
is actually doing the cutting keeps changing. We actually need the nose radius to be
tangential to the part contour at the point where it is cutting, but moving the Theoretical
Tool Tip (TTT) along the contour does not ensure this. As a result, the tool leaves
unmachined material in some areas (P1 to P2 in picture) and digs into the material in
some areas (P3 to P4 in picture).
To get an accurate contour during machining, an alternate tool path is generated such
that the nose radius is tangential to the contour. This is the path with Tool Nose Radius
Compensation (TNRC).
Example
Format
Subprogram call:
M98 Paaabbbb
aaa and bbbb MUST be written as 3 and 4 digit numbers respectively, if necessary by
padding them with leading zeros.
Example
The program segment to cut the grooves would look like this (the text in brackets is
comments, and this is exactly how you can insert comments in an actual program):
-----
-----
G00 X44.0 Z0.0 (MOVE TO START SAFE POSITION JUST ABOVE PART)
(GROOVE 1)
W-5.0 (MOVE SIDEWAYS TO POSITION FOR FIRST 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 tool path is the same for each groove. This segment can be put in a subprogram
that is called 5 times from the main program. The main program and subprogram can be
written like this:
Main program:
-----
-----
G00 X44.0 Z0.0
M98 P0052253 (CALL SUBPROGRAM 2253, 5 TIMES)
-----
-----
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)
Straight turning
Tool path
Format
G90 X_ Z_ F_
-----
-----
G00 X82.0 Z2.0 (RAPID TO INITIAL POSITION)
G90 X75.0 Z-50.0 F0.2 (CUT TO DIAMETER 75)
X70.0 (CUT TO DIAMETER 70)
G00 Z2
-----
-----
Taper turning
Tool path
Example
-----
-----
G00 X67.0 Z1.0
G90 X65.0 Z-50.0 R-2.5 F0.25
-----
-----
Note that the R value has a small approximation here since the cut is starting at Z1.0
instead of Z0.
Straight facing
Tool path
Format
G94 X_ Z_ F_
Example
-----
-----
G00 X122.0 Z1.0 (RAPID TO INITIAL POSITION)
G94 X70.0 Z-3.0 F0.25(FACE TO Z-3)
Z-6.0 (FACE TO Z-6)
-----
-----
Taper facing
Tool path
Example
-----
-----
G00 X122.0 Z1.0
G94 X70.0 Z-6.0 R-2.0 F0.2
-----
-----
Tool path
Format
G92 X_ Z_ F_
Example
-----
-----
G00 X60.0 Z2.0
CAMLab - Turning Programming Guide Page 32 of 56 Cadem Technologies Pvt. Ltd.
G92 X59.0 Z-65.0 F3.0
X58.4
-----
-----
The G92 command, Z and F are modal values, which remain till they are changed. They
are therefore omitted in the third block.
This cycle generates a part shape from a cylindrical raw material, with cuts along the
axis. The cycle definition has the part shape, depth of cut, finish allowance and couple of
other parameters.
Tool path
Format
G71 U(d)_ R_
The blocks after the second G71 block define the part contour A to B. Parameter P has
the number of the first block Ns and Q has the last block Ne.
Example
-----
-----
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
-----
-----
In each of the cases shown above, the tool is positioned at point P before calling the
cycle and the part profile is defined from point A to B. The signs of the finish allowances
U and W are as follows.
Case 1 (Outside-Right) : U +, W +
Case 2 (Outside-Left) : U +, W -
Case 3 (Inside-Right) : U -, W +
Case 4 (Inside-Left) : U -, W -
This cycle generates a part shape from a cylindrical raw material, with cuts perpendicular
to the axis. The cycle definition has the part shape, depth of cut, finish allowance and
couple of other parameters.
Tool path
Format
G72 W(d)_ R_
G72 P(s)_ Q(e)_ U(u)_ W_ F_
Ns _ _ _ _
_______
_______
Ne_ _ _ _
The blocks after the second G72 block define the part contour A to B. Parameter P has
the number of the first block Ns and Q has the last block Ne.
Example
In this example the start and end points are points P2 and P1 respectively, 2 mm. away
from the raw material. Note that these are the reverse of the points in the G71 turning
cycle.
In each of the cases shown above, the tool is positioned at point P before calling the
cycle and the part profile is defined from point A to B. The signs of the finish allowances
U and W are as follows.
Case 1 (Outside-Right) : U +, W +
Case 2 (Outside-Left) : U +, W -
Case 3 (Inside-Right) : U -, W +
Case 4 (Inside-Left) : U -, W -
This cycle generates a part shape from raw material that is the same shape as the final
part with cuts parallel to the along the part shape. It is used when the raw material is a
casting or forging. The cycle definition has the part shape, depth of material to be
removed, number of cuts and finish allowance.
Tool path
Format
G73 U(i)_ W(k)_ R_
G73 Ps_ Qe_ U(u)_ W(w)_ F_
Ns_ _ _ _ _
________
________
Ne_ _ _ _ _
Example
The tool path defining the shape (between the blocks defined by P and Q) must start and
end beyond the raw material. In this example the start and end points are points A and
B respectively, 2 mm. away from the raw material.
This cycle does a single finish pass along a contour that has typically already been rough
turned with a G71, G72 or G73 cycle. Nose radius compensation is automatically
activated in G70.
Tool path
Format
Ns_ _ _ _ _
________
________
Ne_ _ _ _ _
_____
_____
G70 P(s)_ Q(e)_ U_ W_
Example
This cycle does a peck drilling operation to drill a hole along the axis. The cycle can
actually be used to drill multiple axial holes at various positions on the radius, on a
machine with a C-axis and live tools. The explanation here is restricted to drilling a single
axial hole.
Tool path
Format
G74 R_
G74 Z_ Q_ F_
To drill the hole in a single pass (without pecking), set Q equal to the depth of the hole.
Example
-----
-----
G00 X0 Z2.0
G74 R0.5
G74 Z-30.0 Q6000 F0.15
G00 X50.0
-----
-----
This cycle does a peck drilling operation for grooving or drilling perpendicular to the axis.
The cycle can actually be used to cut multiple grooves, or (on a machine with a C-axis
and live tools) drill multiple radial holes at various positions along the length,. The
explanation here is restricted to cutting a single groove.
Tool path
G75 R_
G75 X_ P_ F_
Example
This cycle cuts a straight or taper thread with multiple cuts. The cycle definition has the
thread coordinates, pitch, depth of thread, etc.
Tool path
Format
m = No.of idle passes after the last cut. E.g., 02 would mean 2 idle passes
r = Chamfer distance at end of thread, fraction of the lead multiplied by 10. E.g., 12
would mean a chamfer distance 1.2 times the lead.
a = Angle of tool tip. E.g., 60 would mean a thread angle of 60 degrees.
Q(d min) = Minimum depth of cut, in microns. E.g., 0.1 mm. is written as 100.
R(d) = Finishing Allowance, radial value, in microns. E.g., 0.15 mm. is written as 150.
X,Z = coordinates of end point of thread.
R(i) = Taper value. Positive for external threads, negative for internal threads, 0 for
straight threads.
P(k) = Thread depth, radial value, in microns. E.g., 1.2 mm. is written as 1200.
Q(d) = Depth of first cut, radial value, in microns. E.g., 0.4 mm. is written as 400.
F = Lead of thread
If the depth of cut becomes too low the tool just 'rubs' against the part material and
does not cut it. Specifying the dmin. Value prevents this from happening. If the depth of
cut is smaller than the d min. value, it is clamped at this value.
Example
-----
-----
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
-----
-----
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 tailstock will have M codes for tailstock in/out. A few
(like M00, M01, M02, M98, etc.in the list below) are fixed and based on the controller.
The blocks just before a tool change typically have a number of codes specific to a
particular machine, specifically the type of its tool changer and its tool change position.
They may appear odd and unfamiliar, and may be ignored for the purpose of
understanding this program. The program has been generated by a CAD/CAM software
that automatically considers the tool nose radius during contouring. Coordinates in finish
turning are calculated with nose radius compensation, and will therefore not match the
part coordinates.
%
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 complete sequence of steps involved in generating a machined part from the
drawing is a complex process.
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.