Open WayneKeenan opened 7 years ago
This is my version for a smoother servo movement:
/usr/local/lib/python3.4/dist-packages/picraftzero/providers/servo/piconzero.py
def set_angle(self, angle):
msg = "Set Angle {}".format(angle)
logger.debug(msg)
if angle == self.last_angle or angle is None:
return
if self.last_angle is None:
self.last_angle = 90
maxanglechange = 3
delta = angle - self.last_angle
if abs(delta) > maxanglechange:
logger.debug("Too fast change of angle. Throttling! angle {}, last {}".format(angle, self.last_angle))
if delta > 0:
angle = self.last_angle + maxanglechange
if delta < 0:
angle = self.last_angle - maxanglechange
self.last_angle = angle
logger.debug(msg)
pz.setOutput(self.servo_id, angle)
either running average or do interpolation/fade between present pos and target