Part Programming For CNC Machines
Part Programming For CNC Machines
Part Programming For CNC Machines
Numerical control codes — standards — Manual Programming — canned cycles and subroutines —
computer Assisted programming — CAD/CAM approach to NC part programming — APT language,
machining from 3D models.
A part program is a set of instruction providing x, y and z coordinates and other details to perform the
desired machining operations. It directs how the tool should move with respect to work piece (or) vice
versa. A part program consists of all information necessary to complete the machining of a component.
In olden days, the part programs are coded on the punched tape: Nowadays, the punched tapes are replaced
by floppy disk and CDs. The punched tape is prepared according to the part program manuscript.
The punched tapes are 1 inch wide (25.4 mm). It was standardized by the Electronics industries
Association (EIA). The sample punched tape is shown in fig. The punched tape is fed through the tape
reader once for each component.
There are eight columns of holes as shown in fig. There is one column of sprocket holes in between 3’ and
4 columns to feed the tape.
The coding of the tape is obtained by either the presence (or) absence of a hole in the various positions.
This coding system uses the binary digit.
A binary digit is called a bit. It has a value 0 (or) 1 to represent absence (or) presence of a hole in a
particular row and column position of the tape. The columns of] holes run lengthwise along the tape. Row
positions run across the tape.
In the row of bits, a character is formed. A character is a combination of bits Representing a letter, number
and symbol: A word is. a collection of characters forming part of instruction. The collection of words forms
a block. A block of words gives one set of instruction. Each block of information is separated by End-of-
block (EOB) symbol in the column.
The part program is denoted by the symbol %. It defines the sequence of ONC machining operation. Each
block contains the following, types of words to perform a movement and functions.
1. Sequence Number (N—word (or) N codes)
2; Preparatory functions (G’-words (or) G code)
3. Coordinate words (X, Y, Z words) (or) Dimension words.
4. Speed rate (S word (or) S code)
Feed rate (F word (or) F code)
Tool selection (T word (or) T code)
Miscellaneous function (M word (or) M code) End of Block (EOB/*)
1. Block Number (or) Sequence Number (N words)
This sequence number is used to identify the sequence of block of data. It is usually given in ascending
order. This is useful for the operator to know which sequence of block, is performed by the tool. It consists
of alphabet N followed by ‘0’ to ‘999’.
(Eg) N5, N Ni50....
2. Preparatory functions (G—words (or) G codes)
G words are used to prepare the MCU to be ready to perform a specific operation.
These .words are used to prepare the machine to perform a particular function like positioning, contouring,
thread ‘cutting and machining. The following are the codes of various preparatory functions.
Example 1: Refer the following Fig. Using absolute dimensioning mode and metric units write the part
program only for positioning; First of all, position the tool to PT1, PT2, PT3 then and finally PT4.
Example 2: Write the part program for the following figure only for positioning the tool; Position the tool
PT1, at first then Ff2 and finally PT3. Locate the part reference point in absolute dimensioning and use
incremental dimensioning mode for other dimensions of the part.
Miscellaneous (or) Auxiliary Function (M Code)
The functions like coolant on (or) off, spindle rotation start etc are ‘known as miscellaneous functions.
The following are important M codes for various miscellaneous functions.
Ø a, b, and c (or A, B, and C) are used for rotary motion about X, Y, and Z axes respectively.
-
Ø I, J, K is used for position of- arc centre, thread lead parallel to X, Y, Z axes in case of thread
cutting.
The decimal point is not allowed in this word. So 5.675 mm in X direction will be represented as X 05675.
The last three digits of X05675 are used for the decimal part of the number. Some machines a X5675 by
omitting leading Zeros.
The MCU reads first Tab and stores the data in the address corresponding to sequence number. Then the
second word is recognized as preparatory function. Similarly, all the words are read and stored in particular
addresses.
If next block contains same X and Y words and other words are changed, then the format become
So, only changed words can be given and other unchanged words need not be repeated.
Fixed Block Format
In this fixed block format, -the instructions are given in a standard sequence and the block contains a fixed
number of characters: There are no letter addresses (or) Tab codes and no words are omitted. Even if any
data remains same as in previous block, it should be repeated in the next block also. A sample fitted block
format is shown below:
In this format, the first three digits represent the sequence number, the next two digits represent preparatory
function, next three consecutive 5 digits represent X, Y, and Z coordinates respectively, next three digits —
Feed rate, next four digits — speed, Next two for tool number, next two digits tool compensation, next two
digit miscellaneous function and last digit for EOB. Different CNC machines have different fixed formats.
For example, an CNC lathe has only X and Z word and it does not have Y word.
Manual Part Programming
The programming consists of the following procedure.
In another method, a pen plotter i used to draw the path of the cutter, movement of table on a paper and also
to locate the centre of holes to be drilled and reamed. The plotter drawing will be compared with the
original drawing for deviation.
Production of components
The last step is to produce the actual parts.
Part programming for PTJ’ (Point to Point) machining:
In this PTP, the cutting tool, (or) workpieee moves fast from one point to another point for drilling (or)
boring or teaming etc. Once the point is located, the drilithg yperation gets started as per part program. As
soon a drilling is over, the drill comes out of the hole and goes to next poiat in rapid traverse since there is
no machining in between two points.
Example 3: Write the part program for the following figure. The Z position is zero at 100 mm above the
table surface.
Procedure
1. First of all, the work piece should be aligned so that the edge AX coincides with I axis. AY
coincides with Y axis of the machine.
2. Set the tool tip at origin B (0, 0, 0) at a height of 60 mm above the work piece corner A.
3. For drilling first hole P the tool should travel through 25 mm in X and 30 mm in Y direction and
—83 mm in Z direction (i.e. 60 + 20 + 3). The extra 3 mm is to ensure through hole in the plate,
‘—‘sign for downward direction. Part Program (To avoid confusion, x, y, z values can be given
without decimal part).
NO! G92 XQ YO FO <EOB>
Set the position ‘A’ of the plate (work piece) under the drill at point B. 092 for position
preset (or) Datum preset.
N02 G71. G90 G94 <EOB
071 for Metric, 090 for Absolute dimensioning, 094 for Feed rate in mm
NO3 MO3 F16O S1200 <EOB>
M03—Spindle start—clockwise, F160—Feed rate 160 mm/m and S 1200 — Spindle
speed at 1200 rpm
N04 COO X25 Y30 Z-58 <EOB>
000 for rapid traverse to point P 30, — 58)
N05 G01 Z—83 <EOB>
Drill the hole at point P (i.e. 60 + 20 + 3 = 83 for drill tip)
001 for linear traverse
The horizontal and vertical distances of centre of arc with respect to datum point
in incremental mode are given below.
Coordinates of the starting point S is (X —.10, Z 0). The centre of arc C, is located at C (X —10, Z —10).
So the vertical distance in’ X direction (i.e. from S to C) is 0. So I = 0 [ I is the vertical distance from S
(starting point) to C (centre of arc)]
In this milling operation, the cutter radius compensation should be taken care of.
A suitable dia of cutter is selected and the part program should be written for centre line of the cutter.
The cutter radius compensation will be calculated - by taking difference between programmed cutter
diameter and the actual cutter diameter and it should be entered into the control system. Then the control
system will generate a new cutter path.
It is necessary to specify whether the cutter compensation is to the right (or) to the left of the tool while
machining. The G codes G40, 041 and 042 are used for this purpose.
Example 9: Write a part program to give a finished job as shown in fig using milling operation.
Speed 1200 rpm; • Feed 125 mm Depth of • cut =3 mm; Thickness of plate = 3 mm
Note: The cutter radius compensation is stored in D02. The top surface of the plate is taken as Z = 0. G42
Compensation is applied to shift the programmed cutter path to the right. G40 is to cancel the cutter radius
compensation.
Subroutines (Macros) (L code)
When a repetitive drilling (or) any machining operations have to be done in different places, the subroutine
is used to reduce the effort of writing a detailed program for each machining operation.
The subroutine program will be stored in the memory as a separate program so that it can be called by the
main program whenever needed. When the last block in the subroutine (M17) is executed, the control will
return automatically to the main program. The subroutine is usually placed at the end of the main program.
Example: Using subroutine, write a part program to get the finished part as shown in fig.10
N1 G90 G71 G17 <EOB>
Absolute dimensioning: Metric units: XY plane
N2 GO0 X20 Y25 Z5 <EOB>
Rapidly Move the tool to point A and 5 mm above the plate surface.
N3 L20
Call the subroutine programmed to machine the first slot.
N4 G00 X100 Y25 <EOB>
Move the tool rapidly to the second slot i.e. to point B
N8 GOO X20 Y100 <EOB>
Move the tool rapidly to the 4th slot i.e. to point D.
N9 L20 <EOB>
Call subroutine program to machine 4th slot starting from D.
End of program
L20 <EOB>
Subroutine program
N1 G91 <EOB>
Incremental dimensioning system
N8 G90 EOB>
Convert to absolute dimensioning mode
N9 M17 <EOB>
M17 is for end of subroutine and return to main program
Example 11: Write a part program for the finished - component as shown in figure. The point A is taken as
reference point (0, 0, 0). Take cutter diameter in 20 mm
N1 G92 X0 Y0 Z0 *
[ is given instead of <EOB>]
Position preset (or) Datum preset
N2 G90 *
Absolute dimensions
N3 GO0 X40 Y30 Z2 TO! S3000 M03 - *
Rapid traverse to B with clearance Z = 2 mm above the plate
N4 G01 Z5 F120 *
Tool goes down with depth of 5 mm straight cutting and end milling.
N5 * - -
Tool proceeds to C— straight cutting end milling
NO X80 *
Tool proceeds to E— straight cutting end milling
N7 G02 Y30 10 eJ—30 *
G02 Circular interpolation clockwise
I = 0 .The distance of centre D from E in X direction J = — 30 The distance of centre
from E in Y direction.
Now, the cutter moves through curved profile and reaches F.
N8 X30 *
Proceeds to B
N9 Z2 *
Tool moves 2 mm above the plate surface
N10 G00 Z50 M05 *
Rapid travel of tool upwards 50 mm above plate surface and spindle stops.
N11 X0 Y0 *
Rapid travel to reference point (0, 0)
N12 M02
End of program
The above three actions have to be repeated for drilling other holes also. Therefore, it is necessary to define
a canned cycle (or) fixed cycle to repeat all these motions without repeating (writing) same information for
each hole. Refer the following figures:
In both figures, -the following actions, Position the drill to the hole location,
(ii) Lower the drill at programmed feed rate,
(iii) Lift the drill rapidly to start position
are same. The only difference is in the depth of cut. In first case, it is 30 mm and in 2nd case it is 10 mm.
Hence, the canned cycle requires a new hole location, depth of cut, feed rate and spindle speed.
The canned cycles G81 to G89 ate useful for this purposes and they are stored a subroutines. The R
parameters are necessary to define the variable values necessary to execute canned cycle. The canned cycle
G8i to G89 can be cancelled by G80.
The following are the important R parameters used in canned cycles.
The advantage of the canned cycle can be sensed by writing program without canned
cycle and with canned cycle for the finished component in the following example.
Example 12: Write the part program for the finished component shown in fig. without using canned cycle
and with canned cycle.
• means end of block
Cancel the canned cycle and move the tool to a position (0, 0, 50).
Using caned cycle, 10 blocks are reduced to .4 blocks in CNC programming. So canned cycle prevents
boredom in writing repeated instruction. It avoids mistakes and errors in writing program.
The standard canned cycles approved by ISO are giving it below.
Example 13: Write the program using canned cycles for drilling four holes as shown in fig. Drill diameter 6
mm; Reference plane, is 2.5 mm above the plate, surface.
The components which are similar in shapes but different in. sizes are machined using parametric
subroutine program.
This parametric subroutine is also a portion of a programmer, complete in itself, which is stored in the
computer memory. It is called with required data when required again in a program. It is usually placed at
the end of a programmed.
Difference between canned cycles and subroutines
The canned cycles are more of fixed type and they are used for easy programming of machine features that
are often needed. So canned cycles are more suitable for general situations.
But if a part needs some pattern which is to be repeated a number of times, then a subroutine is very much
useful. -
The parametric subroutine is useful for turning, rough cuts, threat cuts, key way milling, drilling etc. where
a sequence of motions are involved.
Since the parametric subroutines allow to intake their own cycles with different parametric dimensions at
different locations, it is known as ‘user defined canned cycles’
Difference between ‘Do-loops’ and ‘Subroutine’
The Do-loops are used to repeat some motions (operations) On a component for a fixed number of times.
The subroutines are used to repeat some motions (operations) on a component for a variable number of
times.
Macros are also known as ‘parametric subroutines: They are stored in memory (or) macro file used for
machining a complete component. A macro has either fixed dimensions
Macros
(or) parametric variables. These macros are very much useful to program for family of parts having same
shape but variable size as shown in the figure.
Mirroring
When the part geometries are symmetric in nature, then part program can be written to make use of such
symmetry. For doing this, the part programmer has to identify the symmetric axis and write only for half of
part geometry.
Then the part program will be repeated by using appropriate mirror imaging codes. The mirroring of image
can be obtained about X axis, Y axis (or) X and Y. axis.
In Macho programming language, the G code 73 is used for mirroring and G code 72 is used to cancel
mirroring.
The above part is syminetrical about. X axis. So the part programmer can program for upper part alone and
for machining lower part, just write
Ni G73 ex. L..
Then all X coordinates vi1l be reversed and the loiter part will be machined.
WriteProgramming
Computer Assisted Programming (CAP)
In manual part programming, very simple parts are machined, since, it requires a very few number of
instruction (or) sequence .of operations. But, most of the complex parts can not be machined by manual part
programming since they require lengthy and tedious calculations. So it is necessary to make use of
computer for part programming repetitive and complex calculations involved in mathematically defined
curves and other complicated geometrical shapes. So the complex programs can be generated by computer
Assisted Programming (CAP). The part programmer need not learn about the specific coding formats used
in different NC machine tools. Instead, he can learn only high level programming languages like APT,
ADAPT, AU.TOMAP, EXAPT, PROMPT. etc which are all ‘English like statements’.
The reliability of program is enhanced since the computer makes all calculations. Besides, the computers
have facilities for error detection to assist part programmer to produce better part program. The part
program thing time ‘is greatly reduced by as much as 75%.
With the arrival of Computer Assisted Programming (CAP), the programmer is relieved off great burden
and he has to do only the following activities.
(i) Define the geometry of the work piece from part drawing
(ii) Define the sequence of operations and tool path
APT can be used to control a variety of different machining operations. APT uses more than 400 words.
There are tour types of APT statements
1. Geometry Statements -
Geometry statements define the geometric pattern of the work part
These are also called Definitions statements.
2. Motion Statements
Motion statements are used to define the path taken by the cutting tool.
3. Post processor statements
Post processor statements are used in pacific machine tool and control system. They are used to provide
data for feeds and speeds. They are also used to actuate other features of the machine.
4. Aux Statements
Auxiliary statements are used to identify’ the part and tool to specify the tolerances and to operate coolant
N (or) OFF and so on. These are also known as miscellaneous
Statements
Let us see all the above statements one by one in detail.
Geometry statement
First of all, the component geometry must be defined to program in APT. The geometry statements define
the path and locate the points through which the tool has to trace. The geometry statement should be given
before the motion statement.
The format for geometry statement is
Symbol = GebmetryType/Descriptive Data
Example = Point / 2, 4, 7
Explanation: The symbol. P1 is defined as ‘POINT’ having coordinates
X=2;Y=4andZ=7
So the geometric statements comprise of three sections the first section is symbol. The symbol is used to
identify the geometric element. A symbol is combination
of alphabets and numerical. The maximum character should be six. At least one of the
six should be an alphabet. Very important thing is the symbol should not be one of the
APT vocabulary words.
3. By two points and perpendicular to other plane
PL5 = PLANE/PERPTO, PL4,P1, P2
PL5 is a plane perpendicular to plane PL4 passing through P1 and P2.
Motion statements
Motion statements have a general format as given below
Motion command Descriptive Data
GOTO / P2
The above statement consists of two sections.
The first section (GOTO) tells tool what to do. The second section (P2) tells, tool where to go. By this
motion statement, the tool is ordered to go to point 2 (P2) which should have defined already in the
geometry statement.
The following are three types of motion commands
1. Setup commands
2. Point-to-Point motion commands
Setup command
The tool must be given a starting point at the very beginning of the motion.
The starting point is- known as target point where the operator positions the too at the a part of the job.
The setup motion command is
FROM / TARG
The ‘TARG’ is the target (or) starting point from which others will be referred.
FROM / -4, -3, 0
I.e. The tool should start from X=—4; Y—3; Z=O. Another way to make statement - FROM / SETPT
where SETPT is the Starting point.
3. Continuous path (contouring) motion commands
Another way to make this statement is
Solution: The geometry statements &e given beIos by referring the diagram.
$$ All points are th here.
SETPT = POINT/O, 35, 2
P1 = POINT/40,35,0
P2 = POINT/4Q, 170,0
P3 = POINT/90, 140,0
P4 = POINT/120, 60, 0
P5 = POINT/60, 35, 0
$$ Define the top and bottom surfaces.
TOPSRF = PLMTE/P1, P2, P5
BOtSRF = PLANEIPARLEL, TOPSRF, Z LARGE, —25
$ [ is a surface parallel to top surface parallel to top surface and bn the lar side of
2 y 25 downward)]
$$ Define the circles and lines
CR1 = CIRCLE/CENTER, PS, RADIUS, 30
L2 LINEIP2, LEfl, TPsNTO, CR1 1 CR2]
$$ [ The line L2 passes from point P2 and is tangent on the lef*side of arc e
Example 15: Write a part program for the finished part shown in figure
* Use the milling cuter alid drill. Assume the thickness of the plate is 20 mm. Setpt is at (0, 20, 3) and Z = 0
at the surface of the job.
Solution: The dlre of motion is defined in the figure and also all points and lines are shown here.