I am writing some software to control a five phase stepper motor. The speed of the stepper motor is controlled by the frequency of a pulse I am sending to the motor controller. My present challenge is that I want to ease-in and ease-out of movements. I am actually replicating the behaviour of some old software which I do not have the source code for. I have an understanding of the logic of the easing, and it behaves as so:
- when the ending / sustained speed is slow, the ease-in is slower / takes longer
- when the ending / sustained speed is fast, the ease-in is faster / is shorter
For example… when the sustained speed is 693 Hz, the ease-in is 766 milliseconds long. I have sampled this ease-in curve using a Saleae logic analyzer. Here is the curve:
The starting frequency is 97.77 Hz. Here is a link to the actual data. So I am trying to figure out how to implement the proper logic / formula for this in code. The following bit of code will spit out increments of Hz that are relatively close to the increments I need, but the thing I can't figure out is how to get it to repeat/hold the same current_freq for an increasingly long duration of time – which is what essentially creates the curve that you see in the graph. My multiplier creating the increments is also off, but it is relatively close…
** edit – I think the below in theory works as far as adding a dimension of incrementing time to hold the stepping up current_freq, but there's something wrong with my implementation... it's just doing each frequency once.
current_freq = 97.
end_freq = 1134
t = 4
# number of times to send the current freqency
print current_freq
while current_freq < end_freq:
i = 1
t = t+t * .1673
print i
while i <= t:
print current_freq
i = i+1
break
current_freq = current_freq + current_freq * .1673
Any ideas? Is this a logarithm? Sin or cos? In case it isn't blatantly obvious I am horrible at math.
