# CS 101: September 2012

## HW #2: The Robot Games

1. For the robot opening ceremony, we will use the W,A,S, and D keys to move the robot around. The F key will be used to stop the robot, and the P key will have the robot sing the fight song. No sensors will be used for this exercise because all of the robot's commands will be given manually through the keyboard.

2. For the line drawing event, the robot is moves backwards, since the line sensors are located near the back of the robot; this allows for more precise movements. Inside a while-loop, the robot continuously checks to see what value each line sensor is returning, and it feeds these values into the robot.move() function. By treating the left line sensor as a negative value and the right line sensor as positive, and adding them together to form the ROTATE_SPEED of the robot, the robot will move straight if both sensors detect a line(-1+1=0), left if only the left sensor detects a line(-1+0=-1) and right if only the right sensor detects a line(0+1=1). The robot moves slowly to prevent veering too far off the line, and in the case that neither sensors detect a line, it will quickly move backwards in order to try to find the line again.

3. The robot moves forward until it gets to a certain distance from the wall. Then it turns right and checks or an obstacle. If there is no obstacle, it moves forward. If there is, it turns 180 degrees and continues straight.

4. Make Tail, Turn Right 45 degrees, turn left 90 degrees go straight for distance, turn left 90 degrees, go straight for distance, turn left 45 degrees, go straight for a distance, go back half distance, turn right 90 degrees, go back for half distance, turn right 90 degrees, go straight for distance, turn left 45 degrees, go back for distance

5. We used a basic function structure. By selecting a number from a menu and inputing that, it calls the desired behavior function. The opeing ceremony movement behavior is inside the main function though.

## HW #3: Urban Search & Rescue

1. Our team will spread out the disaster area to search for robots in the room.

2. The robot will use a switch function (a substitute for if-else) which will move the robot using WASD.

3. When the robot detects one of the lost robots, the user can edit that photograph and use the input from the user to determine the coordinates where the box will be.

4. The function that displays all the images taken during the rescue operation will help map out the disaster area.

The code for the program can be downloaded here! (Right-click and Save As to download)