CS 395 Fall 2002, Behavior-based Robotics

Group Assignment 0:
Familiarizing Yourself with the Robot

Out: Wednesday, October 2
Due: Monday, October 7

In this assignment, you will become familiar with the setup and use of the robot, and with its hardware capabilities.  You do not need to turn anything in for this assignment.  It's just to give you a chance to learn to use the robot before you have to do a real assignment.

Familiarizing yourself with the hardware

The first thing your group should do is to sign up for some time on a robot.  When your time comes, grab the robot you signed up for and take it to a comfortable place to work on the 3rd floor (probably one of the lounges).  Note that if you wheel (i.e. push) the robot, you need to push it slowly because pushing the robot turns the motors into electric generators and feeds voltages back into the control circuitry. While there are protection diodes in the control circuitry, you can still blow out a base push by pushing it too fast. If you find that the base has powered itself on while you were pushing it, that means you were going way too fast. If you find smoke coming out of it, then you owe us $6,000.

Now look at the top surface of the cylindrical part of the robot, where you'll find a display screen. Rotate the robot so that the screen is near you.  To the left, you will find a serial cable plugged into the base.  Now look to the right, where you will find a big red button. This is the kill switch. Pushing this button while the robot is running will immediately power down the robot's motors. Just below the kill switch is a smaller silver button. This is the control knob. When the robot is powered up, it acts as a kind of 1D mouse. However, with the robot powered down, it's just a power switch.

Powering up the robot

Here's the sequence you need to do to power up the robot base:

  1. Disconnect the serial cable to the left of the LCD display.
  2. Push the control knob to turn on the robot.
  3. Wait about 15 seconds and the display should power up and you should see a control panel.
  4. Now reconnect the serial cable.

Note: Be sure to remember to disconnect the serial cable before powering the base up. Failure to do so will not harm the base, but it will make it think that it's supposed to download a new version of its operating system from the base and so it won't boot. If this happens, open the batter doors and disconnect one of the batteries, then reconnect it, to power it down again.  Then disconnect the serial cable and continue the power-up sequence.

Powering down the base

Once the display powers up, look at the display. It will show a number of rectangular buttons with labels, one of which will be highlighted. Now grasp the control knob and rotate it. As it turns, the highlighting will move from button to button. Move it to the button that says "PWR" and press the control knob. That will bring you to the power control menu. Rotate the knob again until you get to the button that says "Kill Power" and press it. Now you know how to turn off the base.

Checking the battery voltage

Power the base back up again. When the display activates, look at the number in the lower right corner. This is the base battery voltage. It should read at least 22.5V. If it falls below this and you keep using it, we will have to kill you. So keep an eye on it.

If the base battery voltage falls below 22.5V: First, power off the base. Then examine the sides of the base. There are two doors built into the sides that are secured by small silver knobs. Turn these knobs to release the doors and reveal the batteries. If you have trouble opening the doors, it's not your fault. No one seems to have figured how to make good compartment doors for robots yet. Be persistent, and perhaps try pushing in on the door. When you get the doors open, you will see that the batteries are connected to the base by yellow power cables with white molex connectors in the middle that hook the battery's yellow cable to the base's yellow cable. The two sides of the molex connector are held together by a latch built into the plastic push down on the back of the latch to release it and pull the two sides apart. You can now remove the battery from the base.

