I've been working hard all day to get this to work.
I'm playing around with the math module in python. I eventually want the following code to help me control the speed of a servo motor. The idea is to get the servo speed to accelerate and then decelerate as it reaches its set position--in a parabolic way you might say.
The problem is I'm getting wavy numbers apparently from the algorithm I've set up and it needs to be a nice smooth transition.
from __future__ import division
import math
import time
def Interpolation():
EffectPercentage = 1
Step = 1
nSteps = 32
MovementStepPercentage = EffectPercentage/nSteps*Step
print MovementStepPercentage
while Step << 32:
Interpolation = (1-math.sin(MovementStepPercentage*180+90))/2*EffectPercentage+MovementStepPercentage*(1-EffectPercentage)
print "Interpolation =", Interpolation
Step = Step+1
print "Step =", Step
MovementStepPercentage = EffectPercentage/nSteps*Step
print MovementStepPercentage
time.sleep(0.0035)
if Step == 32:
break
Interpolation()
I know a thing or two about math, but not enough to get this to work apparently... any pointers?