Understanding

How to Write

CNC Lathe
Programs
MCAR

May 2012

1

MCAR

May 2012

2

TABLE OF CONTENTS

CHAPTER

PAGE

Part One – CNC Lathe Programming Basics

5

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

3

MCAR

May 2012

4

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. Let’s 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

5

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

shapes that are associated with the points. You should now have a profile of the object you are trying to create. MCAR May 2012 7 . Below is an example of the labeled Quadrants used in the Cartesian coordinate system.

Below is an example of a Lathe Cartesian Coordinate Grid MCAR May 2012 8 .

Using the method shown above. can form simple to complex geometric shapes. Below is an example of a plotted point on a Cartesian coordinate system. plot the points shown on the next page with each corresponding number.Plotting Geometry Using the Cartesian Coordinate System The most crucial building block to all of geometry is the point. once linked together. The point helps establish a location on a grid that. MCAR May 2012 9 . Points have no size and no depth but are usually documented as a round dot when plotted on any grid.

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 .

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

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

MCAR May 2012 13 . other programming codes will be added in order to correctly position and move the machine through the plotted path. Z– quadrant using points. 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. go back and connect the dots using lines to create a profile.The following is an exercise for creating a geometric shape in the X+. then lines. Once the geometric profile has been created. When you are finished plotting the points.

Programming Words Along with X and Z axis coordinates. Probably not like the words such as you are reading in this manual. X and Z in order to create a 3 dimensional object. Those things can and will happen throughout your career as a programmer. MCAR May 2012 14 . the CNC machine tool requires other commands in order to create a shape or profile. the simplicity of the lathe programming is that you only need to think in two dimensions. Many times people try to overcomplicate the process but in the end. material types and work piece holding. Being able to adapt and overcome such obstacles is what makes some programmers more effective than others. 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 commands come in the form of words. 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. What can complicate something viewed as being so simple are things such tool clearances. The newer the machine. 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. 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. 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. Words are typically one letter and up to three numbers in length. the entire profile is created as the tool engages the work piece. the majority will tell you that Lathes are the simplest. As stated before. This type of word is called a programming word.Speed Bumps and Pitfalls If you ask people which type of machine is the easiest to program. 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.

W. K.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. C. S.Z O Depth of Cut P.Y. M. & T MCAR May 2012 15 . N. U. A.C D Axis of Rotation for X. F.K Variable for Canned Cycles Incremental Radius Values for X.W M Miscellaneous or Machine Code X.B.Z N Program line number Clearance Plane for Canned Cycle Incremental for X. Ones that allow for a decimal point and others do not. Please note that not all of the words are used in every CNC program. O. J.V. some variables do not appear until they are needed for a specific option. Q Offset Call for Cutter Comp Program number Variables for Canned Cycles Start End Blocks Return amount F Feed Rate R G Preparatory or “Go” Codes S Speed. P. L.Y. X. The words that allow or may require a decimal point are: A. I. B. Q. Y.Y. & Z The words that do not allow or may not require decimal points are: D.J. R.Below is a list of programming words commonly found in various CNC programs.Z L Number of repeats in a cycle U. V.Y. RPM or SFM T Tool Call I. G.

meaning you are telling the machine to go do something such as perform a task. Most often. There are just about as many G Codes as there are functions to a machine. along with the G code so that the function performs as expected. This means that the codes instruct the machine to perform a task or function based on a particular G code’s parameters. 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. 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. There are some G codes however. additional information must be inserted in the form of other programming words. G codes control a variety of functions such as machine positioning. canned cycles. offset length compensation. feed rate control. Programmers often remember G codes by calling their functions “go” commands.G Code Programming What are G Codes? G codes are preparatory codes. G20 is the Inch Input G code is an example of a G code that does not need any other variable to operate. MCAR May 2012 16 . hole pattern creation. that can work all by themselves without the extra words. to name a few. An example would be calling G01 which is a linear feed move. Sometimes. you will find G01 on a line with X and/or Z. Most G codes must have extra programming words included on the same line in order to perform the task requested. For example. tool radius compensation.

