Assignment

Your goal in this assignment is to program a robot to perform different kinds of search on a graph (depth-first, breadth-first). The graph is on the floor of the linux lab. There are only three robots available for use so you should plan your work carefully. I'm assuming that people can share robots while working, but obviously that system has its limits. PLEASE be thoughtful with your use of the robots. 20 other students in the lab need them. When you are done leave them attached to the connections such that they will remain powered. The success of this assignment is very much in your hands.

You will be expected to demo your robot in class on November 15th. Aside from traversing the tree, I will be looking for good designs, and speed and accuracy of the tree traversal.

Robots

Thanks to Doug Vail's contest page for the bulk of the descriptions.

The robot(s) for this contest are located in the linux lab. DO NOT REMOVE THE ROBOTS FROM THE LAB. Currently, there are only three available. The power switch for the robots is located on the left, rear portion of their board. After you download a program you must turn the switch off and then on again to start running it. CAVEAT: Be careful the robot is not near the edge of a table because the engines will sometimes spontaneously run when the robot is activated. To download a program, log into Linux as you normally would and run ic. IC stands for Interactive C. It's a scaled down version of the C language which runs on the robot. The robot must be turned on for IC to work properly. If it's not turned on, you'll get a message that IC can't synchronize with the board. To download a file, type load filename where filename is the name of a C file. The robot is controlled through several function calls. These are:

void motor(int id, int power);

Turns on the motor specified by id at power percent of its full power. The levels are really far apart - each motor really only has seven different settings, so motor(0, 1) would in theory turn motor 0 on at 1 percent of its full power and in reality not do anything at all. Negative numbers put them in reverse. The motors are numbered 0 and 1 in our particular configuration.

void alloff(void);

void ao(void); These two functions do the same thing; they turn off all motors.

int analog(int id);

Returns a result from 0-255 which corresponds to the reading from an analog sensor. The sensors on the robot are 0-4. Three of them are IR sensors located on the bottom which can be used to tell what color surface the robot is on (white poster board versus dark tape). The best way to learn about this is to play with them. If you type in a command in IC it will be executed immediately. This is great for determining what sensor readings are without going to the trouble of writing a complete program.

int stop_button(void);

int start_button(void);

These are special cases of digital sensors and correspond to the start and stop buttons.

Example

Here's a quick, dirty, and dumb example program that wanders around the board and turns around whenever it is about to wander off it. Notice that IC has no header files. It's either built into the language already or it is unavailable. (The robots only have 32K of RAM so space is scarce). The robots for this project actually have three IR sensors, not just two.

/*  Program to make a robot wander around over a poster which is much lighter 
    than the surrounding ground. */ 

int LEFT_IR = 2; 
int RIGHT_IR = 3; 
int LEFT_MOTOR = 0; 
int RIGHT_MOTOR = 1; 

int threshold = 50; 

int main() 
{ 
  while(!stop_button()) 
    { 
      /* Try to drive across the poster. */ 
      motor(LEFT_MOTOR, 100); 
      motor(RIGHT_MOTOR, 100); 

      /* cruise as long as we're staying on the paper */ 
      while(!IsSensorOff()); 

      /* let's point the robot back onto the paper */ 
      TurnBack(); 
    } 
  return 0; 
} 

int IsSensorOff(void) 
{ 
  if(analog(LEFT_IR)>threshold || analog(RIGHT_IR)>threshold) 
    return 1; 
  else 
    return 0; 
} 

void TurnBack(void) 
{ 
  /*  There are a few cases we can consider: 
      either both sensors are off or one sensor is off */ 
  alloff(); 
  while(IsSensorOff() && !stop_button()) 
    { 
      if(analog(LEFT_IR) > threshold && 
                           analog(RIGHT_IR < threshold)) 
         { 
           /*  The left side only is off - turn right */ 
           motor(RIGHT_MOTOR, -20); 
           motor(LEFT_MOTOR, 0); 
           sleep(.1); 
         } 
      else 
        { 
        /* the right side only is off - turn left or both sides are off. 
           I'm being lazy and saying turn right here as well. */ 
           motor(LEFT_MOTOR, -20); 
           motor(RIGHT_MOTOR, 0); 
           sleep(.1); 
        } 
    } 
  alloff(); 
}