Re: [CAD_CAM_EDM_DRO] hi Circles in CNC
Posted by
Alan Marconett KM6VV
on 2001-10-11 13:17:07 UTC
Hi Semih, Jon,
Jon is correct, I didn't get much out of Bresenham's circle drawing
algorithm for CNC controller use. What you can do is write a simple
"point rotate" routine. This is actually what the cutter will do when
it plods around the arc you want cut. This 'C' code snippit shows a
"point" (end of the radius), being "rotated" to the "TraceAngle", and a
new point (Xtrace, Ytrace) being calculated by adding the X & Y "deltas"
(Dcux & Dcuy) to the "arc centers" (LastX & LastY). So to use this, put
the code in a "loop", and go from "StartAngle" to "EndAngle". The
result will be a series of points (typically 1 step X and/or Y), which
you "move to" by sending steps to the appropriate axis (desired location
- current location all along the arc). The "degree steps" taken to get
from StartAngle to EndAngle determine how "course" the circle will be,
and the intent is to make it fine enough to just get a "step" each time
a new point is calculated. The required step is the angle needed to
move 1 machine step at the radius of the cut (you can calculate that).
/* rotate point */
rad = (TraceAngle / 180.0) * PI; /* Deg to Radians */
Dcux = radius * cos(rad); /* Calc. deltas */
Dcuy = radius * sin(rad);
/* new point */
Xtrace = LastX + Dcux; /* add deltas to center */
Ytrace = LastY + Dcuy;
Do the arcs in no more then 90 degree quadrants, and don't cross a
quadrant boundary in your "cuts". The reason for this is that the
motor(s) MUST change direction at each quadrant boundary. You'll want
to break arcs up so that this is accomplished. For example, 80 deg to
110 degree arc: first "cut" 80 to 90, then cut 90 to 110.
"G02 X 1.2 Y 2.2 I 0.5 J 0.5" (made up arc command)
Study the G02/G03 arc command. Use Absolute coordinates for X & Y, and
relative I and J offsets to the arc center. You will first arrive at a
point where you want an arc, then the G02/G03 specifies a destination
point, and the relative offsets to where the center of the arc is. I
and J can be thought of as the sides of a right triangle, and the
hypotenuse calculated is then the radius you need. The Calculated
"center" of the arc is found by adding I and J to the current
coordinates. Now that we have the center (LastX and LastY in example),
and the radius, we calculate the "StartAngle" of the current position,
and the "EndAngle" of the destination (the X and Y coordinates in the
Gcode command). Calculate the step size (or just always use a small
one), and "loop" from start to end as mentioned above!
Hope this helps your circle question. I noticed you are using Pascal, I
think Daves' TurboCNC uses Pascal.
Alan KM6VV
Jon Elson wrote:
Jon is correct, I didn't get much out of Bresenham's circle drawing
algorithm for CNC controller use. What you can do is write a simple
"point rotate" routine. This is actually what the cutter will do when
it plods around the arc you want cut. This 'C' code snippit shows a
"point" (end of the radius), being "rotated" to the "TraceAngle", and a
new point (Xtrace, Ytrace) being calculated by adding the X & Y "deltas"
(Dcux & Dcuy) to the "arc centers" (LastX & LastY). So to use this, put
the code in a "loop", and go from "StartAngle" to "EndAngle". The
result will be a series of points (typically 1 step X and/or Y), which
you "move to" by sending steps to the appropriate axis (desired location
- current location all along the arc). The "degree steps" taken to get
from StartAngle to EndAngle determine how "course" the circle will be,
and the intent is to make it fine enough to just get a "step" each time
a new point is calculated. The required step is the angle needed to
move 1 machine step at the radius of the cut (you can calculate that).
/* rotate point */
rad = (TraceAngle / 180.0) * PI; /* Deg to Radians */
Dcux = radius * cos(rad); /* Calc. deltas */
Dcuy = radius * sin(rad);
/* new point */
Xtrace = LastX + Dcux; /* add deltas to center */
Ytrace = LastY + Dcuy;
Do the arcs in no more then 90 degree quadrants, and don't cross a
quadrant boundary in your "cuts". The reason for this is that the
motor(s) MUST change direction at each quadrant boundary. You'll want
to break arcs up so that this is accomplished. For example, 80 deg to
110 degree arc: first "cut" 80 to 90, then cut 90 to 110.
"G02 X 1.2 Y 2.2 I 0.5 J 0.5" (made up arc command)
Study the G02/G03 arc command. Use Absolute coordinates for X & Y, and
relative I and J offsets to the arc center. You will first arrive at a
point where you want an arc, then the G02/G03 specifies a destination
point, and the relative offsets to where the center of the arc is. I
and J can be thought of as the sides of a right triangle, and the
hypotenuse calculated is then the radius you need. The Calculated
"center" of the arc is found by adding I and J to the current
coordinates. Now that we have the center (LastX and LastY in example),
and the radius, we calculate the "StartAngle" of the current position,
and the "EndAngle" of the destination (the X and Y coordinates in the
Gcode command). Calculate the step size (or just always use a small
one), and "loop" from start to end as mentioned above!
Hope this helps your circle question. I noticed you are using Pascal, I
think Daves' TurboCNC uses Pascal.
Alan KM6VV
Jon Elson wrote:
>
> Drew Rogge wrote:
>
> > Semih,
> >
> > I'm not sure what CNC controllers use for circle generation but
> > you might try doing a web search on Bresenham's circle drawing
> > algorithm. This used a lot in computer graphics. You'll probably
> > also find that you may need more input than just x1,y1 and x2,y2.
> > Even if these points are the beginning and end of a quarter segment
> > of a circle, there are two circles which share those points; one
> > whose center is at x1,y2 and the other at x2,y1. This is one
> > of the reasons g-codes allow you to specify if the travel along
> > the circle is in the clockwise or counter clockwise direction.
>
> Bresenham's algorithms are more oriented toward dot matrix drawings
> of circles and lines. The DA (Differential Analyzer) is more oriented
> for real numbers and continuous paths from a starting point to an
> end point. You should also be able to find algorithms if you search
> under DA, circle generating, etc.
>
> Jon