you will need to know what G code will need to be used to perform that function. G Codes can reduce the amount of programming time by condensing the amount of code needed to perform a task. create a hole pattern. select offsets. Below is a list of common Fanuc based G codes. cut in a radial motion. MCAR May 2012 17 . Using G Codes When you want to use a G code. one of the first things you want to insert is a G00 for machine rapid positioning. the first thing you will need to ask yourself is. 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. just to name a few.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. For instance. move in a controlled manner. “What do I want the machine to do”? Once you decide which function to perform. if you want to position the machine.

G57.G13. Basic Structure is much like you would write a sentence.G82.G55.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. 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. This is called a modal command. to be simple and fast.G92 G00. Non Modal commands are ones that cancel themselves as soon as the function is performed.G53. MCAR May 2012 18 . This simply means that for the most basic information.G02. System Group Name Codes in the Group 0 or 00 Non-Modal G04. for each tool call. There is a common recurring method that most programmers use called a programming style. There are some exceptions.G21 G40. a programmer tends to insert the data into the same place every time.G91 G98.G42 G98.G10.G52.G28.G81.G83.G12.G80.G99 G20. CNC Programs are much easier to comprehend when they are used in a common repetitive order.G18.G41. Modal G Codes Group Name Codes in the Group 1 2 3 5 6 7 10 12 Motion Plane Distance Feed Units Cutter Comp.G19 G90.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. The following list shows the various groups and also the ones that do not need to be cancelled.G99 G54.G03.G58. Return Mode Coord.G84 G17.G01.G56. at the end of every tool operation and at the end of the program. This is called basic program structure.

