Unit 4
Unit 4
PROGRAMMING
Structure
4.1 Introduction
Objectives
4.1 INTRODUCTION
In Units 1 to 3, we have discussed the fundamental principles involved in the operation of
computer numerical control machine tools. In this unit, we will study some fundamental
aspects related to programming the CNC machines. Later units will concentrate on the
application of these for industrial components.
Objectives
After studying this unit, you should be able to learn the
• fundamental principles to be observed in programming the CNC machine
tools,
• various programming principles that need to be considered while
programming the CNC machine tools,
• description of some of the commonly used preparatory or G codes used for
controlling the part programming, and
• description of some common miscellaneous or M codes that are used in most
of the CNC machine tools.
40 3
80
Ø3 Ø12 25
12 R3
1
30 9.5
The next step involved will be the identification of the datum on the part that can be linked
to the datum of the chosen CNC machine tool. The identification of the axes system of
CNC machine tools is discussed in Unit 1. The part programmer will have to identify the
datum and axes on the part in tune with that on the CNC machine tool. It is not necessary
that the part datum and machine datum be the same, which is more difficult for operation.
The CNC machine tools generally come with ‘floating datum’ whereby the part datum
can be located anywhere in the machine tool’s operation space.
Table 4.1 : Process Plan for the Component Shown in Figure 4.1
Care has to be taken in identifying the axes system, since the calculation of the coordinate
values will be greatly affected by that choice. Generally there are two possibilities to
locate the datum :
80
67.5
52
Y 46
40
34
28
6
80
65 68
Ø12 62
Ø3
40
12 15
R3
X 1
9.5
12.5
Figure 4.2 : Same Part as in Figure 4.1 with Axes System at the Bottom Left Corner
Alternatively the datum could be chosen as a point that is located at the geometric centre
of the workpiece for symmetrical workpieces as shown in Figure 4.3. This helps in
reducing the geometric calculations needed since you will be doing that only for one half
or one quarter of the component and the rest could be manipulated by a simple sign
change. Further, it would be possible to make use of the mirror facility in the controller to
reduce size of the part program.
Y
12
6 6
40
28
22 25
X
Ø3 Ø12
R3
1
9.5
27.5
40
When it comes to the Z-axis datum, the option is relatively simple. It is generally kept to
match with the top surface of the workpiece. This can be easily set as well as all the
positive Z-motions will take the tool away from the workpiece, thereby avoiding any
catastrophic collisions of the tool with workpiece in case of any errors in the part
program.
7
Part Programming After the datum selection, the next choice is that of cutting tools such that the most
effective and economical tools are selected for the operation. Only the general purpose
tools are used as far as possible, unless a required surface cannot be generated by them.
Also the size of the tools have to be carefully selected from the geometry in question.
For a given tool and the operation selected, the appropriate process parameters are to be
selected. These are to be generally taken from the handbooks supplied by the cutting tool
manufacturers or based on the shop experience. Another aspect to remember is the
planning of the various cuts, when large amount of material needs to be removed, for
example in the case of cavity milling. This aspect is generally taken care of by the canned
cycles, which will be discussed later.
The proving of a part program before that can actually cut metal is important. This is done
in many ways. One of the simplest is the graphical proving of the part by a software on
the computer screen or on the MCU monitor. A typical example is shown in Figure 4.4
below.
Figure 4.4 : Tool Path of the Part for Proving the NC Part Program
After the graphical verification, a dry run on the machine tool may be carried out without
a cutting tool to make sure that there are no unwanted motions present in the program.
After a successful dry run, it would be possible to run the part program to make the part.
If in doubt, the first component may be made in a soft material such as machinable wax,
acrylic, nylon or Styrofoam. Having proven the part program, it can be released for
production with appropriate documentation.
SAQ 1
(a) In order to write CNC part programs, what are the various types of
information that needs to be considered by a part programmer?
(b) What is a process plan?
(c) How is the datum selected in the case of CNC part programming? Explain
your answer with examples.
(d) Explain the importance of part program verification.
10
For the sake of simplicity we will be following the ISO format in this course. However, Fundamentals of
Part Programming
the programmer should refer the individual CNC machine program manual to follow the
correct procedures and formats.
The co-ordinates are a major part of a typical part program. The various word addresses
used for specifying coordinates are X, Y, Z, U, V, W, I, J, K, A, B, C, etc. They can be
specified using a direct decimal format as we normally do in algebra. Some examples are:
N035 T01 M03 S1000 ;
N040 G01 X15.450 Y35.540 Z -2.0 F120 ;
N055 X-25.500 Y55.545 ;
N065 X15.450 Y35.540 ;
Generally, the feed rate is specified with F word address and specified in mm per minute.
The value specified normally is the speed with which the spindle moves along the
specified path. For example, F120 in the above statement means that the feed rate is
specified as 120 mm per minute (assuming metric units are used in the program).
However, it is also be possible to specify using the mm per revolution units, with a special
preparatory function as described later. The feed rate specified in any block remains
modal, meaning that it will remain in force till it is altered by another F word. Generally, it
is expected that the axes will be moving at the specifie d rate. However, it is possible to
change this by the use of feed rate override switch on the machine tool control panel.
The spindle speed can be set using the S word address. The number after the S is the
speed of the spindle specified directly in revolutions per minute. For example, S1000 in
the above statement means that the spindle speed is specified as 1000 revolutions per
minute. Though this is the normal usage, it is also possible to specify the spindle speed in
cutting speed units as meters per minute using a special preparatory function, which is
described later.
The tool to be used for an operation is to be identified by the T word address. For
example, T01 in the above statement means that the tool number 1 is to be placed in the
spindle. The tool number is considered in this book as the tool magazine position in the
case of machines with automatic tool changers. The actual case may have to be verified
with the programming manual of the individual machine tool. In some cases the tool
number may also have to be combined with the tool offset register number, which is
described later.
The preparatory functions are denoted by the word address ‘G’. This function principally
controls the geometric functions of the controller. Thus, it is mostly associated with the
control of the axes. These are also called as G codes. It generally has two digits, e.g.
G01, G42, and G90 as per ISO specifications. Many of the current day controllers have
extended this to 3 or 4 digits. Most of these functions are standardized by ISO as
follows :
Code Function
G00 Point-to-point positioning, rapid traverse
G01 Line interpolation
G02 Circular interpolation, clockwise (CW)
G03 Circular interpolation, anti-clockwise (CCW)
G04 Dwell
G05 Hold/Delay
11
Part Programming G06 Parabolic interpolation
G07 Unassigned
G08 Acceleration of feed rate
G09 Deceleration of feed rate
G10 Linear interpolation for “long dimensions” (10 inches-100 inches)
G11 Linear interpolation for “short dimensions” (up to 10 inches)
G12 Unassigned
G13-G16 Axis designation
G17 XY plane designation
G18 ZX plane designation
G19 YZ plane designation
G20 Circular interpolation, CW for “long dimensions”
G21 Circular interpolation, CW for “short dimensions”
G22-G29 Unassigned
G30 Circular interpolation, CCW for “long dimensions”
G31 Circular interpolation, CCW for “short dimensions”
G32 Unassigned
G33 Thread cutting, constant lead
G34 Thread cutting, linearly increasing lead
G35 Thread cutting, linearly decreasing lead
G36-G39 Unassigned
G40 Cutter compensation-cancels to zero
G41 Cutter radius compensation – offset left
G42 Cutter radius compensation – offset right
G43 Cutter length compensation – positive
G44 Cutter length compensation-negative
G45-G52 Unassigned
G53 Deletion of zero offset
G54-G59 Datum point/zero shift
G60 Target value, positioning tolerance 1
G61 Target value, positioning tolerance 2, or loop cycle
G62 Rapid traverse positioning
G63 Tapping cycle
G64 Change in feed rate or speed
G65-G69 Unassigned
G70 Dimensioning in inch units
G71 Dimensioning in metric units
12 G72-G79 Unassigned
G80 Canned cycle cancelled Fundamentals of
Part Programming
G81-G89 Canned drilling and boring cycles
G90 Specifies absolute input dimensions
G91 Specifies incremental input dimensions
G92 Programmed referenc e point shift
G93 Unassigned
G94 Feed rate/min (inch units when combined with G70)
G95 Feed rate/rev (metric units when combined with G71)
G96 Spindle feed rate for constant surface feed
G97 Spindle speed in revolutions per minute
G98-G99 Unassigned
Most of the G codes are modal in nature, so that they need not be repeated in every
block. Another point to be noted with these codes is that the G codes are divided into
various groups depending upon their functionality. It is expected that only one code from
each of the group should be given in any given block. It is generally possible to include
more then one G address in one block, provided these functions are not mutually
exclusive. In Fanuc controls upto 5 G codes can be given in one block. Some other
controls have different limits, but generally upto 3 codes in a single block will be
permissible.
It should also be noted that some of the G codes remain in force when the control is
started or reset. These are termed as default or turn on codes. Though it is a prudent
practice, to specify all the necessary G codes while writing the programs, some times it
may be possible by the experienced programmers to take advantage of these default
codes and reduce the length of the program.
Typical preparatory functions that are generally present in most of the machining centres
are given below :
Motion group
*G00 Rapid Positioning
G01 Linear Interpolation
G02 Circular interpolation Clockwise
G03 Circular interpolation Counter clockwise
Dwell
G04 Dwell
Active Plane Selection Group
*G17 XY Plane selection
G18 XZ Plane selection
G19 YZ Plane selection
Cutter Compensation Group
*G40 Cutter compensation, Cancel
G41 Cutter radius Compensation left
G42 Cutter radius Compensation right 13
Part Programming Units Group
*G70 Inch units
G71 Metric units
Hole Making Canned Cycle Group
*G80 Canned Cycle Cancel
G81-G89 Canned Cycles definition and ON
Co-ordinate System Group
*G90 Absolute co-ordinate system
G91 Incremental co-ordinate system
Preset
G92 Absolute pre-set, Change the datum position
The * sign indicates the generally accepted default or turn on code in operation. However,
this is not generally true with all the controllers and care have to be taken to check with
the programming manual of the controller.
SAQ 2
(a) Explain the word address format that is generally used with CNC machining
centers.
(b) Explain the procedure used to specify the feed rate and spindle speed in the
case of CNC machining centers.
(c) What is the importance of preparatory functions in CNC machining center
programming? Give the description of any two functions and their
application.
14
Fundamentals of
Part Programming
A
40
45°
20
C B
0 X
0 20 40 60
The path of the tool from A to B can be either through the shortest path, or
alternatively the tool will start moving in all axes at the maximum speed possible
thereby going through a 45 path as shown in Figure 4.7. When one of the
coordinates is satisfied, then the tool will start moving in the other axis till the
programmed position is satisfied. Though the above example shows a movement in
two axes, it is also possible to have the same in all three axes simultaneously.
The program block in incremental coordinates would be
N15 G91 G00 X60.0 Y-30.0;
Linear or Straight line Interpolation, G01
17
Part Programming Linear or Straight line Interpolation is generally used when the material is being cut
by the cutting tool. In this case, the tool will move along the programmed straight
line with the specified feed rate. In this case, the controller moves all the three axes
at a rate such that the resultant velocity along the line matches the programmed
feed rate.
It is also possible to specify the radius of the arc in place of the center coordinates
using I and J. In that case, R word address is used for specifying the radius. The
specification will then be for the above case,
N125 G02 X30.0 Y45.0 R20.0 F250;
However, looking at Figure 4.10, it can be noticed that there are two possible arcs
that can be drawn using the given information, since the center of the arc is not
precisely located. It can be noticed that one arc is smaller (less than 180°) and the
other larger (greater than 180°). To check for the correct arc, the nomenclature as
adopted is that the radius of the larger arc is specified with a negative sign for the
radius.
B
R-20
40
R20
20 A C
0 X
0 20 40 60
The miscellaneous functions or M-codes are the ones used for operating the machine tool
functions. Generally, only one -M code is supposed to be given in a single block.
Similar to G-codes, ISO has standardized a number of M-codes as follows :
Code Function
M00 Program stop, spindle and coolant off
M01 Optional programmable stop
M02 End of program – often interchangeable with M30
M03 Spindle on, CW
M04 Spindle on, CCW
M05 Spindle stop
M06 Tool change
M07 Coolant supply No. 1 on
M08 Coolant supply No. 2 on
M09 Coolant off
M10 Clamp
M11 Unclamp
M12 Unassigned
M13 Spindle on, CW (+) coolant on
M14 Spindle on, CCW (–) coolant on
M15 Rapid traverse in + direction
M16 Rapid traverse in - direction
M17-M18 Unassigned
M19 Spindle stop at specified angular position
M20-M29 Unassigned
M30 Program stop at end tape + tape rewind
M31 Interlock by-pass
M32-M35 Constant cutting velocity
M36-M39 Unassigned
M40-M45 Gear changes; otherwise unassigned
M46-M49 Unassigned
M50 Coolant supply No. 3 on
4.6 SUMMARY
CNC Part program is a detailed step by step procedure for carrying out the actual
machining operation in a CNC machine tool. In order to develop a good part program, the
part programmer needs to follow precise steps in a sequence. First step is to identify the
coordinate system to be used with the part that will specify how the coordinates will be
measured. Once the program is written, it is also necessary to prove it before actually
committing the machine tool to machine the part. Word address format is generally used
to translate the machining sequences into a language understood by the CNC controller.
The numerical values in a part program are preceded by a character that specifies its
address. ISO has standardized the word addresses to be used in CNC part programming.
Preparatory functions are G codes which are used to signify the way the part program
needs to be interpreted. There are a number of them that have been standardized and
commonly used in most of the controllers. Miscellaneous functions refer to the codes that
activate mainly the functions of the machine tool.
22