Turn motion on and off with the buttons at the bottom right of the applet (just above this text). The slider controls the speed of the robots. Bothered that at high speeds the robots go right through one another? Then pick a lower speed. When the simulator is stopped, you can drag robots and lights from the palette into the arena. Dragging a light or the middle of a robot moves it. Dragging the end or corner of a robot turns it. Dragging lights or robots out of the arena deletes them. Just drop them someplace in the applet if you’re using Netscape.
The green LightSeekingBots shown here have the speed of their left motors increasing with the intensity of light at their right front eyes, and the speed of their right motors increasing with the intensity of light at their left front eyes. They therefore move toward lights. Although they try to turn around if they hit things, LightSeekingBots tend to end up all together in a pile.
For the curious, here is the definition of the LightSeekingBot class:
/**
* A LightSeekingBot seeks light by having the speed of the RIGHT motor proportional
* to the amount of light on the LEFT front eye, and vice-versa. It backs up and
* turns randomly if it hits something.
*/
public class LightSeekingBot extends ICRobot implements Runnable {
public LightSeekingBot(float x, float y, float theta, RobotsApplet app){
super(x,y,theta,Color.green, app);
}
void main() {
motor(L_MOTOR, 10);
motor(R_MOTOR, 10);
while(!stop_button()) { // A real robot should check whether
// it is being turned off. In our applet,
// a thread can be stopped whenever
// it checks the stop button.
if (digital(L_TOUCH) || digital(R_TOUCH)){
// You hit something. Back up and turn randomly.
motor(L_MOTOR, -10);
motor(R_MOTOR, -10);
msleep(1000);
motor(R_MOTOR, 10);
msleep(random(3000));
motor(L_MOTOR, 10);
}else{ // You're going fine. Do the feedback thing.
motor(L_MOTOR, round(500*sqrt(analog(RF_EYE))));
motor(R_MOTOR, round(500*sqrt(analog(LF_EYE))));
}
defer(); // I.e., yield(). Let another Robot have some cycles.
// It's important to yield, since Java Virtual Machines are
// not guaranteed to timeslice. If we wrote main() without
// the defer(), then on some systems, only one bot would move.
}
}
}