Line Following
February 5, 2022
Today we programmed our robot to follow the line. We started by placing the robot on the course, and imagined which way it would need to turn depending on what the color sensor saw. If driving towards the distribution center, the robot would:
White: Go Straight
Black: Turn Left
Yellow: Turn Right
We made a simple program, and it worked! Then we noticed a problem. When picking up the boxes, the white and the yellow lines diverged and there was black on both sides of the white line. To fix this, we decided to use the brown color and place it on the other side of the white line. Then the robot could do the following instead:
White: Go Straight
Black: Turn Left
Else: Turn Right
This worked, and the robot would turn the corner just like we wanted. Great!
When the robot returns from the distribution center, the black and yellow lines are on the opposite sides. If we used the same instructions, the robot would just drive away from the line and never come back. We created a custom "My Blocks" function with the same instructions but reversed the turn directions. Now we had two functions: Distribution Run and Return Run.
Finally, our robot needs to know when it has reached the destination. We thought about how to use a color sensor for this, but Leon had an idea to use a touch sensor instead. We built a wall at each end of the white line, and added a couple touch sensors to the front of the robot so it could stop when it touches the wall.