It all works well if all numbers inside the interrupt handler are int. I wasn't able to make it work if even one of them is a float. Even if I declare them as float they seam to be turned to int within the interrupt handler automatically.
It would be great if I could specify a float number for self.acc. One is quite large and zero is obviously too small. Here are some code extracts:
Code: Select all
def __init__(self):
# Variables
self.speed_R = 0 #speed counter. If >255 step will be executed
self.speed_L = 0 #speed counter. If >255 step will be executed
self.sspeed_R = 0 #set speed
self.sspeed_L = 0 #set speed
self.dist_R = 0 #distance counter
self.dist_L = 0 #distance counter
self.target = 0 #motion control position target
self.acc = 1 #motion control acceleration
self.dts = 0.0 #motion distance to stop
def Motion(self, t):
self.dts = (self.acc * (self.sspeed_L // self.acc) ** 2) // 512
if self.sspeed_L < 0:
self.dts *= -1
if self.target > (self.dist_L + self.dts) and self.sspeed_L < 256:
self.sspeed_L += self.acc
self.sspeed_R += self.acc
elif self.target < (self.dist_L + self.dts) and self.sspeed_L > -256:
self.sspeed_L -= self.acc
self.sspeed_R -= self.acc
elif self.target == self.dist_L and abs(self.sspeed_L) < 50:
self.sspeed_L = 0
self.sspeed_R = 0
self.MoveStep(1)
def SetMotion(self, value):
if value == 0:
self.tim1.callback(None)
if value == 1:
self.tim1.callback(self.Motion)