1
votes

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:

  1. when the ending / sustained speed is slow, the ease-in is slower / takes longer
  2. 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:

enter image description here

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.

1
Do you or a colleague have access to Graphpad Prism? It's excellent for interpolating series like this. - MattDMo
I'm not familiar with it… looks interesting - dongle
Did you end up downloading Prism and doing some analyses? I'm playing with it now, if you're available just ping me in the Python chat room and we can discuss the data. - MattDMo
I did, but I am totally stumped on how to use it :) - dongle

1 Answers

0
votes

If you are trying to print out the new frequency multiple times, just remove the line with break.

This code produces the output that follows.

current_freq = 97.
end_freq = 1134

# number of times to send the current freqency
t = 4

while current_freq < end_freq:
    i = 1
    t = t + t * .1673
    print("t=%10f" % (t))
    while i <= t:
        print("i=", i, end=' ')
        print("  freq %.2f" % current_freq)
        i = i + 1
        #break
    current_freq = current_freq + current_freq * .1673

Output (truncated)

t=  4.669200
i= 1   freq 97.00
i= 2   freq 97.00
i= 3   freq 97.00
i= 4   freq 97.00
t=  5.450357
i= 1   freq 113.23
i= 2   freq 113.23
i= 3   freq 113.23
i= 4   freq 113.23
i= 5   freq 113.23
t=  6.362202
i= 1   freq 132.17
i= 2   freq 132.17
i= 3   freq 132.17
i= 4   freq 132.17
i= 5   freq 132.17
i= 6   freq 132.17
t=  7.426598
i= 1   freq 154.28
i= 2   freq 154.28
i= 3   freq 154.28
i= 4   freq 154.28
i= 5   freq 154.28
i= 6   freq 154.28
i= 7   freq 154.28
t=  8.669068
i= 1   freq 180.10
i= 2   freq 180.10
i= 3   freq 180.10
i= 4   freq 180.10
i= 5   freq 180.10
i= 6   freq 180.10
i= 7   freq 180.10
i= 8   freq 180.10
t= 10.119403
i= 1   freq 210.22
i= 2   freq 210.22
i= 3   freq 210.22
i= 4   freq 210.22
i= 5   freq 210.22
i= 6   freq 210.22
i= 7   freq 210.22
i= 8   freq 210.22
i= 9   freq 210.22
i= 10   freq 210.22
t= 11.812379
i= 1   freq 245.40
i= 2   freq 245.40
i= 3   freq 245.40
i= 4   freq 245.40
i= 5   freq 245.40
i= 6   freq 245.40
i= 7   freq 245.40
i= 8   freq 245.40
i= 9   freq 245.40
i= 10   freq 245.40
i= 11   freq 245.40
.
.
.