Once the threshold levels have been set, we have to decide what our program is going to do. The best way to begin thinking about this is to write a set of commands in pseudocode. This is text written in lines as opposed to building a program with virtual blocks in the LEGO Mindstorms language. For the line follower, let's say the target RLI (reflected light intensity) is 30%, and that we want our robot to follow the right side of the black line. The pseudocode might look like this:
- Start program
- enter loop
- enter switch
- If RLI is greater than 30%, turn left
- If RLI is less than 30%, turn right
- continue loop forever
This basic program will need to be debugged and tweaked to find the best balance between speed and accuracy. There is also a way for the robot to change its amount of turn based on the reading of the sensor. This is called a proportional program.
I challenged myself to solve the maze problem, and it was much harder than I anticipated. After writing my pseudocode I toiled to come up with the successful program below. It took many rounds of trial and error, and in the end I included specific sounds to keep track of which parts of the program were being executed.
And here's the 'bot in action:
As soon as we get some line-follower robots, I'll post those too. I look forward to lots of lightbulbs going off as the kids learn to write these relatively complex programs!