Linear interpolation
curious1
Posts: 104
Hey Brains,
··
Question is : Can code be written to the BS2 to have··2 motors do linear interpolation· similar to the way a CNC controller runs a mill to cut a straight line at an angle to the X,Y axis,·or a lathe to cut threads ?
I am considering building a small machine specific to 1 part that would not require a PC with CNC software.
I have made 2 such 2 axis machines·and they work very well even though they are open loop steppers·but now I·would like·to interpolate with the 2 motors.
Any sample code would be appreciated, I did the math, ratio from 1 motor to the other was 42 to 1 but how to pulsout motor 1 one pulse for· every 42 pulses on motor 2 has me baffled.
Thanks
··
Question is : Can code be written to the BS2 to have··2 motors do linear interpolation· similar to the way a CNC controller runs a mill to cut a straight line at an angle to the X,Y axis,·or a lathe to cut threads ?
I am considering building a small machine specific to 1 part that would not require a PC with CNC software.
I have made 2 such 2 axis machines·and they work very well even though they are open loop steppers·but now I·would like·to interpolate with the 2 motors.
Any sample code would be appreciated, I did the math, ratio from 1 motor to the other was 42 to 1 but how to pulsout motor 1 one pulse for· every 42 pulses on motor 2 has me baffled.
Thanks
Comments
Pulsout to motor 1 - 4000 pulses
" 2 - 1 pulse for every 42 pulses of motor 1
There has to be a simple way, I just can't see it. Thanks
Do you want motor·1 to move 42 times faster than motor·2 ?
Ed
1. bring both motors to a known starting point.
2. start sending pulses to motor 1. Keep track of how many pulses. I just use a word variable within the loop that sends the pulsout.
3. every time the pulse variable totals 42, goto a loop to send a pulse to motor 2. Reset the pulse counter variable to zero.
4. go back to step 2. Repeat until all of motor 1's pulses have been counted.
A BS2sx will let you get to about 700 pulse/sec, in my experience.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
MAX=4000
COUNT=0
COUNTa=0
loop:
counta=counta+1
count=count+1
gosub motor1 'drive motor1
if count=42 then
gosub motor2 'drive motor2
count=0
endif
if counta<MAX then goto loop
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
Say 100 pulses and in the loop is a PAUSE 20 so it will run 2000 msec.
To define the speed, you need to select the proper pulse width. See the robotics Version 2.2
manual on page 115 .. do you have that ?
Ed
no, I dont have it.
If I did this :
for counter 1 to 1000
Pulsout motor 1
Pause 10
and at he same time :
for counter 1 to 100
Pulsout motor 2
Pause 100
Would the motors start and stop at the same time ?
Wouldnt motor 2 run exactly 50% revolutions as motor 1 ?
?????
Here is the essence of the code
This has a slight flaw, which is that it moves X motor first and then Y based on doing the Xpin instruction first. A better way would be to move both motors at the same time, so some method to output both pins states on the same line would be preferred, just not shown in the example.
Now change the example from X2Y2 to X1Y2, which means we still need to get X and Y motors to the same place at the same time, but now the distance to move is not the same anymore. That means two pieces of code have to be running to allow for two speeds. How to manipulate this on the Stamp I have no idea, the Propeller is a breeze to simultaneously and synchonously move multiple steppers, and I would really recommend the change of processor for your project.
But, here is the general idea, if anyone knows a "Stamp" way please show a way to accomplish this
Post Edited (TChapman) : 4/4/2007 11:29:05 PM GMT
Is there a Propeller tutorial for this sort of thing ?
Online ?
Thanks,
Russ
There is some chance someone here can see a way to Stamp this idea, but it will certainly be slower than I would want to run it on a machine.
length of the pause e.g. the servo's delivered with the Parallax package operate well as long as the pause
is in the range of 10 - 40 ms. Outside that range operation is "adverserly" impacted.
That is what Parallax states in their Robotics manual.
What I understand from the same Robotics manual is that the only proper way to control
the servo's speed is by changing the pulse width.
If not, what did I overlook ?
thanks,
Ed
Link to the Robotics version 2.2 manual
http://www.parallax.com/dl/docs/books/edu/Roboticsv2_2.pdf
Post Edited (TChapman) : 4/4/2007 7:56:21 PM GMT
Overlooked that "word" and I was focused on servo's because that is the only thing I have used so far.
Curious, sorry for the misleading info.
Ed
Looks like overall speed is going to be the problem though.
Is there NO way to run 2 pulse trains simultaneously with the BS2 ?
These stamps are so amazing, it would be a wonder that it wouldn't.
Thanks for the help.
That would assume you just have to feed pulses to the stepper controller. If the Stamp has to sequence the stepper, the OUTA = ~x would be replaced by the state machine code for sequencing.
If the ratio is 1 in 42, say 42000 steps on one axis and 1000 on the other, the outside common factor loop would execute n = 1000 times, and the inner loop would execute 42 times with a least common multiple of 1*42. The speed of motion from the program side is deterimined by the least common multiiple, so a pause may be included so as to adjust the speed if it turns out to be too fast when the lcm is low. Whether it is fast enough depends on the the machine, I guess.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Shouldn't idx and phase be the same variable?
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
This same algorithm can be used to draw straight lines in a bitmapped graphics array, BTW.
-Phil
Assume .25 acme screws and 16 TPI typical on a small machine at 1/2 step, 200 step motor:
16(threads) * 400(1/2 steps) = 6400 pulses to move the tool/table 1 inch.
Assume a nominal cutting speed of 10 inches per minute, what kind of perfomance can be obtained with the amount of code to execute for two motors? How is the Z(router) supposed to be getting into position without a 3rd stepper?
-Phil
If you haven't already, do check out Sid Weaver's super mill. H worked first in PBASIC on the Stamp and more recently in Spin on the Propeller. I think a lot of the PBASIC discussion about it is in the Sandbox forum in the immense community milling machine thread. There are also lot of deep threads about CNC on the propeller forum.
Phil,
I'm staring at your incremental algorithm, and I'm going to have to try it out to see it in operation. Is that a standard bitmap algorithm?
I saw the problem about overflow of the multiplication on the Stamp with the 16 bit word. That is why I broke it down into nested loops using the least common multiple, but of course it would have to be massaged further if the X and Y step numbers are do not have a common factor. As an aside, the X and Y numbers can be broken down as a continued fraction, and the convergents can always be used to guide a motion pattern in shorter cycles. To put that in relevant terms, approximating Y/X is always being done on an integer grid by making a series of shorter excursions that have integer coordinates, Y1/X1...Y2/X2... so that in the end all the Yn and Xn add up to Y and X. The continued fraction is essentially a description of the optiimal path, that is, the path through the grid that stays closest to the slop Y/X. The final convergent is alway the least common multiple of Y and X that could be used in the algorithm I posted.
I'll attached a little program that demonstrates how to extract the convergents of a continued fraction in PBASIC.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I don't know, frankly. It's something I came up with when I was working on the drawing algorithm for the PropCAM firmware. It's fast, since at least one axis gets moved at every step. (In a way, it's just a compression of your algorithm, with the non-motion steps removed.) But the phase jitter might be objectionable in certain apps. In that case, a multiple of xsteps or ysteps can be added when a step is taken to smooth things out, with the time interval between iterations reduced accordingly. Of course, overflow becomes a possibility again, if the multple times the maximum number of steps on an axis exceeds the word size.
The continued fractions stuff is quite intriguing. It's amazing how much can be accomplished with integer operations. I fear that a lot of interesting math is going to get lost when floating point processors find their way into "low level" microcontrollers!
-Phil
I'll read the CNC topics on the other forums.
When GW talks weird, they call it a BUSHISM.
When Gore talks weird do they call it an AlGorism ?·