adjust roam speed

This commit is contained in:
Siwat Sirichai 2022-11-09 23:25:05 +07:00
parent 15ef7493c7
commit 1ae7b3dbb2
1 changed files with 14 additions and 11 deletions

View File

@ -105,8 +105,11 @@ class motion:
self.__roam_handle()
def __roam_handle(self):
sensitivity = 35
self.drive(23)
sensitivity = 65
turn_speed = 30
drive_speed = 30
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")
@ -115,24 +118,24 @@ class motion:
if l_dist < sensitivity: # Left side is blocked
if r_dist < sensitivity: # Both side are blocked, do a full 180deg turn
print("full turn")
self.turn(30, 2*TURN_TIME_FS_90DEG_MS)
self.turn(30, 2)
self.drive(23)
else:
# Right Side is Free, turn right
print("right turn")
self.turn(30, TURN_TIME_FS_90DEG_MS)
self.drive(23)
self.turn(turn_speed, 1)
self.drive(drive_speed)
elif r_dist < sensitivity: # Right side is blocked, left side is free, turn left
print("right left")
self.turn(-30, TURN_TIME_FS_90DEG_MS)
self.drive(23)
self.turn(-turn_speed, 1)
self.drive(drive_speed)
else: # Both Side are free, randomize a direction
print("turn random")
right: bool = randint(0, 1)
if right:
self.turn(30, TURN_TIME_FS_90DEG_MS)
self.drive(23)
self.turn(turn_speed, 1)
self.drive(drive_speed)
else:
self.turn(-23, TURN_TIME_FS_90DEG_MS)
self.drive(30)
self.turn(-turn_speed, 1)
self.drive(drive_speed)
time.sleep(0.5)