Programs to write G-Code (RS-274D)

I have written several small programs to create fairly optimal, yet general, G-Code toolpaths for commonly used machining operations. All these programs assume 3-axis motion control, and the minimum set of G-Code commands, such as linear and circular interpolation with G01, G02 and G03 commands.

Newer programs for making G-code:

Program to rigid-tap a list of coordinates in a file.

Program to drill a circular array of holes.

Program to peck-drill a circular array of holes.

Program to make a round pocket.

Program to trepan a round pocket.

Program to drill a rectangular array of holes.

Program to machine a rectangular pocket.

Program to machine the OD of a round post.

Program to machine a outside of a rectangular post.

Program to make spotting, drilling and rigid tapping programs from a file list of XY coordinates.

Program to trepan a circular cutout with ramp down in Z.

Program to trepan a rectangular cutout with ramp down in Z.

Program to mill internal threads with a single-row thread mill.

Program to machine a oval (race track) hole.

All of these programs need to be compiled with a c compiler. On a Linux system with the compiler installed, create a file "compile" with this in it :

cc $1.c -o $1 -lm

make this file executable with :

chmod u+x compile

then compile these programs like this :

./compile filetap

Older programs for making G-code (kept for historical purposes):

Boring Holes

One of the first things I wanted to do was to bore circular holes in things. Whether you call these pockets or bored holes doesn't matter much. All the moves are made as climb milling passes, spiraling out from the center in quadrants of increasing radius, until the cutter has reached the finish pass allowance. It then plunges deeper, and repeats, until the full depth has been reached. On the last depth pass, the cutter spirals out further, completing the finish pass. it then returns to the hole center and retracts. A screen copy of user's input to the program.
These commands put a 1/2" hole at location X=1, Y=2", using a 1/8" end mill. The roughing feed rate is 10 IPM, and the roughing cut width is .050". The finish feedrate is 5 IPM, and the allowance for the finishing pass is .010". The passes will have a depth of cut of .050", and the final pass will be at a depth of .1". The results of this run will be put into a file called mb.dat, which is shown below. The Z axis is set such that Z=0 puts the tool on the top surface of the work. I usually use a piece of paper of known thickness, jog the tool down until the stationary tool just binds the paper, and then set the Z axis to read the thickness of the paper.
N10 G01 F10.000 X1.0000 Y2.0000
N20 F1.667 Z-0.0500
N30 F10.000 X1.0125
N40 G03 X1.0000 Y2.0125 R0.0125
N50 X0.9750 Y2.0000 R0.0156
N60 X1.0000 Y1.9625 R0.0271
N70 X1.0500 Y2.0000 R0.0391
N80 X1.0000 Y2.0625 R0.0513
N90 X0.9250 Y2.0000 R0.0635
N100 X1.0000 Y1.9125 R0.0759
N110 X1.1000 Y2.0000 R0.0883
N120 X1.0000 Y2.1125 R0.1007
N130 X0.8750 Y2.0000 R0.1131
N140 X1.0000 Y1.8625 R0.1256
N150 X1.1500 Y2.0000 R0.1380
N160 X1.0000 Y2.1625 R0.1505
N170 X0.8250 Y2.0000 R0.1629
N180 X1.0000 Y1.8125 R0.1754
N190 X1.1775 Y2.0000 R0.1775
N200 X1.0000 Y2.1775 R0.1775
N210 X0.8225 Y2.0000 R0.1775
N220 X1.0000 Y1.8225 R0.1775
N230 X1.1775 Y2.0000 R0.1775
N240 G01 F10.000 X1.0000 Y2.0000
N250 F1.667 Z-0.1000
(Continuation of program)
N260 F10.000 X1.0125
N270 G03 X1.0000 Y2.0125 R0.0125
N280 X0.9750 Y2.0000 R0.0156
N290 X1.0000 Y1.9625 R0.0271
N300 X1.0500 Y2.0000 R0.0391
N310 X1.0000 Y2.0625 R0.0513
N320 X0.9250 Y2.0000 R0.0635
N330 X1.0000 Y1.9125 R0.0759
N340 X1.1000 Y2.0000 R0.0883
N350 X1.0000 Y2.1125 R0.1007
N360 X0.8750 Y2.0000 R0.1131
N370 X1.0000 Y1.8625 R0.1256
N380 X1.1500 Y2.0000 R0.1380
N390 X1.0000 Y2.1625 R0.1505
N400 X0.8250 Y2.0000 R0.1629
N410 X1.0000 Y1.8125 R0.1754
N420 F5.000 X1.1875 Y2.0000 R0.1875
X1.0000 Y2.1875 R0.1875
X0.8125 Y2.0000 R0.1875
X1.0000 Y1.8125 R0.1875
X1.1875 Y2.0000 R0.1875
N430 G01 X1.0000Y2.0000
N440 G01 F50 Z0.1
N450 M02

These programs should be able to be compiled on Linux with Gcc, PC-DOS with Microsoft C, or Windows with Borland C. IF you have problems compiling them, let me know, and I'll see if we can solve the problem.

Download program makebore.c source or Download DOS Executable makebore.exe

Download program for arcs with I,J words or Download DOS Executable makebore with I,J words

Milling a Rectangular Pocket

This program mills out a rectangular pocket in the material. If you are making the pocket go all the way through a thin sheet, you can use treprect, which doesn't waste time cutting the entire interior, it just cuts around the perimeter. This program figures out which axis has the longer travel, and then starts by cutting down the center of the pocket in that direction. It then 'spirals' out from there, by climb milling. It repeats this process at each depth until at the final depth, where it completes the pocket out to the finish dimensions. A screen copy of user's input to the program.
These commands put a 3 x 4" pocket with the lower left corner at location X=1, Y=2", using a 1/2" end mill. therefore, the upper right corner would be at X=4, Y=6. The remaining parameters are similar to the program above.
N10 G01 F40.0 X2.5000 Y2.2750
N20 Z0.0200 F40
N30 Z-0.1000 F2.0
N40 Y5.7250 F5.0
N50 X2.2500 F10.0
N60 Y2.2750
N70 X2.7500
N80 Y5.7250
N90 X2.0000 F10.0
N100 Y2.2750
N110 X3.0000
N120 Y5.7250
N130 X1.7500 F10.0
N140 Y2.2750
N150 X3.2500
N160 Y5.7250
N170 X1.5000 F10.0
N180 Y2.2750
N190 X3.5000
N200 Y5.7250
N210 X1.2750 F10.0
N220 Y2.2750
N230 X3.7250
N240 Y5.7250
N250 X2.5000 F40.0
N260 Y2.2750
N270 Z-0.2000 F2.0
N280 Y5.7250 F5.0
N290 X2.2500 F10.0
(Continuation of program)
N300 Y2.2750
N310 X2.7500
N320 Y5.7250
N330 X2.0000 F10.0
N340 Y2.2750
N350 X3.0000
N360 Y5.7250
N370 X1.7500 F10.0
N380 Y2.2750
N390 X3.2500
N400 Y5.7250
N410 X1.5000 F10.0
N420 Y2.2750
N430 X3.5000
N440 Y5.7250
N450 X1.2750 F10.0
N460 Y2.2750
N470 X3.7250
N480 Y5.7250
N490 X2.5000 F40.0
N500 Y2.2750
N510 F5.0 Y2.2563
N520 Y2.2500 X3.7500
N530 Y5.7500
N540 X1.2500
N550 Y2.2500
N560 X3.7500
N570 Z0.1000
N580 M02

Download program rectpocket.c OR Download DOS Executabe rectpocket.exe

Milling a Rectangular Cutout

This program mills a rectangular cutout all the way through the material. It makes a complete path such that the cutter leaves a finish allowance on the inside of the desired dimensions, and then pauses to allows you to remove the 'blank' form the hole. You then resume the program and the cutout is brought up to the desired dimension. A screen copy of user's input to the program.
These commands put a 3 x 4" cutout with the lower left corner at location X=1, Y=2", using a 1/8" end mill. therefore, the upper right corner would be at X=4, Y=6. The remaining parameters are similar to the program above.
N10 G01 F5.0 X1.0725 Y2.0725
N20 Z-0.0500
N30 X3.9275
N40 Y5.9275
N50 X1.0725
N60 Y2.0725
N70 Z-0.1000
N80 X3.9275
N90 Y5.9275
N100 X1.0725
N110 Y2.0725
N120 F3.0 X1.0650
N130 X1.0625 Y2.0625
N140  M01 (Remove blank)
N150 X3.9375
N160 Y5.9375
N170 X1.0625
N180 Y2.0625
N190 Z0.1000
N200 M02

Download program treprect.c OR Download DOS Executable treprect.exe

Here's a variation on this program to ramp down while cutting the outline of the pocket. Download program treprectramp.c OR

Drilling a Circular Pattern of Holes

This program drills holes in a circular pattern. It can do the first n of a pattern of m holes (ie. first 5 out of 6). The first hole is always at Y=Ycent+radius, X=center. If you want to omit specific holes, it is easy to edit them out of the generated G-code file. A screen copy of user's input to the program.
These commands put a the first (counting counterclockwise) 4 holes of a pattern of 5 evenly spaced holes on a hole circle of 2.5" diameter, centered at the coordinates (1,1). The holes are drilled to a depth of .5".
N10 G01 F30 X1.0000 Y2.2500
N20 F10.00 Z-0.5000
N30 F30 Z0.1000
N40 G01 F30 X2.1888 Y1.3863
N50 F10.00 Z-0.5000
N60 F30 Z0.1000
N70 G01 F30 X1.7347 Y-0.0113
N80 F10.00 Z-0.5000
N90 F30 Z0.1000
N100 G01 F30 X0.2653 Y-0.0113
N110 F10.00 Z-0.5000
N120 F30 Z0.1000
N130 F30 X1.0000 Y1.0000
N140 M02

