added kick-start for small motor control signals
This commit is contained in:
parent
7f194f57f2
commit
ab6cc79eea
|
@ -10,6 +10,10 @@ m0.speed(5000)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import ustruct
|
import ustruct
|
||||||
|
import utime
|
||||||
|
import math
|
||||||
|
|
||||||
|
sign = lambda x: math.copysign(1, x)
|
||||||
|
|
||||||
|
|
||||||
_STATE_BRAKE = const(0)
|
_STATE_BRAKE = const(0)
|
||||||
|
@ -49,6 +53,10 @@ class Motor:
|
||||||
def speed(self, speed=None):
|
def speed(self, speed=None):
|
||||||
if speed is None:
|
if speed is None:
|
||||||
return self._speed
|
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:
|
if speed > 0:
|
||||||
self._speed = min(10000, max(1, speed))
|
self._speed = min(10000, max(1, speed))
|
||||||
self._state = _STATE_RIGHT
|
self._state = _STATE_RIGHT
|
||||||
|
|
Loading…
Reference in New Issue
Block a user