Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

Understanding

How to Write

CNC Lathe
Programs
MCAR

May 2012

MCAR

May 2012

TABLE OF CONTENTS

CHAPTER

PAGE

Part One CNC Lathe Programming Basics

CNC Program: What is it?


2 Axis Programming and Cartesian Coordinates
Speed Bumps and Pitfalls
Programming Words
G Codes
Basic Program Structure Putting Codes to Work
Program Zero and Work Offsets
Tool Offsets
Part Two Programming Methods and Tool Nose
Radius Compensation

29

Programming Methods
Tool Nose Radius Compensation Rules
Part Three Canned Cycles

41

Definition
Various Types
Variables: Finding the Perfect Recipe
Canned Cycle Exercise
Part Four Writing a Program

49

Calculating What Needs to be Machined


Locating Part Zero
Tool Selection and Placement
Preparing & Writing the Program
Running the First Part for a New Program

MCAR

May 2012

MCAR

May 2012

Part One CNC Lathe Programming Basics


Welcome to CNC Programming for Lathes. In this part of the training, we will go over the
many different aspects of CNC Programming for lathes. Everything from what axis of motion is
controlled to simple formatting of CNC programs and simplifying, rather than complicating, the
overall programming process. First and foremost, we will discuss what CNC Programming is and
also how it relates to lathe programming.

What is a CNC Program?


A good way to describe it would be a simple list of commands that are listed in the order
that the machine will perform the tasks commanded. In short, it is a script that a machine will
use to create a part. Think of a recipe, any recipe. Lets say chocolate chip cookies. You have a
list of ingredients, the things that are required in order to make the cookies. Next you have a
play by play group of instructions on how mix the ingredients a certain way, turn on the oven to
a specific temperature, cautions to only put so much cookie dough on the sheets at a time and
most importantly, how long to bake them.
A CNC program is no different. Instead of butter, eggs and flour, the ingredients
for a machine may be a turning tool, drill, boring bar and grooving tool. Instead of instructions,
G codes and other programming words perform the play by play steps that will result in a
correctly made work piece shape and size. Programming is not some huge mystery that
everyone makes it out to be. It is merely a simple set of instructions you give the machine to
create a geometric shape out of a piece of material that is both accurate and functional.

MCAR

May 2012

2 Axis Programming and Cartesian Coordinates


Because a common CNC lathe uses only 2 main axes of movement, the type of
programming used to control it is called, no surprise, 2 axis programming. Two axis
programming is often seen as one of the most basic and simplest forms of programming though
very complex shapes can be made using only two axis of movement.
In order to create geometry using the two axis of movement, we need to be able to
keep track of ever possible location where the axis may travel to. To do this, CNC machines
utilize a very old system that has been around since the 17th Century, called the Cartesian
coordinate system. This system was created by Rene Descartes in 1637. Descartes invention
made it possible to plot the location of two dimension drawn geometry. By using two
perpendicular lines that have a fixed intersection, called the origin, geometric shapes could be
plotted and measured. This was one of the first steps to defining the size and shape of any
drawn two dimensional object. Sounds pretty complicated? Yes, it truly can be but for what
programmers use it for, it is actually quite simple. You may have learned about Cartesian
Coordinates when you were in grade or high school and it may have been called grid mapping.
Here is how it works: Two fixed lines, called axis, are perpendicular to each other. The
point at which they intersect is called the origin. Each line is named so you will know which axis
to use when plotting. Every number moving to the left and beneath the origin the origin is
considered negative movements and is labeled with a sign. A Cartesian Grid is simplified by
being divided into four quadrants. Each Quadrant is labeled by the sign of the numbers in that
zone. For example, if you are working in the positive direction on the X axis from origin and in
the negative direction on the Z axis from origin, you are working in the +, quadrant. It is
sometimes described by using the axis letters with the sign of travel. So in the example, it
would be X+, Z quadrant. A sample grid showing the quadrants is shown on the next page. You
can then plot out profile of a part by putting a point where each new direction of travel occurs.
The basics would be straight perpendicular lines to each axis. More complicated movements
would be radial and angular movements. No matter what, the one thing that each piece of
geometry has in common is that they all have a starting point and an ending point. We can plot
any of those. Once you have all the points located, play connect the dots using the geometric
MCAR

May 2012

shapes that are associated with the points. You should now have a profile of the object you are
trying to create.

Below is an example of the labeled Quadrants used in the Cartesian coordinate system.

MCAR

May 2012

Below is an example of a Lathe Cartesian Coordinate Grid

MCAR

May 2012

Plotting Geometry Using the Cartesian Coordinate System


The most crucial building block to all of geometry is the point. Points have no size and
no depth but are usually documented as a round dot when plotted on any grid. The point helps
establish a location on a grid that, once linked together, can form simple to complex geometric
shapes. Below is an example of a plotted point on a Cartesian coordinate system.

Using the method shown above, plot the points shown on the next page with each
corresponding number.

MCAR

May 2012

Each set of points establishes a geometric location for which a machine function can be
performed. In the case of lathe work most geometric shapes will need to be linked together in
some way. The method most commonly used is creating geometric lines.

MCAR

May 2012

10

Creating Lines
When two points are placed anywhere on a grid, we can now create the next basic
geometric shape, a line. A line is a straight geometric shape that has no width and no depth but
does have one feature, distance. The distance of any line can be measured by the location of
each set of plotted end points. Lines do not have to remain in one quadrant of a Cartesian
coordinate grid as shown on the next page.

MCAR

May 2012

11

As the grid from the previous page shows, the line crosses from one quadrant to
another. This can become confusing when trying to figure move after move, first positioning in
one quadrant, then another, then back again, then to another. Most CNC lathe programs use
one quadrant in particular to create the profile for which work piece geometry is created. This
quadrant is X+, Z . The reason for this is when you look at a CNC lathe, the centerline of the X
axis is considered the origin or zero location for the diameter of the part. If, for example, you
want to create a 2 diameter shape, you would simply divide the diameter you want by two
and plot your answer. Once plotted and connected with other points, radial geometric shapes
will be created. In the above example, the X axis point to create a 2 diameter would be 1
3/8 or X1.375.
Remember, since the part is revolving around the X axis, whatever is created on the top
of the part, is created on the bottom and in essence all around the work piece. Though shown
as straight lines on a profile view, the lines actually translate into diametrically precise
cylinders.
As for the Z axis, most programmers tend to use the face of the part as their zero
location though all the numeric values will need to be stated in negative numbers. This is still
easier than establishing lets say the middle of a work piece for Z zero. You would then have to
figure distances in both the positive and negative direction. Doing this would take much more
time to make calculations, thus delaying the creation of the program. After the program is
created you would then run into the trouble of establishing the zero point while setting up the
machine.
We will discuss program creation as it relates to part and work zero in a later lesson. For
now, lets just use the quadrant of X+, Z to create our lathe shapes.

