Arc Feeds

Just like the linear feeds discussion we had, we will need to cover some information before we jump in to write code to cut circles or arcs.  The first thing to discuss is the circle itself.

Arcs and Circles

circle info thumbThe first thing is to describe a circle.  According to merriam-webster.com a circle is a closed plane curve every point of which is equidistant from a fixed point within the curve.  From this we can deduce that an arc is a partial curve on a plane.  That is all well and good, but what about circles and arcs in terms of CNC and G-Code?  Take a study of the image to the left.  We start with a circle drawn in blue.  The circle can be described as being a point on a plane and a radius and diameter. This is how most circles are described when we encounter them on a drawing or when we draw something up in a CAD package.  There are a few more things to know about a circle in order to know enough to write G-Code to cut one.  Looking back at our image to the left, if a horizontal line is drawn through the circle passing through the center point and a vertical line drawn through the circle through the center point we have divided it into four sections or quadrants.  These quadrants are essentially the same as the quadrants you labeled in high school algebra when you were mapping equations on a Cartesian plane.  Here, simply call the center point of the circle the origin of the Cartesian plane.  The quadrants are numbered exactly the same.  The upper right is quadrant I, then working counter clockwise, Quadrant II, III and IV.  This concept is important because later we will have to calculate indexes based on the quadrant we are cutting in.

The next thing to observe is that the point at which the circle crosses quadrants is called the quadrant point.  These are kind of special as most simple cuts either start and/or end on one of these points.  Additionally the indexes are easily calculated for these points.  There are lots of other things to know about circles, but this is enough for what we are trying to do.

Arc Direction - Clockwise or Counter Clockwise

We have two choices when cutting arcs.  They can be cut in either a clockwise direction or counter clockwise direction.  Mathematically speaking, an arc going in the counter clockwise direction is moving in a positive direction and is a positive angle.  The reverse applies to an arc going in the clockwise direction.  It moves in a negative direction and is a negative angle.  Arc direction is controlled by G2 and G3.  A G2 command specifies an arc in the clockwise direction (CW) and the G3 command specifies that the arc will be in the counter clockwise direction (CCW).

What plane are we in?

When cutting arcs, the controller needs to know what plane are the arcs being cut in.  There are three possibilities for this, most often we will be cutting in the XY plane.  But you can also cut in the XZ plane and the YZ plane.  There are specific preparatory command that let the controller know which plane we are working in.  The command G17 selects the XY plane.  The G18 command selects the XZ plane and the G19 command selects the YZ plane.  So, if I am cutting a profile on my JGRO CNC Router that has rounded corners, I would select the G17 command to let the controller know that my arcs are being cut on the XY plane.

Describing the arc or circle

Now that we know what the commands are for selecting the plane and arc direction we need to describe from which point the arc begins and ends and the radius of the arc we are cutting.  This information allows the controller to calculate the path that it needs to run on to make the cut.  Selecting the starting point of the arc is easy.  It is the current location of the tool.  Let me clarify that a little.  If we are cutting a piece of material and we want rounded corners, we would start by making a linear cut using something like G1 X2 Y2 and then start our rounded corner.  Well the starting point of our arc will be the last position the cutter was in, in this case X2 Y2.  To find the end point we look at our drawing and determine what that will be.  Lets pretend we are cutting a round corner.  Our corner is a quarter circle of a 1 inch radius and will start at X2 Y2 and end at point X1 Y3.  The center point of our circle will be at X1 Y2.  It may be helpful to sketch that out.  Go ahead and do that, I will wait for you here.

Now that we know our data, the start point, the end point and the radius we have enough information to write the code to cut this arc.  It is as follows:

G3 X1 Y3 R1 ;CCW arc starting at X2 Y2 and will go to X1 Y3 with a radius of 1 inch.

That seems simple enough, but there is a problem.  When arcs of this nature are described with a Radius it is possible that the controller can select a center point of someplace other than what we intended.  For example, we intended that the center of the circle was at location X1 Y2, but a point at X2 Y3 would have worked too.  Additionally, some controllers will not accept the Radius command.  But don't despair, there is a better way and once you learn it, there is no chance for ambiguity.

Setting the center point using offsets

Another way of describing the center point of the arc or circle is to give the controller a relative offset from the starting position to tell it exactly where the center point is located.  Now this sound a lot more complicated than it really is.  First there are three offsets we can work with.  These are I, J and K and each one of these is used with a certain axis.  I is used for the X-Axis, J is used for the Y-Axis and K is used for the Z-Axis.  To calculate the offset, lets go back to the Cartesian plane and the quadrant stuff from above.  Remember, our center point represents the origin or (0,0) of the Cartesian plane.  To determine the offset we need to calculate what we would need to add or subtract from the X, Y or Z axis to get us from the starting point of the arc to the origin (or center point) of our arc.  In our example above, our arc stared at X2 Y2 and the origin was at X1 Y2.  Since we are working in the XY plane we will use the I and J offsets.  Remember, I is used for the X-Axis and J for the Y-Axis.  Now lets calculate what our offsets would need to be.  Looking at the X location of the starting point we know it is at 2 and the X location of the origin is at 1, so to get from 2 to 1 we have to subtract 1 from the starting point.  We are working in the X-Axis so that means the I offset equals -1. (I-1).  We do the same process for the Y-Axis.  The starting Y position of the arc is 2 and the center point of our arc is 2 so to get from 2 to 2 we add/subtract 0.  The J offset is used for the Y-Axis so it comes out as (J0).  Also note that we are starting on a quadrant point making our calculations pretty simple.  If this confuses you, read the above a couple more times.  If you need more examples use the CONTACT US link at the top of the page, and I will add more examples of doing this.

