11 Mission Instructions
Your mission is to create a cookie delivery robot.
6. Code: Create Your Program
Remember the last mission when the notion of top-down design was introduced? The idea is to take a big problem and break it down in smaller problems until we find something we can solve.
Our main goal is to have the GoPiGo follow our line from start to finish. How will that work?
Let’s take a look at what can happen when the GoPiGo is on a delivery mission.
1. The GoPiGo might veer to the left, in which case it should try to get back on track by shifting a little more to the right..
2. The GoPiGo might veer to the right, in which case it should veer a little left. (These first two points are almost the same. Once we solve one, we'll have the other solved, just in reverse.)
3. The GoPiGo might have to go around a curve. Good news - if your line curves, your robot will too. All we need to worry about is keeping the robot centered on top of the line.
4. The GoPiGo needs to know when it’s reached its destination at the end of the line.
Write down how the GoPiGo should react to each of the following scenarios help answer the questions above.
If the line follower reads centered then _____________
If the line follower reads all black then _____________
If the line follower reads all white then _____________
If the line follower reads to the right then __________
If the line follower reads to the left then ___________
That top-down design approach is turning out to be very useful. When we break down the challenge into smaller parts, we can re-use the solution from one small part for another.
We need to keep in mind that following a line is precise work. To achieve this mission, the GoPiGo has to slow down.
Hint #1: Don’t expect the GoPiGo to stay exactly in the middle of the line at all times. It will waver from left to right. As long as at least one of the five sensors is on the line, the GoPiGo should be able to correct its direction.
Hint #2: Under which conditions do you want the GoPiGo to stop? How will it know it’s reached the end of the course? Maybe the end of the course is a black sheet of paper, so the GoPiGo will read black on all sensors, or maybe it’s a white sheet of paper? Make your decision and code accordingly.
Hint #3: What happens if the GoPiGo loses track completely? How do you want the GoPiGo to react?