Add strafing and diagonal movement
This commit is contained in:
parent
f705faf83e
commit
2310ddd020
1 changed files with 28 additions and 4 deletions
32
folkrace.py
32
folkrace.py
|
|
@ -27,18 +27,42 @@ def backward():
|
||||||
m3.throttle = -1
|
m3.throttle = -1
|
||||||
m4.throttle = -1
|
m4.throttle = -1
|
||||||
|
|
||||||
|
def stleft():
|
||||||
|
m1.throttle = -1
|
||||||
|
m2.throttle = 1
|
||||||
|
m3.throttle = 1
|
||||||
|
m4.throttle = -1
|
||||||
|
|
||||||
|
def stright():
|
||||||
|
m1.throttle = 1
|
||||||
|
m2.throttle = -1
|
||||||
|
m3.throttle = -1
|
||||||
|
m4.throttle = 1
|
||||||
|
|
||||||
|
def dgright():
|
||||||
|
m1.throttle = 1
|
||||||
|
m2.throttle = 0
|
||||||
|
m3.throttle = 0
|
||||||
|
m4.throttle = 1
|
||||||
|
|
||||||
|
def dgleft():
|
||||||
|
m1.throttle = 0
|
||||||
|
m2.throttle = 1
|
||||||
|
m3.throttle = 1
|
||||||
|
m4.throttle = 0
|
||||||
|
|
||||||
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}")
|
||||||
try:
|
try:
|
||||||
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()
|
||||||
if right.distance > left.distance: # Diagonally right
|
if right.distance > left.distance: # Diagonally right
|
||||||
|
dgright()
|
||||||
if left.distance < 30: # Strafe right
|
if left.distance < 30: # Strafe right
|
||||||
|
stright()
|
||||||
if right.distance < 30: # Strafe left
|
if right.distance < 30: # Strafe left
|
||||||
|
stleft()
|
||||||
else:
|
else:
|
||||||
forward()
|
forward()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue