CSCI 108 Lab 4
Description
In this lab, you will write a program to make your robot 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.
Part I: Simple Functions
The corridors through which your robot needs to move are straight with
turns at right angles. It will therefore be useful to write functions
that will make your robot travel straight and that will make it turn. In
particular, you are to write the following four functions:
- void right_90Degrees( )
i.e., turn 90o to the right
- void left_90Degrees( )
turn 90o to the left
- void forward_xInches(float x)
go forward x inches
- void forward_xFeet(float x)
go forward x feet
In order to write these functions, you should first experiment with your
robot in interactive mode. Refer to the writeup of Lab 2 for notes on
starting up Interactive C. In Lab 2 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.
Writing functions for turning. Before writing the function
that will turn your robot 90o to the right, set your robot
turning right in interactive mode. For example, if 3 is the left motor and 1 is the
right motor, you can type
{fd(3); bk(1);}
Measure how long it takes to reach a 90o angle. This should give you
all the information you need to write the function.
Writing functions for going straight a certain distance. Before writing the
distance functions, you should measure how long it takes for your robot to move
forward 1 inch and 1 foot. Based on this information, your function can calculate
the time required to move x inches and x feet. You will find it useful to know that
the multiplication operator in Interactive C is the asterisk (*) character.
I will bring a stopwatch to lab, as well as rulers 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 absolute accuracy can't be achieved.
Note that we have been discussing planning in class, which involves putting
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 operators to
be carried out by your robot. That is, they are the building blocks from
which you can create a plan.
Part II: Programming the Robot's Path
Once you have written the four functions above, 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.
Requirements
You will need to demonstrate to me 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.
Please turn in your program, both electronically and on
paper. To turn it in electronically, drag it to the Dropoff folder that
can be found in the CS 108 folder. (Note that Lab 3 had directions for
getting to the CS 108 folder.) Don't forget
to put your name on everything submitted. It is particularly helpful if
you put your name (or initials) in the name of the file you submit
electronically.
Due to Reading Period, this lab will not be due at the usual time. Instead,
it must be completed by Thursday, October 16 at 1:00 PM -- i.e., right before
the next lab.
Before you leave the lab, please be sure to do the following:
- Quit out of Interactive C.
- Drag "Courses" to the trash in order to disconnect from the file
server (if you connected to the cortland file server).
- Log out.
- Make sure your Handy Board battery is being charged for next week.
- Put away any toolboxes, Lego boxes, cables, etc.