Custom Macros Can Skip Holes After Replacing Broken Tools
Using “vacant” local variables enables CNC machinists to create custom macros that can target multiple types of machining work.
Some programmers shy away from using custom macros because they feel these macros make it more difficult to restart a program from the middle of a complex machining operation. This concern can often be overcome with a little planning. Indeed, custom macros sometimes make it easier to restart the program and run from the middle of a cutting tool’s machining operation.
The technique in this article was inspired by Chad Kluth of Mid Valley Industries in Kaukuana, Wisconsin. I was helping him resolve a different issue in a bolt-circle hole-machining custom macro. I include it here since it is relevant to our discussion.
Kluth’s application involved machining very large and tough 4140 steel components used in the mining industry. He needed to drill as many as 100 holes, each 2 inches in diameter, around a bolt-circle pattern into a round face/flange to a 6-inch depth. As you can imagine, tool wear and tool breakage are big issues. Even a drill with new inserts may not make it all the way through the cycle without wearing out — and the drill could be 90 holes into the cycle when it does wear out. To make matters worse, a hard inclusion in the raw material could cause the drill to break at any time.
Kluth uses a universal bolt-circle custom macro capable of performing several kinds of hole-machining operations, including drilling, standard tapping, rigid tapping, reaming and counterboring. The original issue had to do with rigid tapping. Being a “universal” custom macro, the M29 command needed to ignore rigid tapping if the machine was performing any other operation. To solve this issue, we used “vacant” local variables.
As for skipping holes, an argument in the calling command specifies the number of holes to skip. For example, if the drill wears out during the 90th hole, the user needs to set this argument to 89. We used the K-word (L-word with older FANUC CNCs) in the canned cycle command to specify whether the machine should skip a hole. If K is set to zero (K0), the hole is skipped. If K is set to one (K1), the hole is machined.
Here is a sample program containing an example calling command:
- N005 G90 S500 M03
- N010 G00 X0 Y0
- N015 G43 H01 Z0.1
- N020 G65 P9010 X0 Y0 Z0 C81.0 D6.0 R0.1 B12.0 A90.0 I100.0 F12.0 H89.0
- N025 G91 G28 Z0
- N030 M30
These are the mandatory arguments that must be in the calling command:
- (X = X center)
- (Y = Y center)
- (Z = Z surface)
- (D = Hole depth)
- (C = Cycle to use — G81, G82, G83, G73 or G84)
- (R = Z rapid position)
- (B = Radius of bolt circle)
- (A = Start angle)
- (I = Number of holes)
- (F = Feed rate)
These are the arguments that are only required in special cases:
- (T = Needed with G82 to specify dwell time)
- (Q = Needed with G73 or G83 to specify peck depth)
- (M29.0 = Needed if rigid tapping)
- (Sxxxx.x = Needed if rigid tapping to specify spindle RPM)
- (H = Needed if skipping holes to specify the number of holes to skip)
Here is the custom macro:
- O9010 (Universal bolt-circle custom macro)
- #101=1 (Initialize counter)
- #102=#1 (Initialize current angle to A)
- #103=360 / #4 (Incremental angular distance between holes)
- #104=#26 + 0.1 (Rapid approach plane)
- #105=#26 - #7 (Z bottom position of hole)
- #32=1 (Skip-hole counter — used if H is included in calling command)
- N1 IF[#101 GT #4] GOTO 99 (Test if finished machining holes)
- #110=#24 + COS[#102] * #2 (X position for current hole)
- #111=#25 + SIN[#102] * #2 (Y position for current hole)
- #33=1 (K word value, set to 1 in case next hole will be machined)
- IF[#11EQ#0] GOTO5 (Test if H is included in the calling command)
- IF[#32GT#11] GOTO5 (Test if finished skipping holes)
- #33=0 (Next hole will be skipped)
- N5 M#13 S#19 (Not executed if #13 and #19 are vacant)
- G#3 X#110 Y#111 R#104 Z#105 P#20 Q#17 F#9 K#33 (Machine current hole)
- G80 (Cancel cycle)
- #101=#101 + 1 (Step counter)
- #102=#102 + #103 (Step current angle)
- #32=#32+1 (Step skip-hole counter)
- GOTO 1 (Go back to test)
- N99 M99 (End)
Here is a guide to the bolded items in the custom macro:
- M#13 S#19 – If a CNC word contains a vacant local variable, the CNC will ignore the word. When performing rigid tapping, the calling command must include the words M29.0 and Sxxxx.0 (S specifies the RPM for rigid tapping). If doing some other operation, users must leave M and S out of the calling command.
- P#20 and Q#17 – If the user is using counterboring (G82), they must include T in the calling command to specify dwell time. When peck drilling (G73 or G83), users must include Q to specify peck depth.
- K#33 – FANUC has two programming formats for canned cycles. With newer FANUC CNCs, K specifies the number of holes being machined. Older FANUC CNCs use L for the same purpose. If this custom macro does not work (the machine is not skipping holes even if H is included in the calling command), change the K#33 in this command to L#33.
Parameters tell the CNC every little detail about the specific machine tool being used, and how all CNC features and functions are to be utilized.
For the most part, CNC controls will follow the instructions given in a program to the letter. With the exception of basic syntax (program formatting) mistakes, the CNC control will rarely be able to tell if a mistake has been made.
While the mistakes listed here will not sound an alarm or cause a program to fail, they will cause confusion, wasted time and scrap parts.