View Full Version : Algorithm?
CNCgr 10-14-2006, 04:27 AM I don't know if it's the right place to post this.
Some time ago someone posted that he was developing his own motion control software and someone suggested he took a look on some algorithm of converting the motion to intermediate steps (essentially a vector to raster transformation).
The algorithm was named after the man who invented it, doesn anybody know what I'm talking about?
Thanks,
Nikolas
WayneHill 10-14-2006, 05:26 AM Bezier curves ?
CNCgr 10-14-2006, 05:39 AM No, but thanks for answering. The one I'm looking for is much simpler. I want to go from point A to point B. Say I'm using steppers so there's a finite amount of positions the machine can take. Which are the points that better represent the A to B line. I hope I made it clearer.
Nikolas
gimbal 10-14-2006, 07:06 AM Hi Nikolas,
The algorithm you are looking for is the Bresenham Algorithm.
Cheers,
Pat
CNCgr 10-14-2006, 07:31 AM Hi Nikolas,
The algorithm you are looking for is the Bresenham Algorithm.
Cheers,
Pat
:cheers: Yeaaaaah!!! Thank's a lot, I owe you a beer!
Nikolas
DR-Motion 10-14-2006, 04:38 PM Consider the process of connecting two points on a piece of paper by drawing a line between them. To do so we must move our pencil in two axes simultaneously... where the motion of one axis is in fixed proportion to the motion of the other. This fixed proportion is the ratio of the distance the secondary axis has to move compared to the primary axis... and is equivalent to the slope of the line between the two points.
The procedure we use to calculate this ratio can have a major impact on the maximum precise pulse rate that our controller can produce. The processing time, used for the calculation limits the minimum step delay time, which determines our maximum speed. When we extend the coordinated motion to three or four axes, this processing time becomes even more significant.
The most efficient approach adopts an algorithm from the old days... when men were men and computers were wimpy. In the early days of computing, processing power was extremely expensive and limited. The task of connecting two points with a line was solved, for the problem of plotting a line on the raster display of a typical monitor.
The solution was called Bresenham's algorithm and involved only integer arithmetic, using addition and subtraction.
Here's an example of some pseudo code that demonstrates the application of Bresenham's algorithm in coordinating two axes of movement from one point to another.
distance = master // master is the axis which has the longer
distance to travel.
error = zero // error tracks the distance from the ideal
position.
While distance > zero // loop until distance has been traveled
{
Step pulse on master axis // outputs a pulse for the master axis .
distance = distance - 1 // distance has one less step to take
error = error + slave // slave is the axis, which has the
shorter distance to travel.
If error > slave // compare error
{
error = error - master
step pulse on slave axis // outputs a pulse for the
slave axis.
}
}
It turns out that this algorithm can be adapted to more than two axes simply by having a separate error term for each slave axis term. So as the master axis is traversed one step at a time... each of the (shorter) slave axes are stepped in proportion to their ratio (to the master).
So now we have a method of coordinating the motion of multiple axes with a minimum of computational overhead. In fact, a similar algorithm exists for circular motion.
acondit 10-14-2006, 08:07 PM I thought that in 8 bit logic 2b = 00101011 and ~2b = 11010100.
So 2b | ~2b = 00101011 | 11010100 = 11111111. Or FFh or 255.
Alan
DR-Motion 10-14-2006, 08:34 PM Sorry that would be 0x2d | ~ 0x2d ( 0b00101101 | 0b11010010 )
Symbolic algebra does not imply any particlular number base.
To paraphrase another member's sig... there are 10 kinds
of people in this world, those who don't understand binary,
those who think binary is the greatest new thing and
those who routinely use a plethora of modulo number bases ;-)
acondit 10-14-2006, 10:58 PM Gary,
You are correct, (my bad).
Alan
HuFlungDung 10-15-2006, 11:43 AM Hey, I got it...."10 kinds of people", but that's two in decimal talk isn't it? So shouldn't it be 11 kinds of people? ;)
Question on the application of this algorithm to machine motion: it would seem that none of the axis can move less than a pulse, so how do you prevent the loss of steps due to rounding off errors? Or how does the computer create what appears to be a smooth output over this bumpy road of digital bits? Is there some kind of averaging thing that is having all these "go, don't go" signals fed in?
Hey, I got it...."10 kinds of people", but that's two in decimal talk isn't it? So shouldn't it be 11 kinds of people? ;)
Thanks Hu, I did wonder what I was missing.
DR-Motion 10-15-2006, 12:16 PM count 0,1,2,10 in base 3 (trinary numbers)
It's a Monte Python number base...
yes, no and perhaps ;-)
Hu, a step and direction system can never output a fractional step/microstep;
if you zoom in close enough all curves show as a staircase albeit smoothed
by the inertia and flex of the machine.
unterhaus 10-16-2006, 10:08 PM Question on the application of this algorithm to machine motion: it would seem that none of the axis can move less than a pulse, so how do you prevent the loss of steps due to rounding off errors? Or how does the computer create what appears to be a smooth output over this bumpy road of digital bits? Is there some kind of averaging thing that is having all these "go, don't go" signals fed in?
Bresenham's algorithm has advantages over the brute force method: it can be done with integer only math, errors don't acummulate, and it uses a very nice method to decide if you should move on the minor axis. If you think about how this works, one of the axis is going to move one step every time because it has more distance to cover. The other one - the minor axis - may or may not move. So if the error between where you are and where the line exceeds half a step (not how they calculate it, but it's equivalent) you move the minor axis. This minimizes the error. On a machine, cutting forces and inertia may be your friend. On your screen, they also blend colors to make the jaggies look less stark, can't really do this with a stepper motor.
I just used it for an image processing algorithm, and it worked great. Of course, I didn't care about jaggies at all, just speed and accumulated error. I did have to modify it a little from the normal computer video implementation, because I wanted to start in one place and end in the other. I looked it up on Wikipedia.
hobby.club 11-01-2006, 05:54 AM Hello,
I use an very simple algoritme .
i write a program for AT90S2313,it communicate to Pc via RS232
on the PC runs a program in VB6
maybe its usefull for you?
I am new on the internet i dont now how to attach the code,maybe i can
mail it to you?
Sorry for my english
my email adres:ludo.van.ginderen@telenet.be
mwalach 09-03-2007, 02:03 PM I am working on a CNC driver program and am trying to wrap my head around the G2 and G3 codes. It looks like the Bresenham Algorithm is the answer, but I'm having trouble getting my head wrapped around this. How do I use the algarithm to generate my steps from a centerpoint and a radius as I would have in a G2 or G3 gcode?
BartW 08-03-2009, 04:01 AM Any one done a 3d version?
|
|