MCAR

May 2012

12

The following is an exercise for creating a geometric shape in the X+, Z quadrant using
points, then lines. When you are finished plotting the points, go back and connect the dots
using lines to create a profile.

Once the geometric profile has been created, other programming codes will be added in
order to correctly position and move the machine through the plotted path. Some parts may
have complex looking geometry but once you know how to dissect and plot the tool paths,
those complex shapes will become easy to manufacture.

MCAR

May 2012

13

Speed Bumps and Pitfalls


If you ask people which type of machine is the easiest to program, the majority will tell
you that Lathes are the simplest. The main reason people say that programming lathes is so
simple is because you only need to program one side of the part profile. Doing so results in the
machine moving the tool along a two dimensional plotted path and because the part is rotating,
the entire profile is created as the tool engages the work piece. What can complicate
something viewed as being so simple are things such tool clearances, material types and work
piece holding. A well written program is not worth a hill of beans if a tool will not clear the work
holding device or a shape that was created by another tool and is directly in the way of the tool
needing to be used for the next operation. One of the worst scenarios is having the material is
in such a state that removing excess metal is next to impossible due to hardness or toughness.
Those things can and will happen throughout your career as a programmer. Being able to adapt
and overcome such obstacles is what makes some programmers more effective than others.
As stated before, the simplicity of the lathe programming is that you only need to think
in two dimensions, X and Z in order to create a 3 dimensional object. Many times people try to
overcomplicate the process but in the end, what happens in one area of the work piece will be
translated 360 degrees around the entire part surface due to the part rotating in the work
holding device.

Programming Words
Along with X and Z axis coordinates, the CNC machine tool requires other commands in
order to create a shape or profile. The commands come in the form of words. Probably not like
the words such as you are reading in this manual. This type of word is called a programming
word.
A programming word is a term used to describe any Alpha Numeric code that is used
either to activate a program / machine function or a support variable used to enhance a
program function. Words are typically one letter and up to three numbers in length. The newer
the machine, the more likely you will find up to 3 digit codes. Older machines mostly had only a
letter and two numbers to describe its programming words.
MCAR

May 2012

14

Below is a list of programming words commonly found in various CNC programs. Please
note that not all of the words are used in every CNC program, some variables do not appear
until they are needed for a specific option.
A,B,C
D

Axis of Rotation for X,Y,Z

Depth of Cut

P, Q

Offset Call for Cutter Comp

Program number
Variables for Canned Cycles
Start End Blocks
Return amount

Feed Rate

Preparatory or Go Codes

Speed, RPM or SFM

Tool Call

I,J,K

Variable for Canned Cycles


Incremental Radius Values for X,Y,Z

Number of repeats in a cycle

U,V,W

Miscellaneous or Machine Code

X,Y,Z

Program line number

Clearance Plane for Canned Cycle

Incremental for X,Y,Z


Finish Allowance for Canned Cycle
Axis or Motion

Decimal point usage in words


Words that are used in CNC programming are grouped into two classes. Ones that allow
for a decimal point and others do not.
The words that allow or may require a decimal point are:
A, B, C, F, G, I, J, K, Q, R, U, V, W, X, Y, & Z
The words that do not allow or may not require decimal points are:
D, L, M, N, O, P, S, & T

MCAR

May 2012

15

G Code Programming
What are G Codes?
G codes are preparatory codes. This means that the codes instruct the machine to
perform a task or function based on a particular G codes parameters. Sometimes, additional
information must be inserted in the form of other programming words, along with the G code
so that the function performs as expected. Programmers often remember G codes by calling
their functions go commands, meaning you are telling the machine to go do something such
as perform a task.
For example, G00 tells the machine to move in a rapid motion while G01 tells the
machine to move in a controlled motion along a straight line.
Most G codes must have extra programming words included on the same line in order
to perform the task requested. An example would be calling G01 which is a linear feed move.
Most often, you will find G01 on a line with X and/or Z.
There are some G codes however, that can work all by themselves without the extra
words. G20 is the Inch Input G code is an example of a G code that does not need any other
variable to operate.
G codes control a variety of functions such as machine positioning, offset length
compensation, tool radius compensation, hole pattern creation, canned cycles, feed rate
control, to name a few. What makes G codes so useful is that each code specializes in a function
and thus helps reduce the programming time by requiring only specific data.
There are just about as many G Codes as there are functions to a machine.

MCAR

May 2012

16

What are some machine operations that


can be performed using G Codes?

Rapid movement

Feed movement

Linear movement

Radial movement

Select fixture offset

Create patterns
G Codes allow the machine to perform simple to complex tasks such as position the

machine, select offsets, move in a controlled manner, create a hole pattern, cut in a radial
motion, just to name a few. G Codes can reduce the amount of programming time by
condensing the amount of code needed to perform a task.

Using G Codes
When you want to use a G code, the first thing you will need to ask yourself is, What do
I want the machine to do? Once you decide which function to perform, you will need to know
what G code will need to be used to perform that function. For instance, if you want to position
the machine, one of the first things you want to insert is a G00 for machine rapid positioning.
Below is a list of common Fanuc based G codes.
G00

Rapid Traverse

G40

Cutter Comp Cancel

G01

Linear Feed

G41

Cutter Compensation Left

G02

Circular Interpolation CW

G42

Cutter Compensation Right

G03

Circular Interpolation CCW

G54

Work Offset

G04

Dwell

G90

Absolute Programming

G20

Inch Programming

G96

Constant Surface Speed

G28

Reference Return

G99

Feed Per Revolution

Note Every machine tool is different so be sure to check with your machine tool
builder for an accurate list for your specific model machine.
MCAR

May 2012

17

Modal and Non Modal Groups


