RCX Java API


A platform independent Java library used to develop RCX applications

For general information on Lego Mindstorms Robotics visit http://www.crynwr.com/lego-robotics first


The current version of the RCX Java API is 2.1
.

See:
          Description

Packages
rcx Provides classes and interfaces for handling and supporting communication with the Lego Mindstorms RCX (versions 1.0 and above)

These classes use the Java Communications API for communicating via the serial port (for RCX version 1.0 or 1.5) as well as the USB port (RCX 2.0 and above) by using the rcx.comm package

In addition to supporting these ports, the architecture abstracts the ports to allow for new types of RCX ports such as a TCP socket port for remote communication and a high level abstraction to motors, sensors and sounds

An emulation mode is also available for developing and testing without an RCX.
rcx.comm Provides classes and interfaces for handling and supporting the USB port on various platforms for the Lego Mindstorms RCX tower (version 2.0+)

These classes abstract the underlying native USB drivers and provides a mechanism similar to the Java Communications Extension API for discovering and managing USB Ports.

 


A platform independent Java library used to develop RCX applications



For general information on Lego Mindstorms Robotics visit http://www.crynwr.com/lego-robotics first


The current version of the RCX Java API is 2.1
.
Description: The RCX Java API provides a high level API that communicates with the Lego Mindstorms RCX via the infrared tower which connects to a computer either by the serial port or usb port depending on whether you have RCX 1.0,1.5 or RCX 2.0. This library will manage and hide the low level protocol details and provide an easy to use interface for controlling a RCX robot.


Download:

This Java library is available as rcx.jar which is available as a free download in the following zip file here:

rcxjava2.1.zip - last updated  3/14/02 - changes.txt

This zip file includes all the examples shown in the following sections as well as many additional ones.

Note: this release comes with open source code that uses the LGPL license


Installation and configuration:

To run an application from the command line: (the Test example source code follows below)

java -cp rcx.jar Test [portname]

If you have the serial port tower (RCX 1.0,1.5) you need to install the Java Communications Extension API.
You would then copy the properties file, javax.comm.properties and the native library (e.g. win32comm.dll) as well as the actual library, comm.jar, to your current working directory and run a test from there as follows:

java -cp rcx.jar;comm.jar Test [portname]

You can obtain the Java Communications Extension API for the Windows and Solaris platforms from:
http://java.sun.com/products/javacomm

For Linux, one source for JCE is: http://www.vorlesungen.uni-osnabrueck.de/informatik/robot00/ftp/javacomm.html
And for the MacOS, one source for JCE is: http://homepage.mac.com/pcbeard/javax.comm.MRJ/

Note:  You can place the comm.jar in the \lib\ext folder of your Java Runtime Environment to avoid referencing it.

Example Usage of RCX Java API:

The following is a simple example of how to use the RCX Java API to control a Lego Mindstorms Robot:
import rcx.*;

public class Test {

    public static void main(String[] arg) { 
        new Test(arg[0]);
    }

    public Test(String portname) {
        RCXPort port = new RCXPort(portname);
        Motor.A.forward();
        Motor.A.stop();
        port.beep();
        System.out.println(
         "Battery Level = "+port.getBatteryPower()+" volts.");

    }
}
In the example above the port name is passed from the command line. The port name is the name of the actual port. For example, on the Windows platforms this would be COM1 to indicate a serial port or LEGOTOWER1 to indicate a USB port.

In addition to these two types of RCX ports, polymorphism is demonstrated further by passing in a custom port name for remote control via sockets as shown in the advanced example below. One can reuse the same exact code to run in a standalone application or in a remote applet. In the following case the same AWT panel, RCXControl.java, can be used in an application where the port name is supplied via the command line, RCXControlApp.java, or in an applet, RCXApplet.java, where the port name is provided on the html page via an applet tag parameter.

<applet codebase="." code=RCXApplet.class archive=rcx.jar width=275 height=125>
    <param name=rcxport value="rcx://localhost:174">
</applet>

The following screen shot shows the applet in a browser:

images/RCXApplet_screen.gif

To run this example the proxy server provided by the RCX Java library is required:

 java -cp rcx.jar rcx.RCXServer [portname] [portnumber]

Where portname is the name of the local rcx port (e.g. COM1 or LEGOTOWER1) and port number is the server port number that the applet client connects to (default value is 174). To run the client open test.html which is provided in the distribution.


For more documentation please refer to the javadoc documentation for the RCX Java API.


For further information on the history, architecture and design considerations of the RCX Java API, a detailed analysis of the Java Communications API with the trials and tribulations of extending  that API  (why it is no longer possible or supported) as well as the design considerations when adding USB support, refer to the following book now available:

Programming Lego Mindstorms with Java images/book.jpg

Publisher: Syngress Publishing

ISBN: 1-928994-55-5




Not only is the RCX Java API covered but several other Java APIs for the RCX including leJOS which is a custom Java VM that can run inside the RCX, allowing you to run Java tasks inside the RCX.

The accompanying CD contains all the required software including additional example code for the RCX Java API (e.g. using AI with RCX robots).


This documentation is also available in the zip file distribution.
It was generated using the javadoc utility of the Java 2 SDK 1..4.0



Copyright 1998-2002 dario laverde