Now that we have calculated the offsets let's rewrite the code above to use them.

G3 X1 Y3 I-1 J0 ;Using the starting point of X2 Y2, CCW arc ending on X1 Y3 with center point being X1 Y2

That wasn't so bad, but there is another caveat.  How do we cut a full circle.  Well we know that the start point and end point are the same.  Let's say we want to cut a 1 inch diameter circle with the center point being at X4 Y5.  Let's cut the circle using a clockwise cut and start it in the left center of the circle on the quadrant point.  The start position would be the center point minus the radius of the circle for the X coordinate and Y is the same as the center point.  So the start point is X3.5 Y5.  Since we are cutting a full circle, the end point will be the same as the starting point.  Now we need to calculate the I and J offsets.  Remember, we are going from the start point to the origin or center point of the circle.  The I offset equals .5 because we need to add .5 inches to the X coordinate to get to the center.  The Y starting point is the same as the origin or center point of the circle so the J offset is 0. The code to cut this circle is as follows.

G2 X3.5 Y5 I.5 J0 ;Starting point X3.5 Y5, cutting clockwise with center at X4 Y5 ending on X3.5 Y5

So where is the caveat?  Well, some controllers will not let you cut across a quadrant boundary.  So how do you cut a circle then?  If the controller does not let you cut across a quadrant then you will have to cut the circle in four segments.  One for each quadrant.  The code to do that is as follows:

G2 X4 Y5.5 I.5 J0 ;Starting point X3.5 Y5, cutting clockwise with center at X4 Y5 ending on X4 Y5.5 Quadrant II
G2 X4.5 Y5 I0 J-.5 ;Starting point X4 Y5.5, cutting clockwise with center at X4 Y5 ending on X4.5 Y5 Quadrant I
G2 X4 Y4.5 I-.5 J0 ;Starting point X4.5 Y5, cutting clockwise with center at X4 Y5 ending on X4 Y4.5 Quadrant IV
G2 X3.5 Y5 I0 J.5 ;Starting point X4 Y4.5, cutting clockwise with center at X4 Y5 ending on X3.5 Y5 Quadrant III

It is more work to cut this way but you are assured it will run on many more controllers.  This only matters if you are worried about portability.  Learn what your controller will do and do it the way you find easiest, whether you cut in one line, cut be quadrant or use the radius method.

Other things to consider

Finally, when cutting arcs or circles there are other things to consider.  Although I didn't mention it, the G2 and G3 command require a feed rate just like the G1 command.  If you don't supply a feed rate (F command) for the arc feed command the controller will use the last feed rate used.  If one does not exist, then it will throw and error.  Finally, if your start point begins on a point that does not reside on one of the quadrant points, you may have to use a little trigonometry to determine the point to calculate your I, J or K offset.

Putting it all together

Cutting arcs thumbTake a look at the drawing to the left.  Let is assume this is what we want to cut the profile of.  Further let's make the following assumptions.  The machine origin is located at the red cross hairs and is X0, Y0.  The material is wood and is .500 inches thick.  The Z-Axis home position has been set to the top surface of the work piece, .500 inches.  The starting position of the Z-Axis is at 1 inch.  Each grid square is equal to 1 inch.  With that out of the way, the drawing is a three inch square block with the corners having a radius of 1 inch.  All we need to do is determine what the starting point of the cut will be.  I have elected to (arbitrarily) start the cutting point at X1, Y2.  To make this part, we will use a .250 inch flat end mill.  We will take two passes at .250 inch each to cut the complete profile.  Below is the program to cut the profile.

(Set the units to inches)
G20
(set the plane to XY)
G17
(Select Tool 1 - .250 End mill, Change Tool)
T1 M6
(Set the feed rate to 50 inches per minute)
F50
(Turn the spindle on clockwise at 15,000 RPM)
M3 S15000
(Move to the start position)
G0 X1 Y2
G1 Z-.250 ;plunge to first cut depth
G3 X2 Y1 I1 J0 ;cut bottom left radius
G1 X3 Y1 ;cut the bottom of the square
G3 X4 Y2 I0 J1 ;cut bottom right radius
G1 X4 Y3 ;cut right side of square
G3 X3 Y4 I-1 J0 ;cut top right radius
G1 X2 Y4 ;cut top of square
G3 X1 Y3 I0 J-1 ;cut top left radius
G1 X1 Y2 ;cut left side and finish first pass
G1 Z-.500 ;plunge to final cut depth
G3 X2 Y1 I1 J0 ;cut bottom left radius
G1 X3 Y1 ;cut the bottom of the square
G3 X4 Y2 I0 J1 ;cut bottom right radius
G1 X4 Y3 ;cut right side of square
G3 X3 Y4 I-1 J0 ;cut top right radius
G1 X2 Y4 ;cut top of square
G3 X1 Y3 I0 J-1 ;cut top left radius
G1 X1 Y2 ;cut left side and finish second pass
G0 Z2 ;retract end mill
G0 X0 Y0 ;return home
M5 ;turn off spindle
M30 ;end of program
Clowns to the left of me, Jokers to the right, here I am, Stuck in the middle with you.

So far we have covered rapids, linear feeds and arc feeds.  If you have ran this code in an emulator you will have noticed that the cutter is cutting on the actual line.  As a result, the part is not the correct size as it ends up smaller than it is supposed to.  Cutter radius compensation is the answer and we will touch on that next.