reverse after collision

This commit is contained in:
Siwat Sirichai 2022-11-09 23:34:26 +07:00
parent 7bf2ead82c
commit 2418bee407
1 changed files with 4 additions and 1 deletions

View File

@ -106,13 +106,16 @@ class motion:
def __roam_handle(self):
sensitivity = 35
turn_speed = 30
turn_speed = 40
drive_speed = 25
self.drive(drive_speed)
f_dist = self.sensors.sonar_get_distance(1)
if 0 < f_dist < sensitivity: # Close to collision, turn the vehicle
print("collision")
self.drive(-drive_speed)
time.sleep(0.75)
self.stop()
l_dist = self.sensors.sonar_get_distance(0)
r_dist = self.sensors.sonar_get_distance(2)
if l_dist < sensitivity: # Left side is blocked