Added option for turning.

This commit is contained in:
Γιώργος Αντρέου 2025-05-22 17:58:27 +03:00
parent 2310ddd020
commit 8de04e2155

View file

@ -51,6 +51,18 @@ def dgleft():
m3.throttle = 1 m3.throttle = 1
m4.throttle = 0 m4.throttle = 0
def turnright():
m1.throttle = 1
m2.throttle = 1
m3.throttle = 1
m4.throttle = 0
def turnleft():
m1.throttle = 1
m2.throttle = 1
m3.throttle = 0
m4.throttle = 1
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:
@ -60,9 +72,11 @@ while True:
if right.distance > left.distance: # Diagonally right if right.distance > left.distance: # Diagonally right
dgright() dgright()
if left.distance < 30: # Strafe right if left.distance < 30: # Strafe right
stright() turnright()
#stright()
if right.distance < 30: # Strafe left if right.distance < 30: # Strafe left
stleft() turnleft()
#stleft()
else: else:
forward() forward()