cogliano
Posts: 2
Joined: Fri Mar 06, 2015 8:52 pm

Gertbot - Future stepper ramp support?

Fri Mar 06, 2015 8:58 pm

My Gertbot board does not support ramp up for stepper motors. Will this be supported in the future? I am wondering if I need to write some code to do this manually or if it will be supported natively in the near future.

Thanks!

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot - Future stepper ramp support?

Mon Mar 09, 2015 11:27 am

I have been thinking about that. It is a very difficult problem!

First there is the frequency change interval. For the linear motors I use the native
1KHz system timer. That will not work if your step frequency is lower then that.
Which it is in 9 out of 10 cases. In effect you might have to change the
step frequency each step. As the stepping is done in the interrupt routine
and a step frequency change requires a lot of calculations, I would not be able
to keep my limit of 5KHz steps.

The second problem is the ramp-down. For ramp-down you have to start reducing
the speed knowing when you will finish. (And the frequency at which you start ramping
and finish ramping has to be programmable as well, you get some very complex set-up data to send)
It gets more complex if you run for a short period of time as your ramp-up time will cross your ramp-down.

Furthermore there are some frequencies at which stepper motors can get in resonance.
You are bound to hit those during ramping. I understand professional stepper code
is written for a specific machine and avoids the resonance frequencies.
If ramping is required, it steps 'quickly' past those frequencies .

I will have another think about it but it is not an easy problem to solve.

cogliano
Posts: 2
Joined: Fri Mar 06, 2015 8:52 pm

Re: Gertbot - Future stepper ramp support?

Sat Mar 14, 2015 4:31 am

Thanks for the feedback. I can see your dilemma.

I decided to write a python routine to do the ramp up/down for a stepper motor. I am posting it here for others who may be interested in this. For a given frequency and number of steps, the routine ramps up for 20% of the time, at full velocity for 60% of the time and then ramps down at the last 20% of the time. The number of actual steps used is less than specified, since the number specified would be if full velocity was used at 100% of the time. If you are counting steps this routine may not be helpful but for my application I did not need an accurate count. The time taken should be close the time at full velocity (numsteps / freq). With this routine I was able to get the stepper motor to run at a much higher frequency than without the ramping.

Create a file named gertramp.py:

Code: Select all

import gertbot as gb
import time

def ramp(BOARD, MOTOR, freq, numsteps):
	if freq > 0 :
		gb.open_uart(0)
		maxloop = 10
		ramptime = 0.2 * abs(numsteps) / freq
		ramploop = ramptime / maxloop
		gb.freq_stepper(BOARD,MOTOR,0 )
		gb.move_stepper(BOARD,MOTOR,numsteps)

		# ramp up
		for i in range (0, maxloop - 1 ):
			gb.freq_stepper(BOARD,MOTOR,freq / (maxloop - i) )
			time.sleep(ramploop)

		# constant velocity
		time.sleep( 0.6 * abs(numsteps)  / freq);

		# ramp down
		for i in range (0, maxloop - 1 ):
			gb.freq_stepper(BOARD,MOTOR,freq / (i + 1) )
			time.sleep(ramploop)

		# stop motor
		gb.move_stepper(BOARD,MOTOR,0)
Here is a sample using the ramp function. Use a negative step count to reverse the direction:

Code: Select all

import gertbot as gb
import gertramp as gr
BOARD = 0
MOTOR = 0
gb.open_uart(0)
gb.set_mode(BOARD,MOTOR,gb.MODE_STEPG_PWR)
gr.ramp(BOARD,MOTOR,2000,4000)

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot - Future stepper ramp support?

Sat Mar 14, 2015 6:02 pm

With this routine I was able to get the stepper motor to run at a much higher frequency than without the ramping.
Ooops yes, I forgot to mention that.
Indeed with ramping you often can run a stepper motor faster.

The problem is that there are just too many variants of problems that there is no one solution fits all.
With the Gertbot I tried to accommodate the most common usage.
If not you have to do some programming yourself.
Which is exactly what the Raspberry-Pi is all about! :idea:

Return to “HATs and other add-ons”