It is important to remember to use the letter O and not a zero here. The important thing is to be able to understand what needs to be in a program and what doesn’t. a program number must be designated for the machine’s memory. The following pages detail a basic style for starting a CNC program. If you do not insert an end of block when you want to end a line of code. 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. Each line of a program ends with a semi colon ( . N50 G96 S750 M03. 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. They will all accomplish the same thing but the formatting will be a little different within each one. errors or erratic machine movement can occur.Compatibility One of the biggest problems within any shop is writing the programs so they can be read and understood by anyone. N30 T0101 M08. 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. N40 G54 . calling a tool. taking a tool to a tool change position and the codes needed for ending a cycle or program. MCAR May 2012 19 . N20 (T1 – TOOL DESCRIPTION). Above is an example of a typical program start up. The letter O is used before a 4 or 5 number program designation for most Fanuc based controls. ) known as an end of block ( EOB ). you will likely come back with 10 different programs. For every CNC program on a Fanuc style control. N10 (COMMENT). Start of a Program O1234 (Part #### for XYZ Company).

Any words in parenthesis are called comments. T0101 M08. which operation is being performed and information regarding the handling of the work piece. Comments are mostly used as random bits of information for the operator such as what tool to use. etc. Comments can be seen by the operator but are ignored by the machine. clearing chips. This also happens a lot if you have a long cycle time and it is the end of the work day. For example. 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. Comments can also contain valuable set up information such as which Work Offset to set up to. The rest of the code stays the same. N0300 and so on.otherwise the machine will generate an alarm and will not load the program into the active memory. Storms that cut power from lightning strikes can be one source of power loss. So every tool call after the first will be N1000. G0 X#### Y#### The tool call is very similar to the program start up except the lack of extra comments and the program number. N0200. always make a habit of inserting it when calling a tool. Since he knows he will not finish the entire program. N Numbers can be up to 6 digits on some modern machines but is usually 4 digits on older models. you write a program using G57 and it is a 40 minute total run time. N3000 or N0100. Tool Call (T1 – TOOL DESCRIPTION). he will MCAR May 2012 20 . G54 G96 S550 M03. The reason for this is in case you need to or your machine is powered down while in a cycle. The letter N is used to number the lines of code. Most programmers prefer to count by tens when initially writing a program. N2000. The operator starts the run 20 minutes before quitting time. Even though you may not change your work offset while running the part. This allows for the addition of extra lines of code without totally rewriting the entire cycle in most cases. flipping the part over. Most tool calls after the first one start with either a new number in the hundred or thousand position.

X10. the operator does not have to stop the program every time. Things the operator may check for include. the machine will crash. T0100. MCAR May 2012 21 . With the optional stop. 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. part size. and part clamping. As you can see the spindle start command usually occurs before the machine moves towards the work piece. broken or chipped tools. Ending for a Tool Cycle G0 G40 Z. Before calling the next tool it is recommended to cancel any tool nose radius compensation.2 M09. By having the machine at a safe tool change position. the machine automatically defaults to G54. shut the coolant off and to take the machine to a safe tool change position. but he/she does have the option to do so if needed. M01. The next morning when he starts the machine back up.activate the optional stop button and stop the program before the next tool change. the machine will not be performing the work in the correct location. Z10. surface finish. tool wear. The M01 is the optional stop M code and will allow the operator to stop the program before the next tool is called. the operator may safely use the optional stop to check the part or tool as it completes this portion of the program. The part will be scrap or worse. 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 program ends with the machine being sent out of the way of the work piece. . X10. M30. (boring bars.1 M09. or G28 G91 X0 Z0. etc. ID grooving tools. In any way that it is done. 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. drills. Some companies require that the tool turret be rotated so that tools which project outward from the turret. 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. Z10. G0 G40 Z. T##00. MCAR May 2012 22 .Ending of a Program .1 M09. M30. When ending a program. G0 G40 Z. 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.) be rotated so that there would not be any incidents where to the part contacts the tool.

tool call. 2. Z10. G54. Some or all of the code may not be positioned on the line where it is needed. G00. G00. T0606.1. M03. Simply rearrange all of the information in order.1. (COMMENT FOR SET UP). Program Structure Exercise 1. X10. M09. M08. G56. T0101..Exercise For the exercise below you will need to write the code for a program start up. G96. (1/2” BORING BAR). T0400. Z10. M01. 3. and end of program. O1234. end of tool. S1500. G96. The code provided next to each exercise number will give you all the required information. S500.. (T1 – CNMG 432 OD). Z. M03. 4. Z. M30. X10. G40. G40. (ABC COMPANY). M08.. M09 T0300.. MCAR May 2012 23 .

you must decide the most important feature of that part you want to create. now what? Once this point has been established. In most instances. the next step will be to assign a Work Offset to the part.Program Zero and Work Offsets When you begin a program. all other programmed movements for operations performed on the part should come from that location. Without a starting point. MCAR May 2012 24 . 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. All programmed points will be calculated from these set locations and the locations will be used when setting the work offset value as well. 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. Picking points without a physical location can be tricky and confusing for an operator so take that into your thought process. there will be nothing to reference all of your moves. 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. it becomes hard to set up repeat jobs without a clear method of setting the zero point. before you write the first meaningful line of code. where to start everything at. Just remember. nor will an operator be able to setup the machine since he will not know how to orient the work piece. this starting point will be known as the Program Zero. Once the Program Zero has been established. The starting point has been established. whether it is a point on a finished work piece or a point in space. Otherwise.

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. 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. Tool Offsets With all the different tool shapes and sizes that are made today. You will need to consult your machine tool builder’s manual to find out if there are any extra G Codes used for Work Offsets. 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 are helpful if you have multiple jobs set up on a single work table.Work offsets and you. 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 . Each location where a part is to be made can have its own Work Offset. This is why Tool Length Offsets were created. They also are handy when using fixtures that will hold several of the same work piece. How many different work offsets are there? The most common Work Offset G Codes used are G54 through G59. 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.

0. 0 7 -21.6325 0.6729 -0. 0. 0 11 -13. You will need to consult your company to know which method they prefer to use. This is usually the top of a finished work piece. 0. 3 MCAR May 2012 26 . 0. 2 6 0.4463 0. 0. 0. 0.0073 0.0036 0. This will allow actual true tool movement to be set.6864 0.0156 2 10 0.0052 -0. 0.5595 0.3367 0. 0.5294 0.1673 0. 0.9133 0. 0. Tool Offset Page Offset X Wear Z Wear Radius Tip 1 -14.0142 0.0312 3 2 -13. 0. 0 9 -19. 0. 0.0056 0. 6. 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. 0.1335 0. Programming becomes simpler because each tool start point is referenced to a known zero location. This allows only the actual tool length.0312 2 8 0.0162 . 3 12 -14. Each tool can be “tweaked” by making fine adjustments for each tool if needed.8268 0.0083 . The program work offset for Z is then set. 3 3 -16.7441 0. 0 5 -22.5898 0.0072 -0. 0. from the face of the spindle to be entered. 0.0156 3 4 0.0034 3. The reference dimension is then put into a user offset page that has a listing of offset numbers. .0022 . The following chart shows a sample tool offset page as it might look on any given CNC control.3714 -0. 0.9119 0.0085 4. including holder.In most cases. 0. 0. Tool Length Offsets establish a reference dimension from home position to an active part zero reference plane.

If. Again. it is easier to write down small numbers in the wear column. than the entire geometry offset. a tool nose compensation function is used. which offset value will be used. the operator will need to be sure to enter the tool tip radius in the geometry page. it is often found that the tool offsets match the tools position in the numbered turret. 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.Since most CNC lathes use a numbered tool turret. for example. A Helpful Tip Write down the current offset already input on a scrap piece of paper. the operator will need to know which tool position the tool is located. MCAR May 2012 27 . 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 will help make sure you did not make a mistake or miss-key when entering in the new number. This is more from a safety point of view than anything else. 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 28 .

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. tool nose compensation or tool nose comp as it is often called. The tool centerline is ALWAYS programmed. Two Types of Programming Methods There are two programming methods used in profile machining operations on modern lathes. tools are often not thought of and all the programmed moves must be calculated out manually to compensate for the tool’s nose radius. the radius of the tool tip causes the tool to cut the shape incorrectly. 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. especially ones just starting out. We will also go into detail about the rules and proper use Tool Nose Radius Compensation. tapping.Part Two – Programming Methods & Tool Nose Radius Compensation “TNRC” During the part of the class. As the tool moves through the various geometric shapes. For some programmers. The reason for this is that the machine moves the tool through each position as if MCAR May 2012 29 . This becomes more and more difficult when radii and angles are created. For any operations such as drilling. we will discuss the two main programming methods for creating geometry using CNC lathes. When creating a geometric shape on paper. etc. Machine Compensated and User Compensated. has frustrated and caused more problems that its designed intent.

The programmer will not have to calculate for the tool nose radius because all of the machining occurs in the X and Z axis. the geometric shapes would be exactly as programmed. 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. It does not take the radius of the tool into account. The image above depicts the tool path of a user compensated method of programming. The larger the radius on the tool tip. the greater the Cosine Error. 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. If the tool was indeed a sharp point. MCAR May 2012 30 . When Radii or Angles are called out. The term for the improper geometry created is called Cosine error. 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 tool tip was a theoretically sharp point at a theoretical 90 degree angle to the cut being made. most programmers use the other type of programming instead of trying to compensate the moves manually.

G54.1. G03 X2. MCAR May 2012 31 .281 Z-2. Tool Nose .. T0100. G0 Z.Program T0101 M08.281 R. M30.031 Radius Program T0101 M08. Z-2. G0 Z. G54. T0100. Z-1.1. you will see the same general shape but with a slight twist. G01 Z-1.1 M09. G96 S700 M03. X3. Z.. F. G0 G40 X1. X1.. X10. G01 Z-1.438. Z10. G0 G40 X1.1.1 M09. X3. X10. Z10. M30.. X2. G96 S700 M03.008.008. F.1. In the next image. Z.

While this may not be difficult for radius shapes presented at 90 degrees in movement. G54. Typically on Fanuc machines. This is due to the programmer having to compensate for the nose radius on the tool being used. If you do not put a tip in the offset page. 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. 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. the machine will use 0 for the tip and the tool compensation will more than likely have errors in the computed path..031 Radius Program T0101 M08.In the example. Notice that the radius compensation is more than the actual radius called out. 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. MCAR May 2012 32 . The tool tip will need to be declared in most cases. changing the tangent points from 90 degrees to let’s say 45 degrees creates a whole new set of math equations that will need to be made to ensure the correct geometry is created. tip #3 is for OD normal turning style tools while tip #2 is for normal ID boring style tools. 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. What this lets the machine know is how the tool is oriented in reference to the edge of the work piece. Tool Nose . G96 S700 M03.

. 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. G03 X2. The program reflects the actual tool movements without having to calculate extra geometry in order to compensate for the radius being created.1. If you are just turning or facing straight back or down. knowing just what is needed to be machined will lead to exactly what will need to be compensated. Z. Using Machine Compensated Programming. X10. Z-1.25 Z-2.008. Z-1. then you do not need any type of tool nose compensation. but if you have complex geometry of any sort.1 M09. Once you have all the facts. M30. use the method that best suites the situation.25 R. G0 G40 Z. 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. F. What you see is an example of a machine compensated method of programming. G01 G41 Z0. X3.G0 G40 X1. you should opt to the machine compensated method. Key factors for correct Tool Nose Compensation: When and Where Tool Nose Radius Compensation is needed /possible.5. X1.1. it will MCAR May 2012 33 . T0100. Z10. When having to pick one style from the other. In the end.

the machine calculates the complex mathematical equations based on part and tool geometry. There are no set order to the rules. 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. This would result in angles and radii being cut undersize.all depend on how much information you have about the various geometry and how comfortable you are with creating your own compensated tool paths. in effect. 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 will allow the tool to travel along a modified programmed path and compensate when making angular and radial movements. out of compensation mode. When finished. Without Tool Nose Radius Compensation. the machine shifts the tool back to the theoretical edge position. The tool then moves around the new computer modified path so that that it cuts on the compensated tool nose radius at all times. Once inserted. only that they ALL must be followed to create a tool path with no errors. 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 tool’s actual position based on the tool’s nose radius size and tool tip orientation in order to correctly create geometric features accurately. MCAR May 2012 34 .

MCAR May 2012 35 .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. G42 is used primarily in right handed turning operations. More programming mistakes are made from making the wrong compensation selection than other compensation errors. It is best to never skip a rule. typically on lathe programming. If you follow some of the rules but not all of them. errors can and usually will occur. 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. Decide to use G41 or G42 based on what machining function you are performing. Rule #1: Figure which mode of Tool Nose Radius Compensation is to be used. G41 is used for boring tools while G42 is used for turning tools. 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. 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. As an example. which side of the tool is being used as the primary cutting tip and what type of compensation to use.

(This is the better of the two) 2: the machine plunges the tool into the part in an attempt to make the compensation. The location where the shift occurs is often called the lead in position.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. One thing to note. Simply put. 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. The second result occurs most often on older machines.008 tool nose radius and are going to cut along the edge of a part. must be added to the amount shifted. Some machines. Example: If you are using a turning tool with a . It is never a good idea to move the machine in two axis while turning on the compensation. from a cast surface or previous machining operation. Newer machines have specific deviation alarms which prevent gouges or incorrect geometry from being created. any extra material. Rule #3: Do not insert a G41 or G42 in a line with both an X and Z axis feed movement. the position must be at least . This results in an imperfection or a crashed part / tool. MCAR May 2012 36 . shift the tool in the correct direction and distance from the part.009 more than the actual position of the edge of the part. otherwise the tool will move down and possible crash into the work piece. 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.

to move back towards the machine’s theoretical edge as it disengages tool nose radius compensation. 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. mainly older ones. it was because one of the rules stated above was not followed or was not followed closely enough. chances are. it may crash into the part. MCAR May 2012 37 . 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. On newer machines. If the offset value is incorrect or missing. On some machines. It was designed to make your life easier and your programming a lot more practical. tool nose compensation is removed right after the last X movement that clears the tool from the work piece. If your tool nose compensation alarms out when you try to use it. if the movement amount is not far enough. the more it will feel natural is a good rule of thumb to go by. the machine physically shifts the tool back to the theoretical edge of the tool. A good majority of the time. when tool nose compensation is cancelled.Rule #5: Clear the work piece completely before canceling Tool Nose compensation. an alarm is usually generated. This allows for some machines. If your tool is not completely clear. either an alarm will be generated or the tool path will look incorrect. It is recommended to clear at least two times the radius plus several thousandths away from the side of the work piece. 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. The more you use it. even in graphics enabled machines.

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

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. Material stock size is 1 ¾”. Be sure to include the tool path for all radii required. MCAR May 2012 39 .

MCAR May 2012 40 .

Once the canned cycle is called. 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. 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 .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. it will perform the operation at that location.

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. 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. In this case. G71 – Turning / Boring canned cycle (Fanuc Style) G71 U1000 R300 G71 P101 Q102 U.005 F. This is done through setting variables in the canned cycle line. 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. 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.03 W. MCAR May 2012 42 .Example Below is an example of what the structure of a typical canned cycle looks like. The canned cycle uses a series of variables in order to break down the programmed profile into even cuts.012. it is a turning canned cycle for a Fanuc control. 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.

03 W. 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 .005 F. Not only do you need the correct G Code to tell the machine what you want to do.012.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. The following are the canned cycles listed above and G71 – Turning / Boring canned cycle (Fanuc Style) G71 U1000 R300 G71 P101 Q102 U. you need extra information to tell the machine how you want it to go about performing the operation.

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

too little information can cause mistakes as well. G70 P Q G71 P Q U W F G72 P Q U W F G73 P Q U W F G74 X Z P Q R F G75 X Y P Q R F G76 X Y R P Q F G81 X Z R F G83 X Y R Q G84 X Z R F F 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. it will stay the same and may cause issues such as when tapping. If you do not enter a new feed rate when you want it to change. A common modal command is feed rate. MCAR May 2012 45 . Most CNC machines have codes that are called “modal” which means they remain active in the memory until altered by the user. Just the same. but you will also keep from omitting or including data that would prevent the function from being performed properly. Carefully constructed programs will allow for fewer mistakes and faster set up times. 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.Below is a table of some of the most commonly used canned cycles and the variables that are often used with them.

the cycles will undoubtedly become second nature when performing any hole making task. the canned cycle uses built in macros that are designed to eliminate all of the extra programming work and potential costly errors as well. MCAR May 2012 46 . for example.In Review As you have read. Once they are mastered. 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.

006. G01 X-. G0 G___ Z. G___. (ROUGH OD).75.1. Z-1. N101 G0 X1.1 Z. T_______. G0 X2. G03 X1.025 R.95.Canned Cycle/ Programming Exercise Study the following program then fill in the blanks with the missing G and M Codes. G03 X1. Z. __102 X2. G0 G___ X2. G___ X2. Z-1. _____.25.. (FINISH OD) T0303 M08.875.875. G01 G42 Z0.. G___ X-. Z3.25. Z. Z-.275 R.9 R. G01 Z-1.005. G___ S780 M03. May 2012 47 . G___ G40 Z. X1.01. X1. G0 G40 X5. M___.025. (T1 CNMG 432 OD).. X1.1 Z0.005 F. O1500(CANNED EXERCISE #1).025.1.2. T0100.025. (OP 1) (TOOLS). F. G___ S1600. G54 G96 S600 M03. G___ X.01.. T0101 M___. Z3.01. G01 Z-1.07 F.. G01 Z-1.2. X5. MCAR X5.7. X2.95. G71 U1000 R300 G71 P101 __102 U.1 M09.03 W.95. G___ Z-1. G0 G40 X1. (T3 DNMG 431 OD). Z3.07 F.75 Z-1.

MCAR August 2014 48 .

a portion of the time it is because the programmer did not stop and thoroughly look at the part and plan things out. 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. Ask yourself. The time lost is not only in the set up but also the extra handling of the work piece. you will have saved a tremendous amount of time and money. If you can save just one extra set up on a job. “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. 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. 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. Too often there are extra set ups made that are unnecessary. Though mostly it is due to how that person was taught. That is something to think about when looking at a part print and getting ready to program it.Part Four – Writing a CNC Lathe Program Preparing to Write Programs We have come to the point where you are ready to write programs. 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 .

All X Axis values will typically be read in diameter and will be a positive value. This can be dangerous and often requires multiple calculations. you will need to select the tools to perform those tasks. 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. On top of that. correct parts. there is no silver bullet to any one operation. you will also need to figure out where in the tool turret each tool needs to be placed. Once the features of a work piece that need to be machined are identified. Which turret position and how far to project each tool from the MCAR August 2014 50 . 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.Calculating What Needs to be Machined Locating and identifying part features is an important skill that is needed to write programs effectively. 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. Once that is done. you will only be taught to program from the front of the work piece as Z0. you are ready to cut the thread. The size of the thread needs to be 2 inches in diameter. Locating Part Zero For most lathe programs. the face of the work piece is usually declared Z0.250 Tool Selection and Placement After you know what processes you are going to use. you had to prep your work piece to the point where it was ready to accept the thread cutting cycle. usually the soft chuck jaws. and most of all. When selecting tools. efficient. making sure you have the correct variables in place such as thread height depth of first cut. meaning that there is not a perfect tool to do every type of cut. you will need to write the threading cycle. Knowing and using the correct order to create part features on any work piece translates into safe. This means that Z Axis movements into the work piece will be a negative value. finish allowance and feed rate. In order to be able to create the thread you must first remove the excess material. you will need to work backwards from the longest value from Z0 towards Z0 itself. If you want to move ¼” into the work piece on the Z axis. The raw stock for the work piece is 4 inches in diameter. The centerline is almost always considered X0. Here is an example: You want to put threads on a work piece you are creating. This is process of machining. If this is the case. For safety reasons. After all of the preparation. Too often process of machining is overlooked or taken for granted. the display will look like this: Z-. Once you have done that. Can you see how there were several steps required before creating one feature? In order to do so. Some part prints are not always clearly defined in reference to what is finished and what isn’t. Some programmers program all work pieces from the face of the work holding device.

A set up that works on large parts may not work on small parts.tool pocket will vary based upon the operation and parameters of what is being cut. 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. 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. If you are not experienced. If you only write the program and then have someone else run the first piece. you get to check your own work. There are an infinite number of variables when machining. it is something that can take a while to obtain in certain circumstances. If they have a graphics option on their machine. it is best to start with what you know from experience. When you have completed the program. you might suggest they run the program through the tool path graphics to ensure MCAR August 2014 51 . navigate around each part feature that needs to be created and be sure to follow the path of least resistance. What order you put them in greatly depends on the circumstances regarding size and surface finish required on the finished part. Next. improper machine movements which can result in a crash. it is simply trial and error. Once you write a cycle for a particular feature. and improper feature size or shape. knurling and milling can be performed. Most programmers are also the set up person for companies. you will want to rough the entire profile. go back and double check to make sure the data makes sense. This results in omitting or incorrectly locating features. machine errors. 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. you are now ready to run the first part. This list goes on and on. From there. Machine alignment sometimes plays a role. 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. What works on one material may not work on another and so forth. If this is the case. auxiliary functions such as grooving. go back one more time and check again for missing or misplaced decimal points and any other typos. work piece holding is another. Most of the time. Most of the time. No one can just wave a magic wand and grant you experience. Running the First Part Depending on the policy of the company you work for. both external and internal before finishing both the external and internal surfaces. start with a recommendation from a lead man or machine manual. threading. Using the part print as your map. It is too often that programs are rushed to be written and then rushed to be run without checking for mistakes. 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.

there are no errors and all of the cuts appear to go where they need to. MCAR August 2014 52 . speed and feed adjustments can be made and also any offset adjustments to bring the part into tolerance. He/she will explain which tools to use. Once the first part is run. If there is time. 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 be able to write several programs and then run them on the machines. 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. creating a part. You will then take your program out to the machine and run it.