Now carry the old batteries to the wall of chargers in the lab. Select two new ones swap them with the old ones, making sure that the old ones are connected to the chargers. Note that the molex connectors on the batteries, bases, and chargers are all "keyed" meaning that there's only one way that they'll fit together (the right way), so you don't have to worry about hooking anything up backwards. Carry the new batteries back to the base and slide them into the battery compartments, making sure that the yellow power cables don't get wedged in between battery and base. Now reconnect the molex and shut the doors, rotating the silver knobs to fasten them shut (this is the hardest part of the whole procedure, so don't feel stupid if you have trouble - we all do). Power the base back up and check to make sure the voltage is reasonable.

Releasing and setting the "brake"

Next to the voltage indicator, you should see another indicator that says "BRAKE: ON". That means that the robot's motors are disabled. When you run the robot, you will need to enable the motors. To do this, move the control knob so the cursor is over the "Brake" button and press the control knob. The base should now say "BRAKE: OFF". Now press the big red button and the indicator should go back to saying "BRAKE: ON".

Note: the name "brake" is somewhat misleading. You will notice that when the brake is "on" you can push the robot around, but when it's "off" you can't. That's because when the brake is off, the motors are active and the base is trying to maintain the last velocity is was commanded to maintain, which in this case is zero centimeters per second. So if you try to push it, the base will more or less think that it's rolling down a hill and try to generate a force with the motors to keep itself in place. In some sense, the brake is more like the clutch on a car: it "disconnects" the motors (powers them down, actually) and lets the wheels run free.

OK, now you know everything you need to know about the bases.

Booting the laptop

Now start the laptop booting. On the base, you will find two cables: a serial cable and a USB cable. Connect them both to their respective ports on the back of the laptop. and place the laptop in the cradle on top of the base.

Since the laptop only has a battery life of a couple of hours, you should plug it into its AC adaptor if it isn't already plugged in.  Then you should make sure that it's plugged in whenever you aren't specifically driving it around.

When the machine finishes booting, you will see a windows login prompt.  The machine is in the ILSPC windows domain, not in the CS domain, so your CS lab account won't work on it.  So just hit the escape (ESC) key when you see the login window.  You should get the default desktop on the screen.

The next thing you should do is to create a subdirectory for your group in the C:\cs395 directory so you have someplace to store your files.  Once you've done that, you're all set.

Learning Emacs

At the moment, our programming environment runs inside of XEmacs, which is the UberTextEditor from heck. Emacs is a very sophisticated editor that has the ability to be reprogrammed for a wide range of tasks using a macro language. This makes it good for programming because you can automate a number of editing tasks, like indentation or finding the declaration of a variable, using the macro language. You can also write mail readers, web browers, etc. in Emacs. You won't be doing any of this, but this at least explains why we use it.

To run XEmacs, find the icon on the desktop that says XEmacs and double-click it. When the emacs window pops up on the screen, type control-H and then press T to start up the automatic emacs tutorial.

Starting the programming environment

When you're done learning emacs, type M-x run-grl and wait for a new subwindow to be displayed with a scheme prompt.  This will start Scheme and make it load the GRL compiler and the drivers for the robot peripherals. When you see the ">" prompt, the system is ready to use.

Running code

You can type code directly into the *scheme* buffer.  However, you will often want to type code into separate buffers (files) so you can save it. When you type an expression into a different buffer, you can run it by putting the cursor inside of the expression and typing C-M-x (control-meta-x). That will cause emacs to copy just that expression to the paste buffer and send it to Scheme, although it won't appear in the scheme window.

If you are running some code and you want to stop it, type Control-break. That will interrupt the code and drop you in Scheme's debugger. You can get out of the debugger by typing F2.

Using the robot

Now you can try running some GRL code. You run GRL code using the try-signals macro. When you type "(try-signals GRL-code)", it compiles and runs the GRL code.

Try typing:

  (show-image (grab-grayscale-frames 160 120)))

A window should pop up showing you live video from the camera. Type Control-break to interrupt Scheme and F2 to get back to the top-level prompt. Now try trying:

(try-signals (show-pings))

The base should start clicking and another window should pop up showing brightly colored lines. The clicks are the sounds of the sonar transducers "pinging": sending out sound waves to sense the presence of objects, ad the lines show the sensed locations of the objects. You will probably notice that there are fewer lines than transducers (there are 16 transducers). That's because sound waves often bounce off of objects and keep going, so that the transducer never hears a return. You'll also notice that it seems to get some very odd readings. Those are because the sound wave bounces off and odd angles, but does come back eventually. When that happens, the robot thinks that it sensed a far-away object in the direction the transducer was pointing. It also thinks, then, that there must be free space between the transducer and the location it got the ping back from. So it over ends up missing walls completely.

