Last active
November 15, 2016 12:41
-
-
Save bennuttall/76902a324db41e5403c0de212e7d07d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from gpiozero import LineSensor, Robot | |
| robot = Robot(left=(9, 10), right=(7, 8)) | |
| line = LineSensor(25) | |
| speed = 0.6 | |
| while True: | |
| robot.forward(speed) | |
| line.wait_for_no_line() | |
| robot.left(speed) | |
| line.wait_for_line() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from gpiozero import LineSensor, Robot | |
| robot = Robot(left=(9, 10), right=(7, 8)) | |
| line = LineSensor(25) | |
| robot.source_delay = 0.5 | |
| speed = 0.6 | |
| def look_for_line(): | |
| while True: | |
| yield (1, 0.5) # left motor full speed, right motor half speed | |
| yield (0.5, 1) # left motor half speed, right motor full speed | |
| while True: | |
| robot.forward(speed) | |
| line.wait_for_no_line() # go forward until the line is lost | |
| robot.source = look_for_line() # alternate between slight left and slight right | |
| line.wait_for_line() # until the line is found | |
| robot.source = None # unset the source to stop looking left and right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment