HTML

wanderer.py

Nov 18th, 2016
158
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # A simple program that wanders and avoids obstacles
  2.  
  3. from finch import Finch
  4. from time import sleep
  5.  
  6. # Instantiate the Finch object and connect to Finch
  7. tweety = Finch()
  8.  
  9. # Get the Z-Axis acceleration
  10. zAccel = tweety.acceleration()[2]
  11.  
  12. # Do the following while the Finch is not upside down (z value in gees above -0.7)
  13. while zAccel > -0.7:
  14.    
  15.     left_obstacle, right_obstacle = tweety.obstacle()
  16.     # If there's an obstacle on the left, back up and arc
  17.     if left_obstacle:
  18.         tweety.led(255,0,0)
  19.         tweety.wheels(-0.3,-1.0)
  20.         sleep(1.0)
  21.     # Back up and arc in the opposite direction if there's something on the right
  22.     elif right_obstacle:
  23.         tweety.led(255,255,0)
  24.         tweety.wheels(-1.0, -0.3)
  25.         sleep(1.0)
  26.     # Else just go straight
  27.     else:
  28.         tweety.wheels(1.0, 1.0)
  29.         tweety.led(0,255,0)
  30.     # Keep reading in the Z acceleration
  31.     zAccel = tweety.acceleration()[2]
  32.    
  33. tweety.close()
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment