Robot Simulation

What’s Here?

  1. What Are the Robots Like?
  2. How Do You Program the Robots?
  3. So What Can You Do with the Robots?
  4. Why Would You Simulate the Robots?
  5. What’s the Simulator Like?
  6. Will the Simulator Work on My Machine?
  7. OK, Let’s Try It.
  8. Now What?

What Are the Robots Like?

Legobugs are mobile robots built from Lego. If you don’t come from the Galapagos Islands, then a Legobug is about the size of a tortoise. If you do come from the Galapagos Islands, then a Legobug is about the size of a Marine Iguana’s head. There are two motors, each controlling one of the rear wheels. As we have built them, there are 2 touch sensors, one at each of the front corners, and there are 5 photoresistor “eyes”. One eye points straight out from each side of the robot, and one faces straight back. There are also two eyes in the front, separated by a “nose” which casts a shadow.

How Do You Program the Robots?

Legobugs are programmed using Interactive C, a subset of the C programming language. The Handy Board computers on Legobugs have Motorola 6811 processors with 32k of RAM equiped with ports to control 4 motors and with input ports supporting up to 9 digital and 7 analog sensors. One writes Interactive C on a Mac or PC, then dumps the compiled code over a phone cable to the Handy Board. Then you disconnect the phone cable and turn the thing loose.

So What Can You Do with the Robots?

We’ve written IC programs that allow single Legobugs to explore a room by following the walls. We’ve also used the eyes to locate and drive up to a candle flame, then extinguish the flame by turning on a small fan. The robot then waits to make sure the fire is really out, and sets out exploring to find another fire.

Why Would You Simulate the Robots?

Our current project is writing code to allow a number of Legobugs to interact with one another. For instance, we’d like to put lights on each of the robots, and then tell them to try to move to an area where the light is not too bright and not too dim. Would they form swarms if we did this?

The trouble is that we only have 5 robots. Also, downloading code to 5 machines and turning them loose takes a while. So why not simulate on a computer what the robots would do if we had lots of robots and if we gave them various programs and turned them loose? We could use more robots than we have, and we could try things out a lot faster.

Also, I’m trying to learn Java right now, and this is as good a project as any to use.

What’s the Simulator Like?

Try it out to see. It’s crude, but I’m learning.

Will the Simulator Work on My Machine?

Technically speaking, maybe. I’ve tried to be careful, but getting this applet to work has definitely been a learning experience. I had hoped that Sun’s slogan, “Write once, run anywhere,” was an actual development strategy rather than a research direction.

It turns out that despite the fact that Java 1.1 has been out for a year, Netscape’s JVM still does not support large portions of it. This discovery caused me significant rewriting. At this writing, use of Java 1.1 by applet developers is definitely premature.

It is also the case that Netscape’s JVM bogs down rather quickly as the number of threads grows. This poses a problem for the simulator, which naturally uses a thread for each robot's control program. I’ve tried to tune the applet to work acceptably under Netscape by looking to see what browser you’re using, and setting some constants accordingly (just the sort of thing I thought Java was supposed to let one avoid). If you’re using Netscape, though, don’t try to use too many robots at once.

Although the lion’s share of my problems as a novice Java developer were caused by Netscape, there were in fact 2 or 3 points during the history of this project at which the 4 different JVMs at my disposal produced 4 different types of behaviour, ranging from working perfectly to suffering moderate glitches to failing even to launch. One should never assume that a platform or JVM against which one has not tested one’s code will work as expected.

Having said all this, it is only fair to add that the labor involved in writing this applet was more than an order of magnitude less than producing in C a comparable application running on the Mac, Windows, and Linux. We are not now in the promised land, but the Java project is moving us in that direction. It may even get us there before its alternatives do.

The range of systems and JVMs at my disposal is limited; I would therefore be very much interested in the experiences of anyone looking at this applet. Even a very quick note mentioning your OS, your browser, and whether it worked would be very helpful. Just drop me a line.

OK, Let’s Try It.

All right. Here are a few examples of robot behaviour.

Now What?

I wrote this simulator for fun and in order to learn Java. I don’t have plans for its future development. It is possible I will at some point add a few new features. Or not.


Back to school.