Using GCAM for GCode 1

CNC machines run using GCode, which is a set of instructions which tell the CNC machine what to do. You can write GCode by hand, but normally you use a CAD/CAM program which generates GCode. The very term CAD/CAM brings to mind software packages costing tens of thousands of dollars. Today, CAD/CAM programs are still out of the range of most hobbyists, but since I'm interested in fairly simple shapes, I don't need a big expensive program.

After some searching and evaluating various applications, and getting all frowny at all of them, I found gcam. This program is effectively a GCode editor for XWindows, which means Linux, OSX, and for Windows, cygwin-x11. There isn't a lot of documentation for it, so I'll try to write down the steps I took for a sample part, which is the wall piece for the Babbage-Boole Engine.

I have found gcam to crash occasionally, so save every time you make a change.

Starting up gcam reveals this:

To start, go to File > New Project:

The assumption is that we will start with a rectangular cuboid of material, and then mill out parts until we get what we need. I am going to mill from a bar of 1/2" x 1/4" steel, and let's say it is six inches long. In reality, I'm going to use longer pieces, and cut the bar to size by milling it. Now, the Z axis is the spindle axis: up and down. Looking down from the top, the X axis is left/right, while the Y axis is in/out. So I'm going to enter X=6, Y=0.25, and Z=0.5.

The material origin is going to be 0,0,0, where Z=0 is the top of the bar, and X=0,Y=0 is one of the corners.

I am using a 1/8" flat bottom end mill. There is also only one choice for Machine, so I'll use that.

The Traverse(Z) is the Z-plane where rapid moves above the part should happen. I'll keep that at 0.05". You can always change these settings later in Edit > Project Settings.

I hit Create Project and see the following window:

On the bottom right is the set of GCode instructions. All projects start with a BEGIN block, a TOOL block, and an END block. The TOOL block, which is highlighted, is a tool change, specifying what kind of tool is to be used, and various other parameters which can be seen on the left. Prompt tells whether you want the machine to pause while you change out the tool, Change X, Y, Z says where the machine should go for you to be able to change out the tool, End Mill tells what tool to use, and Feed Rate and Plunge Ratio are some tool parameters.

The top right window shows a view of the workpiece, which can be manipulated with the mouse. A scrolling three-button mouse works best here. The scroll wheel zooms in and out. Pressing the scroll wheel (or the middle mouse button) and moving the mouse will rotate the piece. Pressing the left button and moving will pan the piece.

The default view is from the top, and you can change this via the View menu.

If I zoom in, I can see a grid inside the workpiece. This is the 0.1" grid, so you can see that the workpiece is 0.25" in the Y direction. The brighter lines are the 1" grid. Zooming in even more will reveal the 0.01" grid.

The first thing I want to do is cut out a 1/4" x 1/4" x 1/4" piece on the end. To do this, I Insert > Sketch. In the parameters to the left, I select Pocket, which means this block is going to be milled out.

Opening the blocks, I see that the SKETCH has an EXTRUSION, and the EXTRUSION has a LINE. Selecting the EXTRUSION block gives me different parameters and a new view. We will see later what the Resolution parameter does. The Cut Side tells you what the path of the center of the tool is going to be relative to the path you draw. Inside means the tool will move inside the path, Outside means the tool will move outside the path, while Along mean the tool will move along the path, meaning that the center of the tool traces the path.

The view appears to show something that is 0.5" according to the grid. This view appears to be the workpiece viewed from the front, so it is 0.5" inches in Z and extends out in X.

Moving to the LINE block inside the EXTRUSION, this is the depth of the shape into the material. We see that there is a red line with two yellow endpoints, and we see the parameters for P0 (endpoint 0) and P1 (endpoint 1). You might be confused by the fact that the endpoints have X and Y coordinates. In fact, these are X and Z coordinates! The first endpoint is at 0,0 while the second endpoint is at 0,-0.5. Although it is hard to see since the view cannot be changed, the red line is actually brighter in the direction of the path. You can see this by using Edit > Flip Direction. Make sure the direction is going into the material. It would be very strange to mill out the material starting from the bottom!

The Length and Angle are automatically calculated for you from P0 and P1, or you can enter P0 and change Length and Angle and P1 will be automatically calculated.

Since I only want to go 1/4" deep, I will set the Length to 0.25.

Next, I select the SKETCH block and Insert > Line. This is what the shape to cut out will look like from the top, and this time the X and Y coordinates are appropos. Starting from 0,0, I want the line to go 0.25" (not 1", which is the length of the line by default). So I change the length to 0.25:

Since I want a 1/4" x 1/4" square, I insert another line:

The line automatically starts from the previous endpoint, in the same direction, with length 1", but I want this line to go up by 1/4". So I first change P1(Y) to 0.25" (if I change P1(X) first, the length becomes zero, and gcam rejects lines of length 0) and P1(X) to 0.25":

Similarly, I add two more lines to complete my 1/4" x 1/4" square in the X-Y plane:

If I go back and select the SKETCH block, I can see an orange square tracing out my desired 1/4" x 1/4" path. But if I rotate the view, I can see a series of five squares cutting into the workpiece. In fact, this is what the resolution parameter in the EXTRUSION block specifies: the depth of each pass. The resolution was 0.05", so for a 0.25"-deep cut, this means five passes.

Now let me go to Render > Final Part to see what the result looks like:

Oh no! What happened? The problem is that we specified Inside for the EXTRUSION cut side, which means that the tool can't cut out the corners. But if I change to Along, I get this:

And if I change to Outside, I get this:

So what should I do? Well, clearly I need an Inside cut, otherwise I don't get the material inside the shape removed. But I need to adjust my path so that the tool extends past the outside of the workpiece. So I change my first line to start at -0.1, -0.1 and end at 0.25, -0.1:

Similarly, I change the other three lines so that they extend past the outside of the workpiece by 0.1". The mill is 0.125" in diameter, so really I just need 0.0625", but I'll use 0.1" to be certain.

And the result:

Success! Obviously because the tool will pass outside the bounds of the workpiece, I need to make sure the workpiece is clamped so that the mill doesn't mill out the clamp!

To sum up:

SKETCH lets you extrude a shape in the X-Y plane into the Z plane, and the Pocket parameter of SKETCH says that we will mill out a pocket. The Resolution of the EXTRUSION tells you how many passes into the Z plane will be made. The Cut Side of the EXTRUSION tells you what kind of shape will be cut out.

The LINE of the EXTRUSION indicates how deep the shape will be cut into the Z plane, while the LINEs of the SKETCH draw out the shape to extrude in the X-Y plane.

For fun, we can output the GCode using File > Export GCode. The export format should be compatible with your CNC controlling software. At this point I'm not certain what Mach3 accepts, so I'll choose EMC even though I'm not using EMC. The result is a 265-line GCode file. Note that the free version of Mach3 will only accept up to 500 lines, so I am already near this limit for a simple cut-out.

Next post, I'll see how this sample actually works with Mach3, milling the piece out using a sacrificial piece of wood. I'll also see how to do holes.