From ab6cc79eea2fe71b6f903e5b1f272a69ff813893 Mon Sep 17 00:00:00 2001 From: Simon Pirkelmann Date: Sat, 24 Oct 2020 20:05:39 +0200 Subject: [PATCH] added kick-start for small motor control signals --- micropython_firmware/d1motor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/micropython_firmware/d1motor.py b/micropython_firmware/d1motor.py index 6ca87a6..88afcad 100644 --- a/micropython_firmware/d1motor.py +++ b/micropython_firmware/d1motor.py @@ -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