added kick-start for small motor control signals

This commit is contained in:
Simon Pirkelmann 2020-10-24 20:05:39 +02:00
parent 7f194f57f2
commit ab6cc79eea

View File

@ -10,6 +10,10 @@ m0.speed(5000)
"""
import ustruct
import utime
import math
sign = lambda x: math.copysign(1, x)
_STATE_BRAKE = const(0)
@ -49,6 +53,10 @@ class Motor:
def speed(self, speed=None):
if speed is None:
return self._speed
if abs(speed) < 30 and abs(speed) > 10: # kick-start for small speeds
self.speed(int(100 * sign(speed)))
utime.sleep_ms(5)
if speed > 0:
self._speed = min(10000, max(1, speed))
self._state = _STATE_RIGHT