Programming Lego Mindstorms with Java

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $1.99
Usually ships in 1-2 business days
(Save 93%)
Other sellers (Paperback)
  • All (13) from $1.99   
  • New (3) from $20.80   
  • Used (10) from $1.99   

Overview

Lego robots! The first book that teaches you to program Lego Mindstorms using Java
Lego Mindstorms are a new generation of Lego Robots that can be manipulated using microcomputers, light and touch sensors, an infrared transmitter and CD-ROMs. Since Lego launched Lego Mindstorms in late 1998 sales have skyrocketed - with no sign of slowing down. Mindstorms have captured the imagination of adults and children alike, creating a subculture of Mindstorm enthusiasts around the world. The kits are now a staple part of engineering and computer science classes at many high profile Universities.
Up until very recently, the only languages available to program Lego Mindstorms were NQC, pbForth, and legOS. This is the first book detailing how to program Lego Mindstorms using the newly released Java Virtual Machine for Lego Mindstorm programming. Programming Lego Mindstorms provides readers with all of the information they need to construct and program Lego Mindstorm Robots.

The first book available on how to program Lego Mindstorms with Java
Wallet-sized CD contains the programming code in Java
The CD will also translate the code into NQC, pbFORTH and legOS for readers who are currently using these languages, but are considering Java
The perfect gift for parents and kids alike - out in time for the Christmas rush!

This will be the first book detailing how to program Lego Mindstorms using the newly released Java Virtual Machine for Lego Mindstorms programming. The book will provide readers with all the information they need to construct and program Lego Mindstorms robots.

Read More Show Less

Editorial Reviews

From Barnes & Noble
Whether you're a Mindstorm novice or experienced user, this book is for you. It's also for people at varying programming levels, covering everything from the basics of programming the RCX to advanced topics such as embedded programming using a custom JVM. Unleash the power of this exciting system!
From The Critics
The Lego Company's robotics kit comes with a programmable component (the RCX) that contains software, but a number of hobbyists have begun to program their own software for the RCX. This handbook explains how to use Java to program the robotics kits, covering the Java communications API, communicating with the RCXPort API and the RCX Java API, the leJOS system (Lego Java operating system), programming for the leJOS environment, leJOS tool and internals, and programming the robotics kit with Jini. The CD-ROM contains all the source code from the book and RCXPort, a Java interface. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9781928994558
  • Publisher: Elsevier Science
  • Publication date: 6/8/2002
  • Edition description: BK&CD-ROM
  • Pages: 448
  • Product dimensions: 7.38 (w) x 9.29 (h) x 1.22 (d)

Meet the Author

Dario Laverde is currently a developer at ActionWorld, Inc. where he participated in the design and implementation of the PlayLink Internet Gaming System. Previous to Action World, he worked at InterWorld, Inc. where he developed a chat system (server and clients). Before that, he was a senior software and electrical engineer at Loral Electronics Systems for a number of years.
Read More Show Less

Read an Excerpt

Overview of the Java Communications Extension API (JCE API) The Java Communications API 2.0 was released in 1998 as the standard communication mechanism for serial (RS232/434) and parallel (IEEE 1284) ports using pure Java. That is, standard Java code will run across all compliant platforms, using the official interface. The current implementations are found in the following locations:


*Windows and Solaris http://java.sun.com/products/javacomm
*Linux www.vorlesungen.uni-osnabrueck.de/informatik/robot00/ftp/javacomm.html
*Mac OS http://homepage.mac.com/pcbeard/javax.comm.MRJ For the most part, communication is performed through standard input and output streams in Java. These streams are provided from the underlying ports through a common interface. All the ports extend a common abstract class (called CommPort) that provides the basic representation of a given port. This allows for standard mechanisms to open, read/write, and close ports. This is one of the two primary functions provided by the Java Communications Extension (JCE) API. The other is port management and ownership, which is described below.

Similar to other Java APIs, the JCE API makes use of the observer pattern; event notifications are triggered upon a change of port ownership, as are specific data notifications (as with the case of serial ports). The Java Communications Extension library primarily consists of one package: javax.comm.*. This library contains the classes, interfaces and exceptions listed in Table 2.1.

 Classes                         Interfaces                                                      Exceptions CommPort                        CommDriver                                                      NoSuchPortException CommPortIdentifier      CommPortOwnershipListener                       PortInUseException ParallelPort            ParallelPortEventListner                        UnsupportedCommOperationException ParallelPortEvent       SerialPortEventListner

SerialPort

SerialPortEvent

We will go into the architecture of the Java Communications API in greater detail later; but what stands out from the list at first glance are the event classes and event listener classes. This allows the framework to handle asynchronous notifications of not just specific serial port and parallel port events, but also of port ownership changes and updates. Hence one would know when a specific port is available, or one could wait until it is available or closed.The classes of note above (other than the encapsulation of serial and parallel objects of course) are the CommPort and CommPortIdentifier classes.

The CommPort is an abstract class that serves as the base class for all ports, enabling you to manage and handle all the ports in the same way. It contains the minimal and basic common methods that one would expect from all communication ports, except for one: open() is handled by the CommPortIdentifier. The CommPort’s notable methods are getOutputStream(), getInputStream(), and close().

This leads us to the CommPortIdentifier class through which we will create, manage and identify all ports. Think of this class as a port factory that allows you to discover and enumerate all the ports in the system and handle the ownership of those ports.

The CommDriver Java interface gives the developers of new communication port drivers the ability to add to the Java Communications API in a consistent manner. We will also examine how one would use this to add a new custom port.

Lastly, as listed in Table 2.1, there are custom Java exceptions in this API that allows for notification of errors specific to this framework that might occur: if a given port is already in use, if a requested port does not exist, and if a specific operation on a given port is not supported. One would think that all of CommPort’s abstract methods should be implemented by all ports, as they are a general list. This exception allows for any future type of port to be added easily, as the CommPort contract is not too rigid. For example, a future port XYZ, might not be expected to implement the abstract enableReceiveTimeout() method in the CommPort class if the underlying hardware cannot support this kind of behavior. Basically one would first test to see if a function is supported before trying to use it. If the unsupported exception is thrown, it can then be caught and handled gracefully.

Understanding the JCE Framework

As stated, the Java Communications API provides a clean and simple framework for allowing access to both serial and parallel ports from 100 percent Java code. This permits you to write applications ranging from modem software to custom printer drivers, or provide access from Java to a multitude of devices that interface with serial and parallel ports. These include devices ranging from mp3 players or video capture devices to home automation devices (such as X10 devices). Table 2.2 shows some of the features and limitations of the Java Communications API that will be addressed in the following sections.

Table 2.2 Features and Limitations of the Java Communications API Features                        Limitations Port Discovery and Enumeration  Limited to serial and parallel ports. Port Ownership Management       Difficult for third party implementations of new device protocols to be added to the core API. Asynchronous event based I/O    Initial configuration could be made easier. Clean encapsulation of underlying native ports for several platforms including Windows, Solaris, Linux and Macintosh

Port Discovery and Enumeration

In this section we will illustrate how to enumerate all ports available on a system. This is the first step with all applications that use the Java Communications API. The following classes and methods highlight the enumeration process:


*CommPort Provides input and output streams to the ports and is the base class to SerialPort and ParallelPort.
*SerialPort Extends CommPort to represent a RS232 serial port
*CommPortIdentifier Provides control of ports in a system. Serves as both a port identifier object and a port ID. Note this distinction which at first glance can be confusing. A port identifier object is not a port object but identifies and interfaces with an associated port object.
*public static Enumeration getPortIdentifiers() This static method will provide a complete identifier list of all ports (serial and parallel) on a system.
*public String getName() The name of this port identifier
*public int getPortType() The type of port this port identifier represents, namely one of the following:


*CommPortIdentifier.PORT_SERIAL
*CommPortIdentifier.PORT_PARALLEL The code shown in Figure 2.1 illustrates how the API is used to list all the available serial ports for the entire system (computer). This code can be found on the companion CD with this book. Figure 2.1 TestEnumeration.java

import javax.comm.CommPortIdentifier; import javax.comm.SerialPort; import javax.comm.PortInUseException; import java.util.Enumeration; import java.util.Vector; public class TestEnumeration {     public static void main(String args[]) {         Vector portslist = TestEnumeration.getAvailableSerialPorts();         System.out.println("found "+portslist.size()+" open ports");     }     public static Vector getAvailableSerialPorts() {         CommPortIdentifier pId=null;         SerialPort sPort=null;         Enumeration pList=null;         boolean foundport=false;         pList = CommPortIdentifier.getPortIdentifiers();         String port=null;         Vector ports=new Vector();         if(!pList.hasMoreElements()) {             System.err.print("warning: no ports found - ");             System.err.println("make sure javax.comm.properties file is found");             return ports;         }         while (pList.hasMoreElements()) {             pId = (CommPortIdentifier) pList.nextElement();             if (pId.getPortType() == CommPortIdentifier.PORT_SERIAL) {                 foundport=true;                 try {                 } catch (PortInUseException e) {                 } finally {                 }             }         }         return ports;     } Sample Output: >java TestEnumeration  COM1 is open  COM2 is open  COM3 is closed  COM4 is closed  found 2 open ports

Starting with main(), the call to the getAvailableSerialPorts() method will return a vector of strings of the available serial ports’ names. In this simple example, we get the vector and print its length, telling us how many serial ports there are.

As we step into the getAvailableSerialPorts() method, we find the usual first step for enumerating all the ports:

CommPortIdentifier.getPortIdentifiers() is called.

If no ports are found, a warning message is displayed; this is unusual and usually indicates a configuration problem, namely that the javax.comm.properties file is in the wrong place.

We then loop through the enumeration, checking the port type with each iteration. If it’s a serial port type, we open the port to see if it is available.

Now, why does CommPortIdentifier use the open() method in one step instead of first retrieving the port and then having CommPort invoke the open() method? This clarifies the concept that port discovery and control (ownership) must be done in only one central point: the CommPortIdentifier. Perhaps CommPortIdentifier should have been renamed to "CommPortManager" or "CommPortFactory," but then it would require breaking out the ID portion to a separate class; or perhaps the factory could have implemented it as an interface. A factory implementing an interface? Well okay, perhaps not, but nonetheless this chapter will mention CommPortIdentifier more than any other class, due to its many responsibilities.

Read More Show Less

Table of Contents

Chapter 1
Introducing LEGO MINDSTORMS
Chapter 2
The Java Communications API
Chapter 3
Communicating with the RCXPort API
Chapter 4
Communicating with the RCXJava API
Chapter 5
The leJOS System
Chapter 6
Programming for the leJOS Environment
Chapter 7
leJOS Tools
Chapter 8
leJOS Internals
Chapter 9
Programming LEGO MINDSTORMS with Jini
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)