Now press the kill switch, type Control-break to kill the program, then press F2, and get ready to type some GRL code. Open up a new file, making sure that its name has ".scm" at the end. The type the following code into the file:

(define-signal polly (polly-pipeline 'width 160 'height 120))
(define-signal follow-freespace
  (drive-base (polly-freespace-follower polly
                                        (rt-vector 50 400)

(try-signals (show-polly polly) (show-pings) follow-freespace)

Now put the cursor in the first line of code and type C-M-x. You should see another ">" prompt. If you get an error message, hit F2 and examine the line closely to make sure you typed it properly. Once you manage to get the first line to evaluate properly, move the cursor to next line and type C-M-x again. Again, you should get a > prompt.  Now you're ready to rock 'n roll. Put the cursor in the last line and evaluate it using C-M-x. A new window should pop up and start showing you a video image with annotations in weird colors.

Now do the following:

  1. Point the robot toward some free space
  2. Disconnect the laptop from the AC adaptor
  3. Turn off the brake.

The robot will start driving around. Try to keep close tabs on the robot. Working with the robot is not unlike keeping track of a toddler: you always need to be prepared to take action if it gets into trouble. Fortunately, robots have kill switches.  Always make sure that one team member is close to the kill switch.

Safety issues

When using the robot,

Exercise 1: Herding the robot

The program you are running is doing three things:

This gives you a primitive way of working with the robot when you want it to go somewhere: you can herd it. If you get too close to it on the left side, it with veer to the right. If you get too close on the right, it will veer to the left. If you don't want it to go forward, stand in front of it. Choose a place to guide it to and see if you can get it to go there by herding it.

Exercise 2: Learning how bad sonar is

Now do the following:

Get the robot driving down the hallway and see if you can get a sense of what kinds of features it does and does not pick up on. You want to try to learn to be able to predict when it will and will not see objects.

Exercise 3: Tweaking gains

Now you're going to get to do some actual programming. First, let's stop it. Hit the kill switch and type Control-break and then F2.

Now go back to the window with your code. The driving algorithm you're running is called a freespace follower because it tries to follow along big paths of free space in front of it. It works by taking the center height and multiplying it by a magic number called a gain to get a speed at which it should drive forward. The higher the height of the closest obstacle in the image, the faster it drives. As the obstacle gets closer, it slows down until it reaches a certain threshold distance called the stopping distance. In fact, I lied to you a minute ago, it subtracts the stopping distance from the center height before multiplying it by the gain.

As we said, it steers by balancing the left- and right-heights. What it really does is it takes the right height, subtracts it from the left height and multiplies the result by another gain. The resulting number is then sent to the base's steering motor to use as a speed to turn at. When there's more space on the left, it will turn left until the heights even out, and then it will stop.

So there are three magic numbers in this algorithm that you need to set properly to make it work. A lot of robotics is about tweaking magic numbers to try to get things to work and a lot of robotics research is about trying to come up with new ways of doing things that don't require tweaking so many numbers. The three numbers are encoded in the part of the file you typed that starts with "(define-signal follow-freespace ... ":

(define-signal follow-freespace
  (drive-base (polly-freespace-follower polly
                                        (rt-vector rotate-gain

Try running it now with a rotate gain of 50 and a translate gain of 100. Just change the numbers and type C-M-x. Let the base run for a little while until you get tired of it, then kill the base and stop the program. Now try increasing the rotate velocity without increasing the translate velocity. Make sure that the robot isn't close enough to any walls or obstacles that it's in danger of hitting something while turning, and let it go. Now stop it and increase the rotate gain again.

That's it for today. When you're done for the day, power down the base, shut down the laptop, and plug the laptop in to charge.