Search:
Locator+ Code:
FTPOnline Magazines Newsletters Resources Partner Sites About FTP
Archives
 
 
 
 
 
 
 
 



Programming LEGO Mindstorms with Java
by Giulio Ferrari et al.

Quick Facts
AUTHOR: Giulio Ferrari et al.
PUBLISHER: Syngress Media Inc.
ISBN: 1-9289-9455-5
PAGES: 464
PRICE: $29.95

Programming LEGO Mindstorms with Java by Giulio Ferrari et al. is a must for the robotics enthusiast wondering how to marry an enjoyment of robotics with an interest in Java programming. For those unfamiliar with the LEGO Mindstorms, they are robots whose bodies are assembled with the familiar LEGO building blocks, augmented by sensors, motors, and a microprocessor brain. The modularity of LEGOs let you disassemble and reassemble new robots rapidly, and you can just as readily alter the software that controls the robot.

You program a Mindstorm robot remotely; your development station is a desktop PC outfitted with software and communications hardware. An infrared transmission tower is the host side of the link, and the Mindstorm's microcontroller board (referred to as the RCX) has an onboard infrared port. (Early Mindstorm kits used the RS-232 serial port as the link between the host and the tower; the latest version uses USB as the link.)

The standard control language for Mindstorm robots is the LEGO programming language. However, the architecture of the microcontroller allows for using other languages, which is precisely the thrust of the book: how you can use Java as a Mindstorm robot's control language. Much (though not all) of the book covers leJOS, the LEGO Java Operating system. leJOS is a complete run-time system. You develop leJOS programs on the desktop and download them to the robot for execution.

Though the book's focus is on Java programming for Mindstorm robots, it covers a variety of other topics, some of which are ancillary to programming the Mindstorms. Consequently, some sections will be interesting even to those Java programmers not planning on building a robot. For example, chapter 2 covers the Java communications API, and chapter 9 gives a good overview of Jini.

The book tackles its subject from the outside in. After an introductory overview of the Mindstorm architecture, the authors examine the Java technologies needed to communicate with the robot. USB—the link used in the latest version—is certainly superior to RS-232 in regard to throughput, but is problematic for control through the Java Communications API library, which supports only serial and parallel ports. Luckily, in chapter 3 the authors unveil extensions for the Java Communications API that handles USB. The result is a library that provides a unified interface for communicating with both old and new Mindstorm versions. Once communication with the robot is established, the authors move on to programs illustrating how to execute code on the robot directly, that is, by passing short strings of bytecodes to the robot for immediate execution.

The leJOS operating system replaces the RCX firmware so that Java bytecodes become the executable code on the robot. Of necessity, the virtual machine (VM) on the robot runs a Java subset. For example, while the VM does support multithreading, it does not run the bytecodes necessary to provide for a switch statement. This condition isn't so hard to bear; what's less easy to bear is the VM's lack of a garbage collector. (The authors try to soothe us by reminding us that this deficiency is not entirely pathological. JavaCard does not support garbage collection, and memory space on the RCX is more like the amount you can expect on a JavaCard than on a system that could support the KVM. Carefully planned allocation of objects can make life in such conditions bearable. Nevertheless, the authors hint that a future release of leJOS will have garbage collection.)

Programming LEGO Mindstorms with Java is a fine book all around. The summaries and FAQs that conclude each chapter are particularly good. Mindstorm enthusiasts who simultaneously hold an enthusiasm for Java should add this book to their libraries.

—Rick Grehan

Back to top

Printer-Friendly Version



Sponsored Links


Java Pro | | Visual Studio Magazine | XML & Web Services Magazine
| | Discussions | Newsletters | FTP Home