change speeds
This commit is contained in:
parent
05f48e8a3e
commit
19388afdd2
1 changed files with 31 additions and 27 deletions
58
folkrace.py
58
folkrace.py
|
|
@ -16,52 +16,52 @@ right = adafruit_hcsr04.HCSR04(trigger_pin=board.D10, echo_pin=board.D11)
|
||||||
left = adafruit_hcsr04.HCSR04(trigger_pin=board.D6, echo_pin=board.D9)
|
left = adafruit_hcsr04.HCSR04(trigger_pin=board.D6, echo_pin=board.D9)
|
||||||
|
|
||||||
def forward():
|
def forward():
|
||||||
m1.throttle = 1
|
m1.throttle = 0.5
|
||||||
m2.throttle = 1
|
m2.throttle = 0.5
|
||||||
m3.throttle = 1
|
m3.throttle = 0.5
|
||||||
m4.throttle = 1
|
m4.throttle = 0.5
|
||||||
|
|
||||||
def backward():
|
def backward():
|
||||||
m1.throttle = -1
|
m1.throttle = -0.5
|
||||||
m2.throttle = -1
|
m2.throttle = -0.5
|
||||||
m3.throttle = -1
|
m3.throttle = -0.5
|
||||||
m4.throttle = -1
|
m4.throttle = -0.5
|
||||||
|
|
||||||
def stleft():
|
def stleft():
|
||||||
m1.throttle = -1
|
m1.throttle = -0.5
|
||||||
m2.throttle = 1
|
m2.throttle = 0.5
|
||||||
m3.throttle = 1
|
m3.throttle = 0.5
|
||||||
m4.throttle = -1
|
m4.throttle = -0.5
|
||||||
|
|
||||||
def stright():
|
def stright():
|
||||||
m1.throttle = 1
|
m1.throttle = 0.5
|
||||||
m2.throttle = -1
|
m2.throttle = -0.5
|
||||||
m3.throttle = -1
|
m3.throttle = -0.5
|
||||||
m4.throttle = 1
|
m4.throttle = 0.5
|
||||||
|
|
||||||
def dgright():
|
def dgright():
|
||||||
m1.throttle = 1
|
m1.throttle =0.5
|
||||||
m2.throttle = 0
|
m2.throttle = 0
|
||||||
m3.throttle = 0
|
m3.throttle = 0
|
||||||
m4.throttle = 1
|
m4.throttle =0.5
|
||||||
|
|
||||||
def dgleft():
|
def dgleft():
|
||||||
m1.throttle = 0
|
m1.throttle = 0
|
||||||
m2.throttle = 1
|
m2.throttle =0.5
|
||||||
m3.throttle = 1
|
m3.throttle =0.5
|
||||||
m4.throttle = 0
|
m4.throttle = 0
|
||||||
|
|
||||||
def turnright():
|
def turnright():
|
||||||
m1.throttle = 1
|
m1.throttle = 0.5
|
||||||
m2.throttle = 1
|
m2.throttle = 0.5
|
||||||
m3.throttle = 1
|
m3.throttle = 0.5
|
||||||
m4.throttle = 0
|
m4.throttle = 0
|
||||||
|
|
||||||
def turnleft():
|
def turnleft():
|
||||||
m1.throttle = 1
|
m1.throttle = 0.5
|
||||||
m2.throttle = 1
|
m2.throttle = 0.5
|
||||||
m3.throttle = 0
|
m3.throttle = 0
|
||||||
m4.throttle = 1
|
m4.throttle = 0.5
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print("F=", f"{front.distance:.2f}", "R=", f"{right.distance:.2f}", "L=", f"{left.distance:.2f}")
|
print("F=", f"{front.distance:.2f}", "R=", f"{right.distance:.2f}", "L=", f"{left.distance:.2f}")
|
||||||
|
|
@ -69,16 +69,20 @@ while True:
|
||||||
if front.distance <= 20: # What to do when there is an obstacle ahead
|
if front.distance <= 20: # What to do when there is an obstacle ahead
|
||||||
if left.distance > right.distance: # Diagonally left
|
if left.distance > right.distance: # Diagonally left
|
||||||
dgleft()
|
dgleft()
|
||||||
|
time.sleep(0.8)
|
||||||
if right.distance > left.distance: # Diagonally right
|
if right.distance > left.distance: # Diagonally right
|
||||||
dgright()
|
dgright()
|
||||||
|
time.sleep(0.8)
|
||||||
if left.distance < 30: # Strafe right
|
if left.distance < 30: # Strafe right
|
||||||
turnright()
|
turnright()
|
||||||
#stright()
|
#stright()
|
||||||
|
time.sleep(0.5)
|
||||||
if right.distance < 30: # Strafe left
|
if right.distance < 30: # Strafe left
|
||||||
turnleft()
|
turnleft()
|
||||||
#stleft()
|
#stleft()
|
||||||
|
time.sleep(0.5)
|
||||||
else:
|
else:
|
||||||
forward()
|
forward()
|
||||||
|
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
Loading…
Add table
Add a link
Reference in a new issue