Programming a Drilling Cycle with the G81 G-Code

February 21, 2019 2:44 pm

 

 

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

 

Categories:

Leave a Reply