Most G codes stay active in the control until they are canceled by another G code of the
same group. This is called a modal command. There are some exceptions. Non Modal
commands are ones that cancel themselves as soon as the function is performed. The following
list shows the various groups and also the ones that do not need to be cancelled.
Modal G Codes
Group

Name

Codes in the Group

1
2
3
5
6
7
10
12

Motion
Plane
Distance
Feed
Units
Cutter Comp.
Return Mode
Coord. System

Group

Name

Codes in the Group

0 or 00

Non-Modal

G04,G10,G12,G13,G28,G52,G53,G92

G00,G01,G02,G03,G80,G81,G82,G83,G84
G17,G18,G19
G90,G91
G98,G99
G20,G21
G40,G41,G42
G98,G99
G54,G55,G56,G57,G58,G59 (work offsets)
Non-Modal G Codes

Basic Program Structure


Almost every program uses the same group of G and M codes at the beginning of the
program, for each tool call, at the end of every tool operation and at the end of the program.
This is called basic program structure.
Using a basic program structure allows for easy and efficient understanding of a
program and will allow the examination at any given program written the same way, to be
simple and fast. Basic Structure is much like you would write a sentence. There is a common
recurring method that most programmers use called a programming style. This simply means
that for the most basic information, a programmer tends to insert the data into the same place
every time. CNC Programs are much easier to comprehend when they are used in a common
repetitive order.
MCAR

May 2012

18

Compatibility
One of the biggest problems within any shop is writing the programs so they can be read
and understood by anyone. Any person who writes a program was either taught by someone
who has a certain style or has developed their own style over the years by trial and error. If you
give a print to 10 different programmers at 10 different companies and tell them to write a
program to make the same part, you will likely come back with 10 different programs. They will
all accomplish the same thing but the formatting will be a little different within each one. The
important thing is to be able to understand what needs to be in a program and what doesnt.
The following pages detail a basic style for starting a CNC program, calling a tool, taking
a tool to a tool change position and the codes needed for ending a cycle or program.

