CS 327 LEGO Vacuum Bot Lab

Overview

Welcome AI students!

This lab is designed to let students get some hands-on experience in robot motion planning. It is not necessarily so hard to create a program to simulate robot motion, but actually testing the robot in the real world can often prove to be very difficult.

For this lab, find a group of two or three to work in. You will be using DOS for parts of this lab, so having a group member who is familiar with DOS will be helpful, but not necessary. For the programming parts of the lab you will be using Java, so knowledge of Java is also a plus.

Setting up

You will be using LEGO MindStorms sets and the computers in room 307. You will need to make an appointment or come in at a specified time to get at the LEGOs and maps. Boot any of the computers in room 307 into windows. Log in and download these files:
Calibration program
VacuumBot java file
Example agent

Go to the start menu and select "Run..." in the text field type "command" and click ok. You should now have opened a DOS window.

Learning leJOS and some DOS

In your DOS window, go to the directory where you will be working with your program. I would recommend your k: drive.
If you've never used DOS before, and want some help, try this little help file.

First, familiarize yourself with how the leJOS software communicates with the LEGO robots. Place the robot so that its infrared receiver is facing the LEGO transmitter:

Turn on the LEGO robot. Then in the DOS window, type the command

lejosfirmdl.exe

You should hear a double-beep from the LEGO robot and its LCD screen will begin counting up from 0. What you are doing is downloading the Java firmware to the LEGO robot. This action actually only needs to be performed once per robot, but doing it will help you see how the computer and LEGO robot actually communicate with each other. Don't worry if it takes a long time, the firmware is big. You should never need to do this again, unless you think someone has downloaded firmware for a different programming langauge (other than leJOS) onto the robot.

Once the firmware is downloaded, you can begin downloading java programs for the LEGO bot to run. Try Calibration.java first. This program will come in very handy, trust me. To compile it, type:

K:\AISTUFF>lejosc Calibration.java

Note that lejosc is the equivalent of javac.

Make sure that the LEGO brick is on and pointing at the transmitter, then run:

K:\AISTUFF>lejos Calibration

Both the screen and the LEGO brick will give updates as to the progress of the transmission. When it is done, the brick will double-beep. Now press the "run" button on the brick. The LCD screen will be continuously updating a number that will probably be somewhere around 725. Try pressing some of the other buttons, but not the "on/off" button. Pressing the "on/off" button while running a program will turn off the brick. Remember this, as you will definitely need to stop your robot from going haywire once in a while. Open up Calibration.java in your favorite text editor, and see what it does. It will be useful because not all LEGO light sensors are created equal. You may want to consider keeping track of some of the numbers that your robot reports back while using this program.

Downloading a new program to the brick will simply erase the old one, there is no way to have two programs in the brick at the same time.

Getting VacuumBot started

There are three percepts that the robot knows: atHome(), hitBump() and onDirt(). These percepts are implemented in the form of members that return boolean values.

atHome() returns true if the robot is in its home location. Home is signified by a blue piece of paper on the grid.
hitBump() returns true if the robot just bumped into a wall. Walls line the edge of the grid, so that the robot cannot wander off the edge of the world.
onDirt() returns true if there is dirt underneath the robot. Dirt is signified by purple paper.

There are five commands that the robot will accept: moveForward(), turnLeft(),turnRight(), suck() and shutdown(). These commands are implemented in the form of void members.

moveForward() moves the robot forward until one of the light sensors passes over a black line. Then, using the other light sensor, it attempts to align itself so that it is facing perpendicular to the black line. It then moves forward for a brief amount of time. If, during any of this time, the touch sensor is triggered, the robot will stop and back up.
turnLeft() and turnRight() simply turn the robot in the direction indicated for TURN_DELAY milliseconds. TURN_DELAY may be set in VacuumBot.java. suck() uses the internal speaker to play a buzzing sound, notifying you that it's trying to suck. Note that it doesn't actually pick up the dirt. Feel free to remove the "dirt" from the grid if your robot runs the suck function properly.
shutdown() doesn't actually work properly right now. I wanted it to exit the program, but kept getting errors with System.exit(0).

To help get you started, I've already written a simple agent, Agent.java, which is linked to above. Compiling Agent.java is similar to compiling Calibration.java, but you need to compile it with VacuumBot.java, because it makes use of the class and member functions contained in VacuumBot.java. To do this, you simply compile both java files at the same time:

K:\AISTUFF>lejosc Agent.java VacuumBot.java

Then send it to the LEGO brick:

K:\AISTUFF>lejos agent

Now place the agent on the home (blue) square on one of the maps. Press the run button and watch what it does. It should run along one of the sides until it hits a wall, then turn around and come back, running the suck() function whenever it is over dirt. If it doesn't, you may need to change some of the final ints in VacuumBot.java to reflect more accurately what the sensors' values are and how long it takes to turn ninety degrees. This is what Calibration.java will be useful for.

To calibrate the robot:

While you are working, remember that the sensors are sometimes touchy, and can lead you to frustrating results. Try to minimize the number of variables that you're working with - always use the same robot, try and keep the lighting in the room the same, (I always turn all the lights on and close both of the blinds), remember that battery power may affect the robot's speed and therefore the turning delay will be an issue.

Having major problems with your robot? Try looking at troubleshooting tips.

Your assignment

Reimplement the agent with internal state that you did during the vacuum world simulator assignment.

What to turn in

Turn in the java file AgentState.java. If you changed VacuumBot.java, submit the modified version of that as well.

Written by Andy Exley.
Modified by Dave Musicant.