Computer Science 014 |
Lab 3: Planned Maze Running
Due: 10:00 AM, Tuesday, January 9, 2007
Your task for today is to write a program to allow your robot to navigate a fixed path through a series of corridors. The robot environment will be set up when you arrive at the lab. Your job is to write the program that will get the robot through the maze-like passageways.
The corridors through which your robot needs to move are straight with turns at right angles. Thus, it will be useful to write functions that will make your robot travel straight for a given distance and that will make it turn 90 degrees. In particular, you are to write the following four functions:
Before you write these functions, experiment with your robot in interactive mode. In the first lab, you saw that Interactive C allows you to execute individual commands while in interactive mode. You can also execute a short sequence of commands, as long as you follow some simple rules: The command sequence must be typed on a single line and must be enclosed in curly braces.
{fd(3); bk(1);}Measure how long it takes to reach a 90 degrees angle. This should give you all the information you need to write the function.
There will be a stopwatch available for timing and rulers available for measuring distance traveled.
None of the functions you write will be very complex. However, this lab will involve a fair bit of trial and error to determine the right motor speeds and timing to get the desired effects. (I decided to have my robot move at full power at all times, but this is not necessary.) You should aim for functions that will achieve the desired result as precisely as possible, but you should keep in mind that perfect precision can't be achieved.
These four functions alone aren't especially useful to get the robot through the maze. You will need to put together a plan in the form of a series of operators that can be executed by the robot. You can think of the functions above as operations to be carried out by your robot. That is, they are the building blocks from which you can create a plan.
Once you have written your four building-block functions, you are ready to program the plan for your robot in order to make it travel along the desired path. In order to accomplish this, you should study the maze set-up, measure the distances that your robot needs to travel, and put together a plan in the form of a main function. This plan should naturally call upon the functions you wrote earlier.
You might find it convenient to have your robot wait until the start button is pressed before it begins to travel through the maze. You might also want to turn off all the motors as soon as the robot has completed its journey. Also, turn off the robot if it senses that it has crashed into something (as is done in the baseTest.c program from the previous lab).
You will need to demonstrate that each of your functions makes the robot respond in the appropriate way. You will also need to demonstrate that your robot can successfully make its way through the maze. You should also submit a printout of the program that guides your robot through the maze.