Start of a Program
O1234 (Part #### for XYZ Company);
N10 (COMMENT);
N20 (T1 TOOL DESCRIPTION);
N30 T0101 M08;
N40 G54 ;
N50 G96 S750 M03;
Above is an example of a typical program start up. Each line of a program ends with a
semi colon ( ; ) known as an end of block ( EOB ). The machine will attempt to execute all the
code when it reached each end of block in a program and will not move on to the next line until
the tasks assigned have been completed. If you do not insert an end of block when you want to
end a line of code, errors or erratic machine movement can occur.
For every CNC program on a Fanuc style control, a program number must be designated
for the machines memory. The letter O is used before a 4 or 5 number program designation for
most Fanuc based controls. It is important to remember to use the letter O and not a zero here,
MCAR

May 2012

19

otherwise the machine will generate an alarm and will not load the program into the active
memory.
Any words in parenthesis are called comments. Comments can be seen by the operator
but are ignored by the machine. Comments are mostly used as random bits of information for
the operator such as what tool to use, flipping the part over, clearing chips, etc. Comments can
also contain valuable set up information such as which Work Offset to set up to, which
operation is being performed and information regarding the handling of the work piece.
The letter N is used to number the lines of code. You do not have to use N numbers on
every line or not at all but it is recommended mainly for the ease of finding typos and errors
when they occur. N Numbers can be up to 6 digits on some modern machines but is usually 4
digits on older models. Most programmers prefer to count by tens when initially writing a
program. This allows for the addition of extra lines of code without totally rewriting the entire
cycle in most cases. Most tool calls after the first one start with either a new number in the
hundred or thousand position. So every tool call after the first will be N1000, N2000, N3000 or
N0100, N0200, N0300 and so on.

Tool Call
(T1 TOOL DESCRIPTION);
T0101 M08;
G54
G96 S550 M03;
G0 X#### Y####
The tool call is very similar to the program start up except the lack of extra comments
and the program number. The rest of the code stays the same. Even though you may not
change your work offset while running the part, always make a habit of inserting it when calling
a tool. The reason for this is in case you need to or your machine is powered down while in a
cycle. Storms that cut power from lightning strikes can be one source of power loss. This also
happens a lot if you have a long cycle time and it is the end of the work day. For example, you
write a program using G57 and it is a 40 minute total run time. The operator starts the run 20
minutes before quitting time. Since he knows he will not finish the entire program, he will
MCAR

May 2012

20

activate the optional stop button and stop the program before the next tool change. The next
morning when he starts the machine back up, the machine automatically defaults to G54. See
where you would run into a problem? If he advances the program to the next tool and the work
offset was not in there to be picked up, the machine will not be performing the work in the
correct location. The part will be scrap or worse, the machine will crash.
As you can see the spindle start command usually occurs before the machine moves
towards the work piece. This is to allow the spindle to get up to speed and to allow the spindle
to be running in case the tool happens to contact the work piece during the first rapid move.

Ending for a Tool Cycle


G0 G40 Z.2 M09;
X10. Z10. T0100;
M01;
Before calling the next tool it is recommended to cancel any tool nose radius compensation,
shut the coolant off and to take the machine to a safe tool change position.
The M01 is the optional stop M code and will allow the operator to stop the program before
the next tool is called. By having the machine at a safe tool change position, the operator may
safely use the optional stop to check the part or tool as it completes this portion of the
program. Things the operator may check for include, surface finish, tool wear, broken or
chipped tools, part size, and part clamping. With the optional stop, the operator does not have
to stop the program every time, but he/she does have the option to do so if needed.

MCAR

May 2012

21

Ending of a Program
;

G0 G40 Z.1 M09;

G0 G40 Z.1 M09;

X10. Z10. T##00;


M30;

or

G28 G91 X0 Z0;


M30;

When ending a program, you will most likely want to position the machine so the operator can
get to the work piece without having to try to avoid hitting the tool turret while removing the
work piece. Moving the X and Z Axis to their home positions is a method that will allow the
operator to gain easy access to the work holding area, and allowing for the work piece change
out less cumbersome. Some companies require that the tool turret be rotated so that tools
which project outward from the turret, (boring bars, drills, ID grooving tools, etc.) be rotated so
that there would not be any incidents where to the part contacts the tool. Some companies
require that the first tool used in the program be rotated up so the machine is back to its ready
position to start cutting as soon as cycle start is depressed. In any way that it is done, the
program ends with the machine being sent out of the way of the work piece.

MCAR

May 2012

22

Exercise
For the exercise below you will need to write the code for a program start up, tool call,
end of tool, and end of program. The code provided next to each exercise number will give you
all the required information. Simply rearrange all of the information in order. Some or all of the
code may not be positioned on the line where it is needed.

Program Structure Exercise


1. S1500, G96;
T0101, M03;
(T1 CNMG 432 OD);
O1234, G54, M08;
(ABC COMPANY);
(COMMENT FOR SET UP);
2. M01, M09. T0400;
G40, Z.1, Z10.;
X10., G00;
3. M08, M03;
T0606, S500;
G56, G96;
(1/2 BORING BAR);
4. G00, G40, Z10.;
M30, M09 T0300;
X10., Z.1;

MCAR

May 2012

23

Program Zero and Work Offsets


When you begin a program, before you write the first meaningful line of code, you must
decide the most important feature of that part you want to create, where to start everything at.
Without a starting point, there will be nothing to reference all of your moves, nor will an
operator be able to setup the machine since he will not know how to orient the work piece.

Where do I put the starting point?


This is one of the first thoughts that go through a programmers head when creating a
new program. It is a VERY good question to ask yourself.
In most instances, this starting point will be known as the Program Zero. Your program
zero point on a lathe will most likely be centerline for the X axis and the face of the work piece
for the Z axis. All programmed points will be calculated from these set locations and the
locations will be used when setting the work offset value as well.

The starting point has been established, now what?


Once this point has been established, whether it is a point on a finished work piece or a
point in space, all other programmed movements for operations performed on the part should
come from that location.
Just remember, program zero can be a point in space as long as you have a way to get
back to that point every time you set the machine up. Otherwise, it becomes hard to set up
repeat jobs without a clear method of setting the zero point.
Picking points without a physical location can be tricky and confusing for an operator so
take that into your thought process.
Once the Program Zero has been established, the next step will be to assign a Work
Offset to the part.

MCAR

May 2012

24

Work offsets and you, what they are and how they benefit your program
A Work Offset is a G Code that is used to set a reference point from the machine home
location to usually the program zero location. Work Offsets allow programs to be written using
points pulled from feature diameters and lengths rather than trying to write programs based on
calculations from machine home position. Work Offsets are helpful if you have multiple jobs set
up on a single work table. They also are handy when using fixtures that will hold several of the
same work piece. Each location where a part is to be made can have its own Work Offset.

How many different work offsets are there?


The most common Work Offset G Codes used are G54 through G59. Modern machine
tool builders have added extra Work Offset G Codes with the thinking of more parts being run
on a table at one time, enhancing production.
You will need to consult your machine tool builders manual to find out if there are any
extra G Codes used for Work Offsets.

Tool Offsets
With all the different tool shapes and sizes that are made today, programmers and
operators would have a hard time programming and running parts if they had to make sure
every tool was the exact same length.
This is why Tool Length Offsets were created.

What is the role that tool offsets play?

Establishes a Reference to Home Position or Tool Setter for each tool

Allows for adjustments to be made for each tool

Makes programming easier by making a zero starting point

Allows for quick reference to see how long tool projections are

MCAR

May 2012

25

In most cases, Tool Length Offsets establish a reference dimension from home position
to an active part zero reference plane. This is usually the top of a finished work piece. The
reference dimension is then put into a user offset page that has a listing of offset numbers.
Some companies use a gage block or other reference device to set the distance to the
top of the work surface from the bottom of the spindle. The program work offset for Z is then
set. This allows only the actual tool length, including holder, from the face of the spindle to be
entered.
You will need to consult your company to know which method they prefer to use.
Each tool can be tweaked by making fine adjustments for each tool if needed.
Programming becomes simpler because each tool start point is referenced to a known zero
location. This will allow actual true tool movement to be set.
The following chart shows a sample tool offset page as it might look on any given CNC
control.

Tool Offset Page


Offset

Wear

Wear

Radius

Tip

-14.6864

0.0052

-0.1673

0.

.0312

-13.5595

0.0142

0.4463

0.

0.

-16.7441

0.0072

-0.1335

0.0083

.0156

0.

0.

0.

0.

0.

-22.8268

0.

6.3367

0.

0.

0.

0.

0.

0.

0.

-21.3714

-0.0085

4.6729

-0.0162

.0312

0.

0.

0.

0.

0.

-19.5898

0.0034

3.9133

0.0022

.0156

10

0.

0.

0.

0.

0.

11

-13.9119

0.0056

0.

0.

0.

12

-14.6325

0.0073

0.5294

0.0036

0.

MCAR

May 2012

26

Since most CNC lathes use a numbered tool turret, it is often found that the tool offsets
match the tools position in the numbered turret. Most machines have options that allow the
programmer to actually pick which tool offset value you will want to use with each tool but
there are a couple that make it mandatory to use an exact tool offset that matches the tool
number called. This is more from a safety point of view than anything else.

A Helpful Tip
Write down the current offset already input on a scrap piece of paper. This will help
make sure you did not make a mistake or miss-key when entering in the new number.
Again, it is easier to write down small numbers in the wear column, than the entire
geometry offset.

Offset Placement and Type

Where to place the offset in program

What code to enter when placing offset

How much information needed

When calling a tool in a program sequence, the operator will need to know which tool
position the tool is located, which offset value will be used.
If, for example, a tool nose compensation function is used, the operator will need to be sure
to enter the tool tip radius in the geometry page.
Knowing how much information and exactly what information a tool offset will require will
rely greatly on what type of operations that are being performed.

MCAR

May 2012

27

MCAR

May 2012

28

Part Two Programming Methods


&
Tool Nose Radius Compensation TNRC
During the part of the class, we will discuss the two main programming methods for
creating geometry using CNC lathes. We will also go into detail about the rules and proper use
Tool Nose Radius Compensation. For some programmers, especially ones just starting out, tool
nose compensation or tool nose comp as it is often called, has frustrated and caused more
problems that its designed intent. We will address this and cover the simple rules that will help
relieve some of the headaches and take most of the mystery out of how and when to use it.

Two Types of Programming Methods


There are two programming methods used in profile machining operations on modern
lathes, Machine Compensated and User Compensated.
For any operations such as drilling, tapping, etc. The tool centerline is ALWAYS
programmed.

User Compensated Programming


User Compensated programming is mostly used in older equipment that does not have
Tool Nose Radius Compensation or when creating simple turning or facing programs that do not
have complex geometry such as angles and radii.
When creating a geometric shape on paper, tools are often not thought of and all the
programmed moves must be calculated out manually to compensate for the tools nose radius.
This becomes more and more difficult when radii and angles are created. As the tool moves
through the various geometric shapes, the radius of the tool tip causes the tool to cut the shape
incorrectly. The reason for this is that the machine moves the tool through each position as if
MCAR

May 2012

29

the tool tip was a theoretically sharp point at a theoretical 90 degree angle to the cut being
made. It does not take the radius of the tool into account. The term for the improper geometry
created is called Cosine error. If the tool was indeed a sharp point, the geometric shapes would
be exactly as programmed. The larger the radius on the tool tip, the greater the Cosine Error.
When Radii or Angles are called out, most programmers use the other type of programming
instead of trying to compensate the moves manually.

The image above depicts the tool path of a user compensated method of programming.
The radius is a simple 90 degree sweep. It is one of the easiest geometric shapes to manually
compensate since complex equations do not have to be performed in order to generate the
tool path. Notice how the actual tool radius moves gently around from one tangent point to
another? All the while the theoretical sharp tip stays in contact with the programmed path.
The following part and program is a simple two step part turned at 1 in diameter and
another turned at 2 in diameter and is made from a 3 diameter piece of material. The
programmer will not have to calculate for the tool nose radius because all of the machining
occurs in the X and Z axis.

MCAR

May 2012

30

Program
T0101 M08;
G54;
G96 S700 M03;
G0 G40 X1. Z.1;
G01 Z-1. F.008;
X2.;
Z-2.;
X3.1;
G0 Z.1 M09;
X10. Z10. T0100;
M30;
In the next image, you will see the same general shape but with a slight twist.
Tool Nose - .031 Radius
Program
T0101 M08;
G54;
G96 S700 M03;
G0 G40 X1. Z.1;
G01 Z-1. F.008;
X1.438;
G03 X2. Z-1.281 R.281
Z-2.;
X3.1;
G0 Z.1 M09;
X10. Z10. T0100;
M30;

MCAR

May 2012

31

In the example, the general shape is basically the same as the previous example except
that a radius has been added to edge where the 1 Z depth and the 2 X diameter intersect.
Notice that the radius compensation is more than the actual radius called out. This is due to the
programmer having to compensate for the nose radius on the tool being used. While this may
not be difficult for radius shapes presented at 90 degrees in movement, changing the tangent
points from 90 degrees to lets say 45 degrees creates a whole new set of math equations that
will need to be made to ensure the correct geometry is created.

Machine Compensated Programming

This type of programming method allows the machine to make the radius calculations
for you so that it will create the geometry correctly such as angles and radii based on
information you give the control while setting up the machine.
The main requirement of using machine compensated programming is to identify your
tool radius and tool tip in the geometry page of the tool offset function. The tool tip will need
to be declared in most cases. What this lets the machine know is how the tool is oriented in
reference to the edge of the work piece. Typically on Fanuc machines, tip #3 is for OD normal
turning style tools while tip #2 is for normal ID boring style tools. If you do not put a tip in the
offset page, the machine will use 0 for the tip and the tool compensation will more than likely
have errors in the computed path.
Below is the same part as on the previous page but with tool nose compensation added
to calculate the moves through the radius so you do not have to manually compensate the
movement.
Tool Nose - .031 Radius
Program
T0101 M08;
G54;
G96 S700 M03;
MCAR

May 2012

32

G0 G40 X1. Z.1;


G01 G41 Z0. F.008;
Z-1.
X1.5;
G03 X2. Z-1.25 R.25
Z-2.;
X3.1;
G0 G40 Z.1 M09;
X10. Z10. T0100;
M30;
What you see is an example of a machine compensated method of programming. The
program reflects the actual tool movements without having to calculate extra geometry in
order to compensate for the radius being created. Using Machine Compensated Programming,
you simply insert the tool nose compensation G code to turn the compensation mode on and
the machine uses the information from the Offset page and will make each necessary
calculation for each programmed movement.
Key factors for correct Tool Nose Compensation: When and Where Tool Nose Radius
Compensation is needed /possible, Inserting the actual tool nose radius and tool tip value when
using Tool Nose Comp and Using Tool Nose Compensation Correctly (lead in /out)

How to pick one over the other


Though most modern programmers say they will insert tool nose compensation into a
program that has profile machining 9 times out of 10, there are still times where it is considered
overkill to use tool nose compensation.
When having to pick one style from the other, knowing just what is needed to be
machined will lead to exactly what will need to be compensated. Once you have all the facts,
use the method that best suites the situation. If you are just turning or facing straight back or
down, then you do not need any type of tool nose compensation, but if you have complex
geometry of any sort, you should opt to the machine compensated method. In the end, it will
MCAR

May 2012

33

all depend on how much information you have about the various geometry and how
comfortable you are with creating your own compensated tool paths.

Tool Nose Radius Compensation TNRC


What is Tool Nose Radius Compensation?
Tool Nose Radius Compensation for a lathe is a G code that is inserted into a particular
part of the program so that the machine is made to shift or compensate the tools actual
position based on the tools nose radius size and tool tip orientation in order to correctly create
geometric features accurately. This will allow the tool to travel along a modified programmed
path and compensate when making angular and radial movements.
Once inserted, the machine calculates the complex mathematical equations based on
part and tool geometry. The tool then moves around the new computer modified path so that
that it cuts on the compensated tool nose radius at all times. When finished, the machine shifts
the tool back to the theoretical edge position, in effect, out of compensation mode.
Without Tool Nose Radius Compensation, the programmer would have to make the
calculations otherwise the tool path would follow the programmed edge of the tool nose and
not the true edge of the X and Z axis as they relate to the radius of the tool tip. This would
result in angles and radii being cut undersize.
Tool Nose Radius Compensation is one of the most useful functions of modern CNC
machining but it can also be one of the most frustrating if certain rules are not followed when
inserting it into programs. There are no set order to the rules, only that they ALL must be
followed to create a tool path with no errors.

MCAR

May 2012

34

Tool Nose Compensation G Codes


G40
G41
G42
G40 Cancel Tool Nose Compensation This G code cancels all tool nose compensation
and is required to end a cycle that has tool nose compensation installed.
G41 Tool Nose Compensation Left Calculates all geometry to shift the tool to the
left of the programmed path as it moves around a work piece cutting on the right edge of the
tool. G41 is used primarily in right handed Boring Operations
G42 Tool Nose Compensation Right Calculates all geometry to shift the tool to the
right of the programmed path as it moves around a work piece while cutting on the left edge of
the tool. G42 is used primarily in right handed turning operations.

The Rules
The rules are more like guidelines that need to be followed in order to make sure that
tool nose radius compensation is performed without error. If you follow some of the rules but
not all of them, errors can and usually will occur. It is best to never skip a rule.

Rule #1: Figure which mode of Tool Nose Radius Compensation is to be used.
Decide to use G41 or G42 based on what machining function you are performing, which
side of the tool is being used as the primary cutting tip and what type of compensation to use.
As an example, typically on lathe programming, G41 is used for boring tools while G42 is used
for turning tools.
More programming mistakes are made from making the wrong compensation selection
than other compensation errors.

MCAR

May 2012

35

Rule #2: The tool must be positioned at least one thousandth of an inch (.001)
more than the radius amount indicated in the offset page from the start where
tool nose compensation is to be used.
Simply put, shift the tool in the correct direction and distance from the part. The
location where the shift occurs is often called the lead in position.
Example: If you are using a turning tool with a .008 tool nose radius and are going to cut
along the edge of a part, the position must be at least .009 more than the actual position of the
edge of the part.
One thing to note, any extra material, from a cast surface or previous machining
operation, must be added to the amount shifted, otherwise the tool will move down and
possible crash into the work piece.

Rule #3: Do not insert a G41 or G42 in a line with both an X and Z axis feed
movement.
It is never a good idea to move the machine in two axis while turning on the
compensation. Some machines, especially older ones do not react well to having a multiple axis
move while enabling tool nose radius compensation and some may even give an error in CRC
calculation when more than one axis is used to shift.

Rule #4: Do not try to cut an ID radius that is smaller than the radius of the tool.
One of two things will happen.
1: the machine gives a compensation error alarm. (This is the better of the two)
2: the machine plunges the tool into the part in an attempt to make the compensation. This
results in an imperfection or a crashed part / tool.
The second result occurs most often on older machines. Newer machines have specific
deviation alarms which prevent gouges or incorrect geometry from being created.
MCAR

May 2012

36

Rule #5: Clear the work piece completely before canceling Tool Nose
compensation.
On some machines, when tool nose compensation is cancelled, the machine physically
shifts the tool back to the theoretical edge of the tool.
If your tool is not completely clear, it may crash into the part. A good majority of the
time, tool nose compensation is removed right after the last X movement that clears the tool
from the work piece. It is recommended to clear at least two times the radius plus several
thousandths away from the side of the work piece. This allows for some machines, mainly older
ones, to move back towards the machines theoretical edge as it disengages tool nose radius
compensation. On newer machines, if the movement amount is not far enough, an alarm is
usually generated.

Rule #6: Be sure to enter the correct tool radius and tool tip style into the offset
page before running an operation with Tool Nose compensation.
If the offset value is incorrect or missing, even in graphics enabled machines, either an
alarm will be generated or the tool path will look incorrect.

The Mystery of Tool Nose Compensation is solved!


Tool Nose Compensation should not be a burden nor should it be something that
frustrates the programmer. It was designed to make your life easier and your programming a
lot more practical.
Following the simple rules given in the previous pages will give a firm basis and
understanding of what needs to be present for tool nose compensation to work correctly.
If your tool nose compensation alarms out when you try to use it, chances are, it was
because one of the rules stated above was not followed or was not followed closely enough.
The more you use it, the more it will feel natural is a good rule of thumb to go by.

MCAR

May 2012

37

The following is an example of Tool Nose Compensation as used in a program to create a


simple tool path with linear, radial and angular movements.
T0101 M08; Tool position/tool offset call, coolant start
G54; work offset call
G96 S700 M03; Set constant surface speed, spindle speed and start spindle forward
G0 G40 X2. Z.1; Rapid to 2 in diameter and .100 away from Z0
G01 G42 Z0. F.005; Linear feed movement in Z axis to 0 and insert tool nose radius comp.
right
Z-2.75; Linear movement to next coordinate in shape
X2.5; Linear movement to next coordinate in shape
G03 X3. Z-3. R.25; Move radially to create a radius on top of this shoulder of the part
G01 Z-3.5; Move Linearly to next coordinate in shape
X3.875 Z-4.2578; Linear angular cut at 30 degrees
Z-4.5; Linear turn back to final depth
X4.; Clearance move for tool nose comp cancel
G0 G40 Z.1 M09; Rapid to Z axis clear point, cancel tool nose comp, coolant off
X10. Z10. T0100; Rapid to safe tool change location and cancel tool offset
M30; End of program and rewind
Below is an image of what was created.

MCAR

May 2012

38

Exercise: Use the print provided below and write a simple program using Tool
Nose Radius Compensation to create a tool path from the right side of the part
to the 1 diameter. Be sure to include the tool path for all radii required.
Material stock size is 1 .

MCAR

May 2012

39

MCAR

May 2012

40

Part Three Canned Cycles

What is a Canned Cycle?

G-Code
Input data
Describes a feature
Performs a task
Minimal programming
Standard

Canned cycles are one of the most useful series of G Codes available to a programmer. A
Canned cycle uses data input by the programmer that describes a feature and performs a task
in order create a feature with minimal effort on the part of the programmer. A canned cycle is
similar to a macro or subroutine that comes standard in the machine control.

Functions

Turning / Boring
Face Grooving
Part Off / OD Grooving
Threading
Drilling
Tapping

Structure

Position machine
Call cycle
Perform cycle
Variables and Parameters
A typical canned cycle requires the machine to be in position before the canned cycle is

called. Once the canned cycle is called, it will perform the operation at that location. The
programmer will also need to know what parameters to alter or insert in order for the cycle to
work correctly.

MCAR

May 2012

41

Example
Below is an example of what the structure of a typical canned cycle looks like. In this
case, it is a turning canned cycle for a Fanuc control. The purpose of this canned cycle is to take
a pre-programmed part profile and break it down into several cutting passes that the cutting
tool will be able to handle. This is done through setting variables in the canned cycle line. The
variables are like limits or boundaries which the machine then uses to determine how many
passes to make or how much to leave on the semi-finished profile for a finish cut to remove.
G71 Turning / Boring canned cycle (Fanuc Style)
G71 U1000 R300
G71 P101 Q102 U.03 W.005 F.012;
P Starting Block
Q Ending Block
U on First G71 Line Depth of cut per side
R Clearance amount
U & W Finish Allowance for X & Z
F Feedrate
The above cycle is used with repetitive turning and boring operations on Fanuc style
controls. The canned cycle uses a series of variables in order to break down the programmed
profile into even cuts. Canned cycles can also create geometry such as a threaded feature by
making multiple passes in order to maximize the quality of the feature while not over stressing
the tools.
Knowing which canned cycles come with the machine you are programming is
paramount if you want to utilize them to aide in such things as breaking down complex
geometry and simplifying roughing operations to name a few.

MCAR

May 2012

42

Common Lathe Canned Cycles


G70

OD / ID

Turning / Boring Linear Finishing

G71

OD / ID

Turning / Boring Linear Repetitive

G72

OD / ID

Turning / Boring Facing Repetitive

G73

OD / ID

Turning / Boring Pattern Repetitive

G74

OD / ID

Face Grooving

G75

OD / ID

OD / ID Grooving

G76

OD / ID

OD / ID Threading

G81

Drilling

Straight Drilling

G83

Drilling

Deep Hole Peck Drilling

G84

Tapping

Rigid Tapping

Creating a canned cycle


Each canned cycle use specific variables that allow necessary data to be read correctly in
order to perform the cycle.
Not only do you need the correct G Code to tell the machine what you want to do, you
need extra information to tell the machine how you want it to go about performing the
operation. The following are the canned cycles listed above and
G71 Turning / Boring canned cycle (Fanuc Style)
G71 U1000 R300
G71 P101 Q102 U.03 W.005 F.012;
U (on First G71 Line) Depth of cut per side
R Clearance amount
P Starting Block
Q Ending Block
U & W Finish Allowance for X & Z
F Feedrate
MCAR

May 2012

43

Variables: Finding the Perfect Recipe


The variables in the cycle are preset and are commonly used in many machines with
Fanuc style controls. They can control everything from the Z axis movement, the depth of cut,
the feed of the machine, and what type of function is being preformed among other things as
well. The different variables are common CNC commands called programming words. A word
will start with a letter then followed by a number otherwise known as an Alpha-Numeric
statement. The number portion of the statement will sometimes allow a decimal point to be
used and sometimes not.
Understanding the variables can be confusing and you may find it beneficial to create a
reference sheet like the example on the next page. This will help you when using cycles that
you are not familiar with.
To explain how a canned cycle works using variables, try to think of a recipe. You start
with a list of ingredients and if you follow the recipe and use the ingredients correctly, you will
be eating something tasty really soon. Lets say you choose to skip on some ingredients, you
may still end up with a finish product but it will probably not be as satisfying. If you use the
wrong ingredients or leave out the most important ones, you will more than likely be dining out
because whatever it was you were trying to make, will not turn out. A canned cycle is along the
same thinking. You need to use all the required variables to work perfectly. Leaving some
variables out, the cycle will still work but maybe not as efficiently. If, however, you enter
variables that do not belong or are entered incorrectly, it will cause the machine to reject the
code all together and you will have to reprogram the cycle before it will operate.

MCAR

May 2012

44

Below is a table of some of the most commonly used canned cycles and the variables
that are often used with them.
G70

G71

G72

G73

G74

G75

G76

G81

G83

G84

It is often useful to make a cheat sheet of the various canned cycles and have the other
variables listed with each one so you will not only be sure to use the right variables ones with
each cycle, but you will also keep from omitting or including data that would prevent the
function from being performed properly.
Just the same, too little information can cause mistakes as well. Most CNC machines
have codes that are called modal which means they remain active in the memory until altered
by the user. A common modal command is feed rate. If you do not enter a new feed rate when
you want it to change, it will stay the same and may cause issues such as when tapping.
This is why it is important to know all the variables before you try to enter them in and
not shoot from the hip as it were when entering data. Carefully constructed programs will
allow for fewer mistakes and faster set up times.
MCAR

May 2012

45

In Review
As you have read, canned cycles are very powerful tools that you can use to shorten the
amount of programming you will need to do in order to complete a task. Instead of writing each
line of code for each pass of rough turning a shape, for example, the canned cycle uses built in
macros that are designed to eliminate all of the extra programming work and potential costly
errors as well. Once they are mastered, the cycles will undoubtedly become second nature
when performing any hole making task.

MCAR

May 2012

46

Canned Cycle/ Programming Exercise


Study the following program then fill in the blanks with the missing G and M Codes.

O1500(CANNED EXERCISE #1);


(OP 1)
(TOOLS);
(T1 CNMG 432 OD);
(T3 DNMG 431 OD);
G___ S1600;
G0 G40 X5. Z3.;
(ROUGH OD);
T0101 M___;
G54
G96 S600 M03;
G0 G___ X2.1 Z.01;
G___ X-.07 F.01;
Z.1;
G0 X2.;
G71 U1000 R300
G71 P101 __102 U.03 W.005 F.01;
N101 G0 X1.;
G01 Z-1.25;
X1.75;
Z-1.875;
__102 X2.;
G___ G40 Z.2;

MCAR

X5. Z3. T0100;


M___;
(FINISH OD)
T0303 M08;
G___;
G___ S780 M03;
G0 G40 X1.1 Z0.;
G01 X-.07 F.006;
Z.1;
G___ X.95;
G01 G42 Z0. F.005;
G03 X1. Z-.025 R.025;
G___ Z-1.25;
X1.7;
G03 X1.75 Z-1.275 R.025;
G01 Z-1.875;
X1.95;
G___ X2. Z-1.9 R.025;
G01 Z-1.95;
X2.1 M09;
G0 G___ Z.2;
X5. Z3. T_______;
_____;

May 2012

47

MCAR

August 2014

48

Part Four Writing a CNC Lathe Program


Preparing to Write Programs
We have come to the point where you are ready to write programs. An important piece of
advice for writing programs is to make sure you perform as many operations that you can per each
work holding set up. Too often there are extra set ups made that are unnecessary. Though mostly
it is due to how that person was taught, a portion of the time it is because the programmer did not
stop and thoroughly look at the part and plan things out.
If you can save just one extra set up on a job, you will have saved a tremendous amount of
time and money. Something as simple as allowing the part to overhang the edge of a vise and
perform a side milling operation after drilling and tapping holes instead of performing those
operations separately. The time lost is not only in the set up but also the extra handling of the
work piece. The work piece was still just as secure and supported but an extra operation was
added to the program and not performed in an entirely new set up.
That is something to think about when looking at a part print and getting ready to program
it. Ask yourself, What operations need to be performed to make this part and how many can I
perform to prevent extra set ups?
The following are the steps used by most programmers when wanting to write a program
for any given part.

Steps of writing a program

MCAR

Calculating What Needs to be Machined


Locating Part Zero
Tool Selection and Placement
Writing the Program
Proofreading for Mistakes and Omissions
Running the First Part for a New Program

August 2014

49

Calculating What Needs to be Machined


Locating and identifying part features is an important skill that is needed to write programs
effectively. Some part prints are not always clearly defined in reference to what is finished and
what isnt. Once the features of a work piece that need to be machined are identified, the next
step is knowing which order to put them in for the cutting process to be both accurate and
effective. The order of which certain machining functions are implemented is known as process of
machining. It is the first key to any good program. Knowing and using the correct order to create
part features on any work piece translates into safe, efficient, and most of all, correct parts. Too
often process of machining is overlooked or taken for granted.
Here is an example: You want to put threads on a work piece you are creating. The raw
stock for the work piece is 4 inches in diameter. The size of the thread needs to be 2 inches in
diameter. In order to be able to create the thread you must first remove the excess material. Once
that is done, you will need to decide if there needs to be a clearance groove at the end of the
thread or if the thread will pull out using one of the pull out methods. Once you have done that,
you will need to write the threading cycle, making sure you have the correct variables in place
such as thread height depth of first cut, finish allowance and feed rate. After all of the preparation,
you are ready to cut the thread. Can you see how there were several steps required before
creating one feature? In order to do so, you had to prep your work piece to the point where it was
ready to accept the thread cutting cycle. This is process of machining.

Locating Part Zero


For most lathe programs, the face of the work piece is usually declared Z0. The centerline
is almost always considered X0. This means that Z Axis movements into the work piece will be a
negative value. All X Axis values will typically be read in diameter and will be a positive value.
Some programmers program all work pieces from the face of the work holding device, usually the
soft chuck jaws. If this is the case, you will need to work backwards from the longest value from Z0
towards Z0 itself. This can be dangerous and often requires multiple calculations. For safety
reasons, you will only be taught to program from the front of the work piece as Z0. If you want to
move into the work piece on the Z axis, the display will look like this: Z-.250

Tool Selection and Placement


After you know what processes you are going to use, you will need to select the tools to
perform those tasks. On top of that, you will also need to figure out where in the tool turret each
tool needs to be placed. When selecting tools, there is no silver bullet to any one operation,
meaning that there is not a perfect tool to do every type of cut. You will need to make sure each
tool will perform the cut required and has the proper clearance and tip radius in order for the
work to be completed correctly. Which turret position and how far to project each tool from the
MCAR

August 2014

50

tool pocket will vary based upon the operation and parameters of what is being cut. A set up that
works on large parts may not work on small parts. What works on one material may not work on
another and so forth. There are an infinite number of variables when machining. A good example
is that a certain type of tool may work great on a new machine but may not work on a machine
that is several years old and has a lot of wear and tear. Machine alignment sometimes plays a role,
work piece holding is another. This list goes on and on. Most of the time, it is best to start with
what you know from experience. If you are not experienced, start with a recommendation from a
lead man or machine manual. From there, it is simply trial and error. No one can just wave a magic
wand and grant you experience, it is something that can take a while to obtain in certain
circumstances. One of the key elements for setting tools into the turret is to make sure one will
not contact the spindle or work holding device when the tool next to it is in position to make cuts.

Writing the Program


Now it is time to put the rubber to the road and write the program. Using the part print as
your map, navigate around each part feature that needs to be created and be sure to follow the
path of least resistance. Most of the time, you will want to rough the entire profile, both external
and internal before finishing both the external and internal surfaces. Next, auxiliary functions such
as grooving, threading, knurling and milling can be performed. What order you put them in greatly
depends on the circumstances regarding size and surface finish required on the finished part.
Most programmers insert an M01 before each new tool call after the first tool makes its cuts so
they can activate the optional stop in order to verify the progress of their work.

Proofreading for Mistakes or Typos


The last thing you need to think about when writing a program is to check and recheck for
mistakes and typos. It is too often that programs are rushed to be written and then rushed to be
run without checking for mistakes. This results in omitting or incorrectly locating features,
improper machine movements which can result in a crash, machine errors, and improper feature
size or shape. Once you write a cycle for a particular feature, go back and double check to make
sure the data makes sense. When you have completed the program, go back one more time and
check again for missing or misplaced decimal points and any other typos.

Running the First Part


Depending on the policy of the company you work for, you are now ready to run the first
part. Most programmers are also the set up person for companies. If this is the case, you get to
check your own work. If you only write the program and then have someone else run the first
piece. Be sure to tell them that it is indeed a NEW program and caution them to follow the cuts
closely and also to pay attention to the next move in the queue. If they have a graphics option on
their machine, you might suggest they run the program through the tool path graphics to ensure
MCAR

August 2014

51

there are no errors and all of the cuts appear to go where they need to. Once the first part is run,
speed and feed adjustments can be made and also any offset adjustments to bring the part into
tolerance.
Congratulations on writing your first program!

Class Exercises
Your Instructor will provide you with part prints that you will use in order to write
programs. He/she will explain which tools to use, discuss where the reference zero location should
be set to and any other necessary information you will need to create your first program. You will
then take your program out to the machine and run it, creating a part. If there is time, you will be
able to write several programs and then run them on the machines.

MCAR

August 2014

52

You might also like