diff --git a/folkrace.py b/folkrace.py index 3122be4..ffdcd3a 100644 --- a/folkrace.py +++ b/folkrace.py @@ -27,18 +27,42 @@ def backward(): m3.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: print("F=", f"{front.distance:.2f}", "R=", f"{right.distance:.2f}", "L=", f"{left.distance:.2f}") try: if front.distance >= 20: # What to do when there is an obstacle ahead if left.distance > right.distance: # Diagonally left - + dgleft() if right.distance > left.distance: # Diagonally right - + dgright() if left.distance < 30: # Strafe right - + stright() if right.distance < 30: # Strafe left - + stleft() else: forward()