Hand Written GCode for CNC

Use the source, Luke.

Sometimes it's a good idea to just go straight to GCode for cutting out simple objects. Profile cuts and minor decorations cut out more quickly and cleanly this way. But the complexity can build up fast, making it ever more difficult.


 

Bypassing Brute Force

Results of my first GCode program.

The Trouble with CAM

The first problem with CAM programs is that they're usually an extra expense that comes right on top of paying for your CNC machine, spindles, bits, and all the other hardware components. The second is that they tend to apply more brute force to solving carving problems than intelligence, especially at the low end of the CAM market. That means longer times spent at the CNC, waiting on it doing a finishing cut with a raster-scan across the carving's surface, than is often necessary. Further, if you're using a machine with an A axis (computer controlled rotary indexer), then your CAM program may not support it.

Taking Matters into Your Own Hands

Writing GCode is not especially hard if you have programming experience of any kind, even in a scripting language. It's commands are terse, but easily learned and understood. The image above, of "Saundby" surrounded by a key pattern, is the result of my very first GCode program.

Writing your own GCode programs takes two things: an understanding of what gcode your CNC control program will accept, and a design for you to follow when writing that code. Different CNC control programs use variations in the language itself, or require different setup commands. There is a body of fairly generic commands for movement control for basic 3D machines (X,Y,Z axis movement). You can type the code into any editor that will save a plain text file (no formatting commands embedded in the file, just what you type.) My control program, EMC2, can edit GCode directly. I have a second computer in my office that will boot into the EMC2 Linux environment just so that I can edit and check my GCode without going into the shop. I'll be moving that to a virtual machine when time allows, to make it even simpler.

profile-cut component created using hand-written gcode
Profile-Cut Component Made Using Hand-Written GCode.

Profile Cuts

When you want to make an object that takes advantage of the mill cuts on stock, or is cut from a piece that has already been surfaced and milled to size, GCode lets you do it directly and more rapidly on the CNC than a low-cost CAM solution (there is software that does this, very nicely, but the ones I'm aware of are more expensive than the low end software solutions for CAM). THe above piece is a component from a simple two piece project for a decorative spoon holder. It was cut in profile only to get the decorative shape that includes recesses for the spoon handles to rest in. The screw holes in the stock were not included in the final piece, this was a test piece cut in MDF. The final pieces were cut in hardwood stock that was cut long, supported during machining in the extra length, which was cut off by hand after machining to leave a nice finished piece.

With hand-written GCode, the machining time was only what it took for the router head to make 3 passes on this piece. In the final pieces, which used thinner stock, there were only two passes, only a few minutes to complete each piece.

Surfacing and Other Utility Cuts

Similarly, you can have programs that you use for surfacing standard stock sizes, planing to size, standard embossing cuts and motifs, etc. I have a number of programs that I use for preparing standard pieces of softwood for use. I use softwood for a lot of projects, as well as it's cheaper than hardwood for test cuts on projects that will end up in hardwood in the final piece. While I do a lot of proofing with MDF, it doesn't have a grain, and softwood does.

Built from Pieces

a decorative spoon rack created using hand-written gcode
Motifs Being Proofed with Different Parameters.

Using your own GCode programs gives you another ability, too. You can use your own programs as components in building up more complex programs that employ those pieces. Above are a pair of motifs I designed using GCode. These were test cuts made while I was working out the depths at which each section of the motif would be cut. In fact, they were all part of one program, which used different parameters for each motif so that I could see what they looked like when cut into some MDF as proofs. Later I cut out the parts of the code I like and pasted it into the code that cut the back panel of the spoon rack project. That code, as well as the code for the carvings above, can be cut and pasted into any future project I create.

a decorative spoon rack created using hand-written gcode
A Decorative Spoon Rack Made Using Hand-Written GCode.

Complications

Coding GCode by hand has its downsides. You can't do anything as complex as a thousands-plus polygon 3D model by hand--at least not without being really good at math and willing to dedicate a lot of time to it. Calculating tool offsets gets to be a pain after you reach a certain level of complexity. But it really shines on simple stuff that involves quick or simple cuts, where it gets results so much faster than a conventional two pass CAM program. It shouldn't be your only tool, but it should definitely be in your toolbox.