rx: tweaks, add max delta for turns
This commit is contained in:
parent
1df647198b
commit
0899deb958
1 changed files with 32 additions and 7 deletions
39
src/esc.py
39
src/esc.py
|
@ -1,7 +1,9 @@
|
||||||
from motor import Motor
|
from motor import Motor
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
delta = 10
|
DELTA = 10
|
||||||
|
DELTA_TURN = 5
|
||||||
|
DELTA_MAX = 30
|
||||||
|
|
||||||
class Esc:
|
class Esc:
|
||||||
def __init__(self, pin_m1_ena, pin_m1_in1, pin_m1_in2,
|
def __init__(self, pin_m1_ena, pin_m1_in1, pin_m1_in2,
|
||||||
|
@ -10,22 +12,45 @@ class Esc:
|
||||||
self.m2 = Motor("m2", pin_m2_ena, pin_m2_in1, pin_m2_in2)
|
self.m2 = Motor("m2", pin_m2_ena, pin_m2_in1, pin_m2_in2)
|
||||||
|
|
||||||
def fwd(self):
|
def fwd(self):
|
||||||
speed = min((self.m1.speed + self.m2.speed)/2 + delta, 100)
|
speed = min((self.m1.speed + self.m2.speed)/2 + DELTA, 100)
|
||||||
self.m1.set_speed(speed)
|
self.m1.set_speed(speed)
|
||||||
self.m2.set_speed(speed)
|
self.m2.set_speed(speed)
|
||||||
|
|
||||||
def rev(self):
|
def rev(self):
|
||||||
speed = max((self.m1.speed + self.m2.speed)/2 - delta, -100)
|
speed = max((self.m1.speed + self.m2.speed)/2 - DELTA, -100)
|
||||||
self.m1.set_speed(speed)
|
self.m1.set_speed(speed)
|
||||||
self.m2.set_speed(speed)
|
self.m2.set_speed(speed)
|
||||||
|
|
||||||
def left(self):
|
def left(self):
|
||||||
self.m1.dec(delta)
|
s1 = self.m1.speed
|
||||||
self.m2.inc(delta)
|
s2 = self.m2.speed
|
||||||
|
avg = (s1 + s2)/2
|
||||||
|
delta = s2 - s1
|
||||||
|
|
||||||
|
if delta <= (DELTA_MAX - 2*DELTA_TURN):
|
||||||
|
self.m1.dec(DELTA_TURN)
|
||||||
|
self.m2.inc(DELTA_TURN)
|
||||||
|
elif delta == DELTA_MAX:
|
||||||
|
print("delta reached, not changing")
|
||||||
|
elif delta > (DELTA_MAX):
|
||||||
|
print("delta exceeded, resetting")
|
||||||
|
self.m1.set_speed(avg - DELTA_TURN)
|
||||||
|
self.m2.set_speed(avg + DELTA_TURN)
|
||||||
|
|
||||||
def right(self):
|
def right(self):
|
||||||
self.m1.inc(delta)
|
s1 = self.m1.speed
|
||||||
self.m2.dec(delta)
|
s2 = self.m2.speed
|
||||||
|
avg = (s1 + s2)/2
|
||||||
|
delta = s1 - s2
|
||||||
|
if delta <= (DELTA_MAX - 2*DELTA_TURN):
|
||||||
|
self.m1.inc(DELTA_TURN)
|
||||||
|
self.m2.dec(DELTA_TURN)
|
||||||
|
elif delta == DELTA_MAX:
|
||||||
|
print("delta reached, not changing")
|
||||||
|
elif delta > (DELTA_MAX):
|
||||||
|
print("delta exceeded, resetting")
|
||||||
|
self.m1.set_speed(avg + DELTA_TURN)
|
||||||
|
self.m2.set_speed(avg - DELTA_TURN)
|
||||||
|
|
||||||
# stop
|
# stop
|
||||||
def b1(self):
|
def b1(self):
|
||||||
|
|
Loading…
Reference in a new issue