Programming a Drilling Cycle with the G81 G-Code
As machinists, we are starting to lean on our CAD/CAM software to take care of even the simplest operations.
Often it’s quicker and easier to write the G-Code manually.
A good example of an operation that can be written directly with G-Code is the drilling cycle, so let’s dive in and look at how we can use the G81 drilling cycle on a CNC mill.
Using G81
G81 is the standard drilling cycle that produces our holes with just a few lines of code. A typical G81 line would look something like this:
G81 X50.0 Y30.0 Z-10.0 R1.0 F50.0:
The ‘X’ and ‘Y’ coordinates are the position of the first hole in relation to the datum.
The ‘Z’, in this case, defines the depth of the hole that we wish to produce, the ‘R’ is the retract value, the distance above the working plane that the drill will return to once the hole has been drilled and ‘F’ is our feed rate. The feed rate is dependent on the material that is being cut and the type of drill that you are using.
The lines of code that follow will tell the machine the positions of the other holes that you will be drilling. This measurement is an incremental move that states the distance from the center line of the hole that you just produced to your next hole.
For example:
X20.0;
X10.0 Y15.0;
This will produce the second hole 20mm along the X-axis from the first hole. Once the depth has been achieved, it will retract above the part and rapid transverse to the position of the third hole and drill that to a depth of 10mm.
If the holes are at different depths you can add a ‘Z’ move on these lines:
X20.0 Z-5.0:
X10.0 Y15.0 Z-8.0:
Once all the holes have been produced, you need to cancel the drilling cycle by using a G80 command.
Your program will now look like this:
G81 X50.0 Y30.0 Z-10.0 R1.0 F50.0;
X20.0 Z-5.0;
X10.0 Y15.0 Z-8.0;
G80;
What if you have obstacles in the path of your drill?
For obstacle avoidance, you can add a few more G-Codes to your block of code.
If you define a ‘Z’ height before our G81 command, you can recall that position as well as the retract value ‘R’ when needed within your cycle. It would look something like this:
G00 Z50.0;
G81 G99 X50.0 Y30.0 Z-10.0 R1.0 F50.0;
G98 X20.0 Z-5.0;
G99 X10.0 Y15.0 Z-8.0;
G80;
Note the added G98 and G99 G-Codes to your program.
The G99 command tells the control to retract the drill to your ‘R’ retract value once the hole has been produced.
While the G98 command will retract to the previous safe ‘Z’ distance that we moved to with the G00 rapid movement command.
For a deeper look into this technique, read “G98 and G99 G-Codes“.
The above examples describe the cycle that will sit within your block of code that would look something like this (depending on the version of FANUC that the machine controls are running):
N1 T0101 (10MM DRILL);
M06 (TOOL CHANGE);
G90 G53 G21 G17 (SAFETY LINE);
S1000 M03 (SETS SPINDLE SPEED AND TURNS ON THE SPINDLE);
G00 Z50.0 M08 (SAFE RAPID DISTANCE COOLANT ON);
G81 G99 X50.0 Y30.0 Z-10.0 R1.0 F50.0 (START OF THE DRILLING CYCLE);
G98 X20.0 Z-5.0;
G99 X10.0 Y15.0 Z-8.0;
G80 (CYCLE CANCEL);
G00 Z100.0 M09 (SAFE RAPID DISTANCE COOLANT OFF);
G53 X0.0 Y0.0 Z0.0 M05 (MOVE TO HOME POSITION AND SPINDLE OFF);
M01 (OPTIONAL STOP);
With just a few lines of G-Code, you can drill a series of holes on the CNC machine much quicker than it would take you if you fired up your CAD/CAM software.
Author: Marc Cronin, Senior CNC Machine Tools Engineer, and founder of GCodeTutor.com
LEARN MORE ABOUT GCODETUTOR.COM
4 Comments
When someone writes an paragraph he/she keeps the plan of a
user in his/her brain that how a user can be aware of it.
Therefore that’s why this paragraph is perfect. Thanks!
X20.0;
X10.0 Y15.0;
This will produce the second hole 20mm along the X-axis from the first hole.
*NOTE: The second hole will still be in reference to the datum. So, in your example, the second hole would be at X20.0 Y30.0, from datum, since Y did not change. Not at X30.0 Y30.0, from datum, which would be a +20.0mm incremental move from the last hole.
The only time the holes are incrementally distanced (distance apart) is if there is a G91 in your program. If a G90 is used all of your hole cycle points will be in absolute coordinates from the called work offset. I’m only mentioning this because when I read it I took it as they are always incrementally spaced. G90 and G91 make a huge difference in programming, especially if you are using work offsets and not the machine zero position(G53). Don’t forget if you add a rapid command in the canned cycle it will cancel the cycle. I do agree with the lesson here though, it is faster to just write a canned cycle than using cadcam because the post processor will spit out every point as a new canned cycle, unless you are on the same plane or work offset.
I programmed like that for years.
I came up with a different way.
It was the safety line and drill cycle that gave me the problem.
I made use of sub programs
for the home cycle (G28G91ZO)
Tool change (T1M6) cycle and drilling info (G81, G83, G84,F,S,Q…..etc)
in a sub program.
For example a call up of M98 P4421
called up a .421 tap drill for 1/2 -13.
All required was editing rpm feed and Q values.
Add L0 to not drill it here and M99 to return to the base program.
These subs were stored in the control
for drill cycles.
Taps were 5000 series.
P5500 was a 1/2-13 tap and P5501 was 1/2-20 thread.
After the tool call up came the coordinate list sub program
M98P…….followed by G80 and M99
in that sub.
I haven’t programmed that way for 20
years so no flaming allowed.
Work out the issues for your control
yourself.
Kap