Help converting to spin stepper motor ramping
Bits
Posts: 414
I have found a document that appears to be an elegant solution for a stepper motor ramp. In my attempt to program this document into spin I have discovered a problem. The link to said document is here.
I identify that there has to be a clock (be an object or cog) that should engender a pulse on a selected output pin. That clock needs to be updated from one of these equations. This has yet been programmed.
I think I understand the equations and have posted them below in a very basic manor using floating point computations.
But if someone could explain an order or provide a crude flow chart for what equations have to be executed and when, I would be appreciative.
I identify that there has to be a clock (be an object or cog) that should engender a pulse on a selected output pin. That clock needs to be updated from one of these equations. This has yet been programmed.
I think I understand the equations and have posted them below in a very basic manor using floating point computations.
But if someone could explain an order or provide a crude flow chart for what equations have to be executed and when, I would be appreciative.
{{ Real time stepper motor linear ramping ____________________________________________________ First attempt by : Bits Documentaion bt : Aryeh Eiderman PDF located at : http://www.hwml.com/LeibRamp.pdf HTML located at : http://www.hwml.com/LeibRamp.htm ____________________________________________________ }} Con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 Var Long Base_Speed, Slew_Speed Long acceleration,Timer_freq Long Base_Speed_Squared, Slew_Speed_Squared Long S, P1, Ps, R, P, M Obj ser :"fullduplexserial" math :"float32" pub Start math.start init main Pub Main Pub init ser.start(31,30,0,19200) acceleration := 1.0 'steps / second Base_Speed := 2.0 'steps / second Slew_Speed := 5.0 'steps / second Timer_freq := 1.0 'ticks / second Hz S := P1 := Ps := R := P := M := 0.0 Base_Speed_Squared := math.Fmul(Base_Speed,Base_Speed) Slew_Speed_Squared := math.Fmul(Slew_Speed,Slew_Speed) Pub accel_deceleration_distance | Temp Temp := Math.Fmul(2.0,acceleration) S := Math.Fsub(Slew_Speed_Squared, Base_Speed_Squared) S := Math.Fdiv(S,temp) Pub delay_period_4_inital_step | Temp Temp := Math.Fmul(2.0,acceleration) P1 := Math.Fadd(Base_Speed_Squared,Temp) P1 := Math.FSqr(P1) P1 := Math.Fdiv(Timer_Freq,P1) Pub delay_period_4_slew_speed Ps := Math.Fdiv(Timer_Freq,Slew_speed) Pub constant_multipler | Temp Temp := Math.Fmul(Timer_freq,Timer_freq) R := Math.Fdiv(acceleration,Temp) Pub variable_delay_period | Temp Temp := Math.Fmul(P,P) Temp := Math.Fmul(Temp,m) Temp := Math.Fadd(1.0,Temp) Temp := Math.Fmul(p,Temp) P := Temp Pub variable_multiplier M := 0 { floating point logic needed below if (R < 0) M := -R if (R > 0) M := R }
Comments
1) Floating point is a lot slower than integer arithmetic. Still, floating point speeds with the Propeller are not too shabby. Make sure to use the new floating point object "F32". It's faster and has some minor numeric corrections.
2) You have to use FNeg for negation and FCmp for comparisons like: if Math.FCmp(R,0.0) < 0
Trying to come up with some way to even start the process is a testing to my fortitude. I have read the document a few dozen times and still the light is off.
Hum, anyone even have a slight idea on how I can proceed?
Have you had a look at this attachment? Maybe this can help.
But I agree with Mike about using integers vs. floats.
What are you trying to do, is it to build a stepper controller with ramping or is this your part of a team assignment where you have been given the task of implementing this on the Prop?
If you have total control and want to build a stepper I would suggest using a chip with all this built in and more. Have a look at the L6470 which allows you specify acceleration & deceleration parameters amongst many other housekeeping functions.
Regards,
Mickster
I was thinking similar to your post, in that all the calculations could be completed first then at run time only one recursive equation is used. I am still trying to decipher the order of things.
http://obex.parallax.com/objects/617/
http://www.pmdcorp.com/news/articles/html/Mathematics_of_Motion_Control_Profiles.cfm
Lardom, Ill have a peek at that code.