Avoid obstacles

From Adop-A-Bot -- Wiki at Brunel University
Jump to: navigation, search

This program is used to check if there is an obstacle in front of the Finch and if there is that the Finch will move away, this is used in our scenario when the Finch is avoiding the moving walls of the maze.

  1. A simple program that wanders and avoids obstacles

from finch import Finch from time import sleep

  1. Instantiate the Finch object and connect to Finch

tweety = Finch()

  1. Get the Z-Axis acceleration

zAccel = tweety.acceleration()[2]

  1. Do the following while the Finch is not upside down (z value in gees above -0.7)

while zAccel > -0.7:

   left_obstacle, right_obstacle = tweety.obstacle()
   # If there's an obstacle on the left, back up and arc
   if left_obstacle:
   # Back up and arc in the opposite direction if there's something on the right
   elif right_obstacle:
       tweety.wheels(-1.0, -0.3)
   # Else just go straight
       tweety.wheels(1.0, 1.0)
   # Keep reading in the Z acceleration
   zAccel = tweety.acceleration()[2]