previous chapter table of contents next chapter

MINDSTORMS as a Jini Service

As previously mentioned, a MINDSTORMS robot can be programmed and run from an infrared transmitter attached to the serial port of a computer. There is no security or real location for the RCX ”it will accept commands from any transmitter in range. We will assume that a robot is controlled by a single computer, and that it always stays in range of this computer.

There must be a way of communicating with any hardware device. For a MINDSTORMS robot, this is done via the serial port, but other devices may have different mechanisms. Communication may be by Java code or by the native code of the device. Even if Java code is used, at some stage it must drop down to the native code level in order to communicate with the device ”the only question is whether you write the native code or someone else does it for you and wraps it up in Java object methods .

For the serial port, Sun has an extension package ”the commAPI- to talk to serial and parallel ports (http://java.sun.com/products/javacomm/index.html) . This package includes platform-independent Java code, and also platform-specific native code libraries supplied as DLLs for Windows and Solaris. I am running Linux on my laptop, so I am using a Linux version of the DLL. This has been made by Trent Jarvi (<trentjarvi@yahoo.com>) and can be found at http://www.frii.com/~jarvi/rxtx/ . The native code part of communicating with the device has been done for us, and it is all wrapped up in a set of portable Java classes.

The RCX expects particular message formats that start with standard headers, and so on. A Java package that makes generating messages in the correct format easier has been created by Dario Laverde and is available at http://www.escape.com/~dario/java/rcx . There are other packages that will do the same thing ”see the "LEGO MINDSTORMS Internals" Web page by Russell Nelson at http://www.crynwr.com/LEGO- robotics / .

With this as background, we can look at how to make an RCX into a Jini service. It will involve constructing an RCX program on a client and sending this program back to the server where it can be sent on to the RCX via the serial port. This program will then allow a client to control a MINDSTORMS robot remotely.

The Jini part is pretty easy ”the hard part was tracking down all the bits and pieces needed to drive the RCX from Java. With your own lumps of hardware, the hard part will be writing the low-level code (probably using the Java Native Interface, JNI) and Java code to drive it.


A Programmer[ap]s Guide to Jini Technology
A Programmer[ap]s Guide to Jini Technology
ISBN: 1893115801
Year: 2000
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net