Download program holecircle.c OR Download DOS Executable holecircle.exe

Pecking a Circular Pattern of Holes

This program drills holes in a circular pattern, as above, but using a peck drilling cycle. A screen copy of user's input to the program.
These commands put 4 holes on a 1" hole circle centered around the coordinate (0,0). The holes are drilled .5" deep, with 2 pecks of .25" each.
N10 G01 F30 X0.0000 Y0.5000
N20 F50.00 Z 0.0100
N30 F10.00 Z-0.2500
N40 F50.00 Z0
N50 F50.00 Z -0.2400
N60 F10.00 Z-0.5000
N70 F50.00 Z0
N80 F30 Z  0.1000
N90 G01 F30 X0.5000 Y-0.0000
N100 F50.00 Z 0.0100
N110 F10.00 Z-0.2500
N120 F50.00 Z0
N130 F50.00 Z -0.2400
N140 F10.00 Z-0.5000
N150 F50.00 Z0
N160 F30 Z  0.1000
N170 G01 F30 X-0.0000 Y-0.5000
(Continuation of program)
N180 F50.00 Z 0.0100
N190 F10.00 Z-0.2500
N200 F50.00 Z0
N210 F50.00 Z -0.2400
N220 F10.00 Z-0.5000
N230 F50.00 Z0
N240 F30 Z  0.1000
N250 G01 F30 X-0.5000 Y0.0000
N260 F50.00 Z 0.0100
N270 F10.00 Z-0.2500
N280 F50.00 Z0
N290 F50.00 Z -0.2400
N300 F10.00 Z-0.5000
N310 F50.00 Z0
N320 F30 Z  0.1000
N330 F30 X0.0000 Y0.0000
N340 M02

Download program peckcircle.c OR Download DOS Executable peckcircle.exe

Thread Milling

This program mills threads into a hole that has already been drilled. It is designed for use with single-row thread mills, which have the advantage that they can make threads with a wide pitch range. The disadvantage is they only mill one turn of the thread at a time. (This program will actually work with standard thread mills, too, you just specify a depth equal to a little more than one turn.) A screen copy of user's input to the program.
These values select a thread of 1/2" diameter, 13 threads/inch, with a threaded length of 1/2". The center of the hole is at (1,1). Note that because climb milling was selected, a right-hand cutting tool must orbit counterclockwise, so a right-hand thread requires that the thread be milled from the bottom up!
N10 G01 G17 G90 F30 X1.0000 Y1.0000
N20 Z-0.5000
N30 F5.000 X1.1250
N40 G03 X0.8750 I-0.1250 Z  -0.4615
N50 G03 X1.1250 I0.1250 Z  -0.4231
N60 G03 X0.8750 I-0.1250 Z  -0.3846
N70 G03 X1.1250 I0.1250 Z  -0.3462
N80 G03 X0.8750 I-0.1250 Z  -0.3077
N90 G03 X1.1250 I0.1250 Z -0.2692
N100 G03 X0.8750 I-0.1250 Z  -0.2308
N110 G03 X1.1250 I0.1250 Z  -0.1923
N120 G03 X0.8750 I-0.1250 Z  -0.1538
N130 G03 X1.1250 I0.1250 Z  -0.1154
N140 G03 X0.8750 I-0.1250 Z  -0.0769
N150 G03 X1.1250 I0.1250 Z  -0.0385
N160 G03 X0.8750 I-0.1250 Z-0.0000
N170 G03 X1.1250 I0.1250 Z  0.0385
N180 G01 X1.0000 Y1.0000
N190 G01 F50 Z0.1
N200 M02

Download program threadmill.c OR Download DOS Executable threadmill.exe

Make Ring

This program works very similarly to makebore, but instead of milling away from the center of the hole or pocket, it starts near the edge, and just mills away a little more than the width of the tool, making a finish pass on the OD. This is most useful for cutting large holes out of sheet material, as you don't waste time turning the blank into chips, but just let it drop out.

Download program makering.c OR Download DOS Executable makering.exe

Make Post

This program works very similarly to makering, but makes the finishing pass toward the center, thereby leaving a round post at the center coords. The operation should be obvious, as it is very like the previous programs.

Download program makepost.c OR Download DOS Executable makepost.exe