Programming a CNC lathe to peck-drill.
Drilling holes can be tough work. Problems with chip control, poor tool life and coolant starvation are but a few of the holemaking obstacles machinists face every day. To make things even harder, controls sometime present another hurdle that must be overcome: programming.
Fanuc and Fanuc-compatible controls offer many programming features that make life easier. But sometimes pecking cycles aren’t present or don’t work as desired.
Assume for a minute that you need to make a part with a 1/4"-dia., 2"-deep hole. It’s the programmer’s day off, so you find yourself standing in front of a CNC lathe, scratching your head. Where do you begin? If your machine uses G and M codes, you could program the following:
N1 G97 M3 S1000 T101
G0 X0 Z.1
G1 Z-2. F.005
G0 Z.3
G28 U0 W0
M30
This bare-bones program will start the spindle at 1,000 rpm, index the turret to tool station 1, then rapid to the centerline of the part and start drilling.
Now, if you’re drilling Styrofoam, this program would work fine. But if you’re drilling a real-world material like steel or aluminum, your drill will probably snap off somewhere deep in the workpiece. Drilling holes that are more than 4 or 5 diameters deep usually requires pecking—a periodic retraction of the drill. Pecking clears the chip and allows cutting fluid to enter the hole.
Going back to our example of the 2"-deep hole, if you decide to retract the drill every 1/4", you would need to modify the program like so:
N1 G97 M3 S1000 T101
G0 X0 Z.1
G1 Z-.25 F.005
G0 Z.1
Z-.23
G1 Z-.5
G0 Z.1
Z-.48
G1 Z-.75
G0 Z.1
Z-.73
G1 Z-1.
G0 Z.1
Z-.98
G1 Z-1.25
G0 Z.1
Z-1.23
G1 Z-1.5
G0 Z.1
Z-1.48
G1 Z-1.75
G0 Z.1
Z-1.73
G1 Z-2.
G0 Z.3
G28 U0 W0
M30
Obviously, manual programming can be a tedious job. Some deep holes could require you to keystroke dozens—maybe hundreds—of lines of code. Besides being labor-intensive and costly, manual programming can be dangerous because it increases the risk of human error. A missing decimal point or an incorrectly entered number could cause a terrific crash.
Worse, once a program has been proved out, what if you need to change the pecking interval? Tweaking a program to add or remove pecks can be difficult, because entire sections of code might need reworking.
Wait a minute, you say. Why not just sneak into the programmer’s office, fire up his or her PC and let the computer’s CAD/CAM software crank out all the necessary code? Although number crunching is one of the main functions of computers, tweaking a CAD/CAM-generated program presents some of the same obstacles as manual programming. It would require you to leave your machine, return to the computer and regenerate the entire program. Then, after doing that, you would have to download and prove out the program all over again. Too time-consuming, you decide.
So you decide it would be simpler to just change a value in the program—say, the depth of cut—and have the control figure the whole mess out for itself. You crack open the Fanuc manual, where you find a section entitled "Functions to Simplify Programming." You probably know these functions as "Canned Cycles" or "Multiple Repetitive Cycles." After studying the manual for a while, you try the one that seems most appropriate—G83. This is what you might key into the control:
N1 (G83 DRILL CYCLE)
G97 M3 S1000 T101
G0 X0 Z.1 M8
G83 Z-2. Q.25 R.1 F.005
G28 U0 W0
M30
According to the manual, this program will position the drill on center, 0.1" (the R-value) away from the face of the workpiece. It will then start drilling, pecking every .25" (the Q-value) until reaching the final depth of 2" (the Z-value).
After inputting the appropriate data, you push the cycle-start button and watch as the drill approaches the workpiece. It stops. The red light on the top of the machine starts flashing. The control then informs you that there is a P/S 010 program error.
Naturally, you think you must have made a programming mistake. But you would be wrong. Error 10 means "Improper G code," which, in this case, means that the option for the G83 drill cycle was not purchased with the machine. Now what?
If you were using the G83 cycle on a machining center instead of a lathe, you would probably be OK. Today’s machining centers come loaded with drill cycles, including G83. Unfortunately, G83 is typically found only on lathes that have live tooling—a feature that your lathe doesn’t have.
So what do you do now? Returning to your Fanuc manual, you find a drilling cycle called G74. The problem with G74—a high-speed pecking cycle—is that it breaks chips but doesn’t clear them. G74 works great if you’re running a through-coolant drill and want to break up long, stringy chips. However, if you need to retract the drill, you’re out of luck.
Subprogramming
One solution to the pecking problem is subprogramming. Creating a subprogram allows you to call up and execute a subroutine from your main program. This means you can do repetitive tasks, like drilling, with a minimum of programming. If your control has subprogramming capabilities, here’s a sample program you can use:
O0001 (MAIN PROGRAM)
N1 (1/2" DRILL)
G97 M3 S1000 T101
G0 X0 Z.1 M8
G1 Z0 F.01
M98 P81111
G0 Z.3
G28 U0 W0
M30
O1111 (DRILLING SUBPROGRAM)
G1 W-.25 F.005 (INCREMENTAL PECK AMOUNT)
G0 W2.5 (CLEARS CHIP – MUST BE GREATER THAN THE HOLE DEPTH)
W-2.45 (RAPIDS BACK IN WITHIN .05")
G1 W-.05 F.01 (FEEDS BACK TO STARTING POINT)
M99 (RETURN TO MAIN PROGRAM)
While not perfect, a subprogram sure beats generating dozens of lines of code by hand. Here’s how the above subprogram works: In the main program, the drill rapids to Z.1 then feeds to the starting point of Z0. Next, the control calls the subprogram—O1111—using an M98 P81111 command. The M98 tells the machine to call a subprogram. The P word (P81111) actually stands for two values. The last four digits (1111) are the subprogram number, and the first four digits (0008) are the number of times that the machine runs the program. (Since Fanuc controls ignore leading zeroes, the command reads "P81111.")
If you want to change the number of times the drill pecks while creating the hole, you will have to slightly modify your program. Let’s say that you want to peck 12 times instead of eight. You would have to alter the program to read "M98 P121111."
Because you would be pecking more often, you would also need to decrease the distance at which each peck occurs. To calculate the new pecking rate, divide the hole depth by the number of pecks and replace "W-.25" with the new value.
For our example, 2" divided by 12 pecks equals 0.166666666666666666667. Because most controls only carry out to four decimal places, our new command reads "G1 W-0.1667." This rounding error means you’ll overshoot the required 2" depth by 0.0004". But that’s no big deal.
Parametric Programming
A better alternative to subprogramming is parametric programming. Fanuc permits two types of parametric programming: Custom Macro A and Custom Macro B.
Macro A is the tedious yet powerful predecessor to Macro B. It has much of the same functionality as Macro B, but it is not nearly as straightforward. In this article, we’ll focus on Macro B.
There are many good reasons to use parametric programming, with the main one being that it permits "variables" to be entered into a program. Variables let you alter program code, perform mathematical calculations and change cutting parameters while a program is running. That flexibility, which is required for many difficult drilling applications, is not possible with G83.
One such application is the drilling of deep holes. It’s frequently helpful to decrease the pecking amount as hole depth increases. Macro B is good at this. Returning to our example, consider the following program:
N1 (MACRO DRILL CYCLE)
G97 M3 S1000 T101
G0 X0 Z.1 M8
#100= .25 (PECK AMOUNT)
#101=2. (DEPTH OF HOLE)
#102=.02 (RETURN AMOUNT)
#103=.1 (Z-START POSITION)
#104= #100 (SET TEMP Z EQUAL TO PECK VALUE)
#105= .005 (FEED RATE)
WHILE [#104 LT #101] DO 1 (LOOP WHILE TEMP Z-VALUE IS LESS THAN FINISH DEPTH)
G1 Z-#104 F#105 (FEED TO PECK DEPTH = VALUE OF #104)
G0 Z#103 (CLEAR CHIP - RAPID TO
RETRACT LOCATION)
Z –[#104-#102] (RAPID RETURN TO LAST
LOCATION LESS RETURN AMOUNT)
#104=#104+#100 (SET TEMP Z EQUAL TO TEMP Z PLUS PECK VALUE)
END 1 (END LOOP)
G1 Z-#101 (DRILL TO FINISH DEPTH)
G0 Z#103 (RAPID OUT TO RETRACT
LOCATION)
G28 U0 W0
M30
This macro program will do the same thing as the other programs mentioned. The difference is that if you wish to change the peck amount, you only need to change the value (.25) of the line that starts with #100. The control will then recalculate the pecks accordingly. The program will also retract the drill to a Z position equal to the value of #103, eliminating any wasted motion or overtravel.
The program, while obviously better than the subprogram technique illustrated earlier, is still a bit "kludgy." For one thing, if you have to do a lot of editing at the machine, getting the control to cough up some of the characters needed can be exasperating. Many of the characters are only producible by pressing the shift key, and all those "WHILE-DOs," equal signs and other mathematical symbols also can cause keystroke confusion.
A better alternative is to put the macro program into a subprogram like this:
O0001 (MAIN PROGRAM)
N4 G97 M3 S1000 T404
G0 X4. Z1.
G65 P9010 Z-2. D.25 R.1 F.005 K.02
G28 U0 W0
M30
O9010 (DRILL MACRO)
#100=#7(SET VARIABLE #100 EQUAL TO
D – PECK AMOUNT)
#101=ABS [#26] (SET VARIABLE #101 EQUAL TO Z - HOLE DEPTH)
#102=#6 (SET VARIABLE #102 EQUAL TO K – DRILL RETURN OFFSET)
#103=#18 (SET VARIABLE #103 EQUAL TO R – RETRACT LOCATION)
#104=#100 (TEMPORARILY SET VARIABLE #104 EQUAL TO PECK AMOUNT)
#105=#9 (SET VARIABLE #105 EQUAL TO F, FEED RATE)
WHILE [#104LT#101] DO1 (LOOP WHILE TEMP Z-VALUE IS LESS THAN FINISH DEPTH)
G1 Z-#104 F#105 (FEED TO PECK DEPTH = VALUE OF #104)
G0 Z#103 (CLEAR CHIP - RAPID TO RETRACT LOCATION)
Z- [#104-#102] (RAPID RETURN TO LAST LOCATION LESS K VALUE)
#104=#104+#100 (SET TEMP Z EQUAL TO TEMP Z PLUS PECK VALUE)
END1 (END LOOP)
G1 Z-#101 (DRILL TO FINISH DEPTH)
G0 Z#103 (RAPID OUT TO RETRACT LOCATION)
M99 (RETURN TO MAIN PROGRAM)
This closely resembles the subprogram call illustrated earlier, except that now the subroutine is called up with a G65 instead of an M98. Calling subprograms with a G65 allows you to "pass" variables to the subprogram. Variables make it easy to alter a program as cutting conditions require by simply changing the value of D, R, K, etc. It also makes it easy to use these macros for other jobs, as you can simply change a few values in the G65 macro call instead of rewriting the entire drilling routine.
A cleaner way to use this program would be to assign it a G code, like this:
O0001 (MAIN PROGRAM)
N4 G97 M3 S1000 T404
G0 X4. Z1.
G183 Z-1.5 D.35 R.07 F.012 K.02
G28 U0 W0
M30
This makes the macro program appear to be just like any other canned cycle in your machine. If you want to assign a G code to your macro programs, you will need to open the parameter manual for your control and find the specific parameter that maps the program number (usually a 9000-series program) to the G code.
In fact, as you may have already realized, there are few differences between a macro program and a canned cycle. But while canned cycles are fixed, macro programs give you the freedom to accomplish any programming task you desire. And that usually is a big plus when conducting drilling operations on a CNC lathe.
About the Author
Kip Hanson is general manager of Allen Co., Edina, Minn., and a frequent contributor to CTE.
Related Glossary Terms
- canned cycle ( fixed cycle)
canned cycle ( fixed cycle)
Subroutine or full set of programmed NC or CNC steps initiated by a single command. Operations are done in a set order; the beginning condition is returned to when the cycle is completed. See CNC, computer numerical control; NC, numerical control.
- centers
centers
Cone-shaped pins that support a workpiece by one or two ends during machining. The centers fit into holes drilled in the workpiece ends. Centers that turn with the workpiece are called “live” centers; those that do not are called “dead” centers.
- computer numerical control ( CNC)
computer numerical control ( CNC)
Microprocessor-based controller dedicated to a machine tool that permits the creation or modification of parts. Programmed numerical control activates the machine’s servos and spindle drives and controls the various machining operations. See DNC, direct numerical control; NC, numerical control.
- coolant
coolant
Fluid that reduces temperature buildup at the tool/workpiece interface during machining. Normally takes the form of a liquid such as soluble or chemical mixtures (semisynthetic, synthetic) but can be pressurized air or other gas. Because of water’s ability to absorb great quantities of heat, it is widely used as a coolant and vehicle for various cutting compounds, with the water-to-compound ratio varying with the machining task. See cutting fluid; semisynthetic cutting fluid; soluble-oil cutting fluid; synthetic cutting fluid.
- cutting fluid
cutting fluid
Liquid used to improve workpiece machinability, enhance tool life, flush out chips and machining debris, and cool the workpiece and tool. Three basic types are: straight oils; soluble oils, which emulsify in water; and synthetic fluids, which are water-based chemical solutions having no oil. See coolant; semisynthetic cutting fluid; soluble-oil cutting fluid; synthetic cutting fluid.
- feed
feed
Rate of change of position of the tool as a whole, relative to the workpiece while cutting.
- lathe
lathe
Turning machine capable of sawing, milling, grinding, gear-cutting, drilling, reaming, boring, threading, facing, chamfering, grooving, knurling, spinning, parting, necking, taper-cutting, and cam- and eccentric-cutting, as well as step- and straight-turning. Comes in a variety of forms, ranging from manual to semiautomatic to fully automatic, with major types being engine lathes, turning and contouring lathes, turret lathes and numerical-control lathes. The engine lathe consists of a headstock and spindle, tailstock, bed, carriage (complete with apron) and cross slides. Features include gear- (speed) and feed-selector levers, toolpost, compound rest, lead screw and reversing lead screw, threading dial and rapid-traverse lever. Special lathe types include through-the-spindle, camshaft and crankshaft, brake drum and rotor, spinning and gun-barrel machines. Toolroom and bench lathes are used for precision work; the former for tool-and-die work and similar tasks, the latter for small workpieces (instruments, watches), normally without a power feed. Models are typically designated according to their “swing,” or the largest-diameter workpiece that can be rotated; bed length, or the distance between centers; and horsepower generated. See turning machine.
- machining center
machining center
CNC machine tool capable of drilling, reaming, tapping, milling and boring. Normally comes with an automatic toolchanger. See automatic toolchanger.
- overshoot
overshoot
Deviation from nominal path caused by momentum carried over from previous step, as when a tool is rapidly traversed a considerable distance to begin a cut. Usually applies to CNC machining and is prevented if the control has the appropriate look-ahead capability. See look-ahead; undershoot.