Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try:
- while True:
- # the first if condition handles right angle turns
- # if the left sensor and right sensor continually hit the black tape consecutively
- # then, break this condition by movine forward
- if (right_bucket > 2 and left_bucket > 2):
- robot.forward(100,0.1)
- if (rightSensor() == 1 and leftSensor() != 1): #right sensor is on the tape so move right
- robot.left(50,0.1) #50 is speed and 0.1 is time
- right_bucket = right_bucket + 1
- elif (leftSensor() == 1 and rightSensor() != 1):
- robot.right(50,0.1)
- left_bucket = left_bucket + 1
- else:
- robot.forward(100,0.05)
- left_bucket = 0 #reset the bucket
- right_bucket = 0
- time.sleep(0.1)
- except KeyboardInterrupt:
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement