Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1.     try:
  2.         while True:
  3.             # the first if condition handles right angle turns
  4.             # if the left sensor and right sensor continually hit the black tape consecutively
  5.             # then, break this condition by movine forward
  6.             if (right_bucket > 2 and left_bucket > 2):
  7.                         robot.forward(100,0.1)
  8.             if (rightSensor() == 1 and leftSensor() != 1):              #right sensor is on the tape so move right
  9.                             robot.left(50,0.1)                          #50 is speed and 0.1 is time
  10.                             right_bucket = right_bucket + 1
  11.                    elif (leftSensor() == 1 and rightSensor() != 1):
  12.                             robot.right(50,0.1)
  13.                             left_bucket = left_bucket + 1
  14.                    else:
  15.                             robot.forward(100,0.05)
  16.                             left_bucket = 0                             #reset the bucket
  17.                             right_bucket = 0
  18.                    time.sleep(0.1)
  19.    
  20.     except KeyboardInterrupt:
  21.             GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement