- Read the paper Intelligence Without Representation by Rodney Brooks
that was handed out in class. Think about how you would implement a control
program for your Handy Board robot based on Brooks' subsumption
architecture.
- You may work in teams of two on the rest of this assignment. Connect two
light sensors to your robot and run the program below. This program simply
reports the current values of the sensors. Test the sensor responses under a
variety of different lighting conditions. You'll notice that higher brightness
levels correspond to lower sensor readings.
int LEFT_EYE = 3; /* analog port number of left light sensor */
int RIGHT_EYE = 4; /* analog port number of right light sensor */
void main() {
while (1) {
printf("L=%d, R=%d\n", analog(LEFT_EYE), analog(RIGHT_EYE));
sleep(0.1);
}
}
- To use the light sensors with the motors, we need a way to transform the
light sensor readings into appropriate motor speeds. The following function
will do this.
int MAX_LIGHT = 10; /* maximum brightness level of environment */
int MIN_LIGHT = 200; /* minimum brightness level of environment */
int normalize(int light) {
int output = 100 - ((light - MAX_LIGHT) * 100 / (MIN_LIGHT - MAX_LIGHT));
/* keep output within range 0 to 100 */
if (output < 0) output = 0;
if (output > 100) output = 100;
return output;
}
This function maps sensor readings less than or equal to MAX_LIGHT
(corresponding to high brightness levels) to motor speed 100, and readings
greater than or equal to MIN_LIGHT (corresponding to low brightness
levels) to motor speed 0. Modify your program from Part 2 so that it reports
normalized light sensor readings, and then test out the sensors. You should
experiment with different values of MAX_LIGHT and MIN_LIGHT,
in order to find the most appropriate values for your environment.
- Now we can implement Braitenberg Vehicle #2, using a pair of light sensors
mounted on opposite sides of the robot. The basic code for light-seeking
behavior is shown below.
int LEFT_MOTOR = 1; /* port number of left motor */
int RIGHT_MOTOR = 3; /* port number of right motor */
void main() {
while (1) {
motor(LEFT_MOTOR, normalize(analog(RIGHT_EYE)));
motor(RIGHT_MOTOR, normalize(analog(LEFT_EYE)));
}
}
Simply interchanging RIGHT_EYE and LEFT_EYE results in
light-avoiding behavior. Experiment with both kinds of behavior under a
variety of lighting conditions. Can you rewrite the control program to
accentuate differences between the two light sensors?
- Now add some code to handle touch sensing. In particular, when your robot
runs into an obstacle, it should back up briefly, turn to the left or right
(depending on which touch sensor was activated), and then continue seeking or
avoiding light. It's a good idea to define some helping functions for this.
For example:
void turn_right(float seconds) {
fd(LEFT_MOTOR);
bk(RIGHT_MOTOR);
sleep(seconds);
off(LEFT_MOTOR);
off(RIGHT_MOTOR);
}
Calling turn_right(0.25) will execute a quarter-second turn to the
right. Define similar functions for turning to the left and going backwards,
and then use these in your touch sensor code.
- Sometimes it's useful to be able to include random behavior in the robot.
For example, you could have the robot turn or back up for a random number of
seconds whenever it hits an obstacle. Interactive C's random function
takes an int value n and returns a random int value
from 0 to n - 1. For example, random(100)
returns a value from 0 to 99. Use this to define the function
float random_time(float min, float max)
which should return a random floating-point number in the range
min to max. For example, random_time(0.25, 1.5)
would return a number between 0.25 and 1.5. You can then use this as the
argument to turn_right or turn_left. (Hint: subtracting
min from max gives the size of the range of desired values.
Use random(100) to generate a random "percentage" of this range.) How
does randomized turning affect your robot's ability to avoid obstacles while
seeking light sources? How long can your robot "survive" in its environment
without getting stuck?
- Experiment with the other types of control algorithms discussed in
Vehicles. For example, can you get your robot to exhibit the more
complicated kinds of behaviors shown in Figure 7 on page 18?