Home > Store

Core LEGO MINDSTORMS Programming: Unleash the Power of the Java Platform

Register your product to gain access to bonus material or receive a coupon.

Core LEGO MINDSTORMS Programming: Unleash the Power of the Java Platform


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 2002
  • Dimensions: 7" x 9"
  • Pages: 560
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-009364-5
  • ISBN-13: 978-0-13-009364-6

LEGO Mindstorms robots can do more than you ever imagined! The secret: go beyond the built-in tools, and leverage the full power of Java -- the world's hottest programming language. Core LEGO Mindstorms shows you how, step-by-step -- as you build sophisticated robots and custom sensors that will amaze you. No matter what version of LEGO Mindstorms you own -- 1.0, 1.5, 2.0, even the USB version -- this book will take you farther than ever before. Brian Bagnall guides you through installing leJOS, a full-fledged Java Virtual Machine for the programmable RCX "brick" that gives LEGO robots their intelligence. Next, you'll master each key programming task step-by-step, with practical examples and photographs. You'll master behavior control programming, a simple but brilliant concept developed at MIT. Then, working from beautifully rendered 3-D plans, you'll walk through constructing five unique robots, each capable of increasingly powerful navigation. In later chapters, you'll walk through building and programming powerful custom sensors, including proximity sensors -- and even the "Holy Grail" of navigation sensors: the compass sensor. Bagnall concludes by introducing several powerful new techniques for advanced programmers.



For your convenience, you can download the complete set of code examples from the book in a compressed archive. The code is available in three compression formats:

Code Examples .zip
Code Examples .tgz
Code Examples .sea.hqx

Sample Content

Online Sample Chapters

Lego Mindstorms Programming: RCX Communications

Navigation in LEGO MINDSTORMS Programming

Table of Contents




Enter MINDSTORMS. The Robotics Invention System. RCX Brick. IR Tower. Motors. Sensors. LEGO Parts. Building Tippy. The RIS CD Software. The World of MINDSTORMS. ROBOLAB(tm). LogIT Sensors. Technic. Robotics Discovery Set. Vision Command. RIS Expansion Sets. Code Pilot. Droid Developer Kit. Dark Side Developer Kit. CyberMaster. Ultimate Accessory Kit. Ultimate Builders Set.

2. Getting Started with leJOS.

leJOS Overview. JVM. RCX Platform Extensions. Java API. Robotics Programming. Installing leJOS. Windows 98/Windows Me. Windows NT/Windows 2000. Linux. Macintosh OSX. Testing leJOS. Creating and Running a Program. Uploading More Than One Program. Setting Up an IDE. JCreator (Windows Platforms). How leJOS “Stacks Up”. NQC. PbFORTH. LegOS. Visual Basic. leJOS vs. TinyVM.

3. Learn Java in 2.4 Hours!

Java Core Language. OOP. Source Files. Classes. Interfaces. Import and Package Statements. Methods. Overloading Methods. Fields and Variables. Naming Rules. Operators. Program Flow Control. The java.lang Package. Math. Object. Runtime. String. StringBuffer. System. Threads. Throwable. java.util. BitSet. Hashtable. Random. Vector.


josx.platform.rcx. Button. LCD. MinLCD. Motor. ROM. Sensor. Serial. Sound. MinSound. TextLCD. The josx.util Package. Timer. josx.robotics. java.io and josx.platform.rcx.comm..

5. LEGO 101.

RIS Parts Library. Bricks. Classic LEGO Bricks. Technic Beams. Specialized Bricks. Slope Bricks. Plates Overview. Rectangular Plates. Plates Overview. Specialty Plates. Pins. Tires, Wheel Hubs, and Treads. Axles. Axle Accessories. Gears. Pulleys. Pulley Drive Belts. Lift Arms. Other Parts. Common LEGO Structures. Chassis. Caster Wheels. Ratchets. Single Motor Navigation. Walking Mechanism. Building Philosophy 101.

6. Behavior Control.

Behavior Control Theory. Programming Behavior with leJOS. The Behavior API. Advanced Behavior Coding. Coding Foolproof takeControl() Methods. Coding Solid action() and suppress() Methods.

7. Navigation.

Understanding the Problem of Navigation. Navigation Theory. Trigonometry. Using the Navigator API. Creating a Navigator Robot. Building the Trilobot. Programming Trilobot. TimingNavigator Accuracy. Systematic Errors. Nonsystematic Errors. Summary.

8. Navigation with Rotation Sensors.

Understanding Rotation Sensors. Trailer Odometer. Handheld Odometer. On-Axle Odometers. Off-Axle Odometers. Angle Measurement. Using the RotationNavigator Class. Creating a Navigator Robot. Building Instructions. Programming Tippy Senior. RotationNavigator Accuracy. Systematic Errors. Nonsystematic Errors.

9. Proximity Detection.

Creating a Simple Proximity Sensor. Programming the Sensor. Reliability. Creating a Distance Sensor. The Sharp GP2D12 Sensor. A Primer in Electronics. Building the Distance Sensor. Permanent Assembly. Enclosing the Circuit. Programming the Proximity Sensor Driver. A Wall Follower.

10. Navigation with a Compass Sensor.

The Compass Sensor. Theory of Calculating Direction. Building the Compass Interface. Tools. Circuit Assembly. Testing the Circuit. Programming the Compass Class. Calibration. Compass Driver. Programming CompassNavigator. A Robot Using the Compass. Chassis. Compass Basket. Front Bumper. Final Assembly. Compass Accuracy.

11. RCX Communications.

The Communications API. InputStream. DataInputStream. DataOutputStream. DataPort. PCDataPort. RCXDataPort. Installation. IDE Setup. Uploading Map Data. Controlling the RCX Through a Network. Controlling the RCX from a Web Page. Installing a Web Server. A Simple Project. Alternate Data Transfer Methods. Alternate Communication Uses.

12. Advanced leJOS Topics.

Memory Issues. Monitoring Memory Use. Programming Efficient Code. Hacking leJOS to Save Memory. Performance Tips. Alternate Languages for the JVM. Using NetRexx on the RCX. leJOS Architecture Overview. The Firmware. The API. The Linker. Modifying and Recompiling the Firmware. Adding Native Methods. Portability of leJOS.

Appendix A. Parts and Kits.

LEGO Shop At Home. Pitsco LEGO Dacta. LogIT Sensors. Mindsensors.

Appendix B. Electronics Projects.

Electronics Sources. Europe. North America. International. Distance Sensor Parts. Europe. North America. Compass Sensor Parts. Europe. North America. Compass Sensor Circuit Building. Experimentor Board. Punchboard. Etched PC Board.

Appendix C. Utilities.

leJOS Binaries. lejosc.exe. lejos.exe. lejosfirmdl.exe. lejosrun.exe. emu-lejos.exe. emu-lejosrun.exe. lejosp.exe. lejosp1.exe. lejosc1.exe. emu-dump.exe. leJOS Utilities. RCX Direct-Mode. RCX Download. Bricks Music Studio. Text to LCD Display. leJOS Visual Interface. LEGO Utilities. Ldraw. MLCAD. L3P. LEO Cad.

Appendix D. Internet Resources.

leJOS Resources. leJOS Home Page. leJOS Project Development Home Page. Java Resources. Sun's Official Java Site. LEGO Resources. LEGO Users Group (LUGNet). RCX Resources. RCX Internals. Analysis of the RCX. Sensors and Actuators. Distance Sensor. Compass Sensor. Homebrew RCX Sensors. Resistor Color Bands. RCX Projects. Rubik's Cube Solver (and More). LEGO Robotics Network. Robot Navigation. Mobile Robot Positioning. Dead Reckoning Contest. Other Hardware. Tower Hobbies. Draganfly.




There are 718 LEGO pieces in the latest version of the Robotics Invention System. Depending on how you look at it, 718 can either seem like a large number or a small number. In the grand scheme of things, 718 seems like a small number to me. Of those pieces, 129 are unique LEGO parts (not including color differences). Looking around me, I'd say the Robotics Invention System can build a decent representation of just about everything in this room. It can build a desk, a chair, a primitive speaker, a spinning globe, a blender, a clock (digital or analog), or probably even a simulation of a CD player. Outside my domain, the kit could produce models of automobiles, subway cars, boats, or almost any man-made machine. Looking to nature, it could create simulations of spiders, ants, scorpions, dogs, cats, and whales. True, the kit by itself can't reproduce everything in the world. It can't reproduce the envelope of a helium balloon or a complete BMW assembly line, but the things it can't do are far outweighed by the things it can. And there are probably things it can build that no one has ever thought of! I'm going to go out on a limb and estimate that 718 pieces can create an infinite number of models. From this logic, it's easy to see that 718 equals infinity.

It's no exaggeration to say that LEGO MINDSTORMS has done for robots what Henry Ford did for automobiles. LEGO has managed to put robots in the hands of ordinary people. The standardized parts and common languages means sharing of ideas in robotics is happening on a scale that has never occurred before. A brief search of the web to shows just how much MINDSTORMS has permeated through cyberspace.

If you already own the Robotics Invention System, congratulations! You have almost everything you need to create some amazing robots. The only remaining tool you need is a truly powerful programming language, and that is what this book will present to you. The language is Java, one of the most universally accepted programming languages in computers today, and this book will show how to use Java to push MINDSTORMS to the limit.

This book is not a compilation of projects, (of which there are several good ones on the market). The aim of this book it to give you the knowledge and tools you need to turn your ideas into reality, not someone elses. All the projects in this book are presented because they have some sort of lasting value. If this book has done its job, hopefully you will be surprised by what you didn't know MINDSTORMS could do.

This book will also solve the greatest mystery of the MINDSTORMS kit-what the grey foot-pedal looking part is for (see Figure below). To my know-ledge, no one has yet discovered what this part does or how it is used. Not even the actual LEGO MINDSTORMS engineers who designed the part understand what it is for. Chapter 5 will answer this age old mystery.

About this Book

Chapter 1 is an introduction to the Robotics Invention System. This chapter covers just the main components of the kit, including software, the RCX brick, and the IR tower. It also introduces other kits and products that can expand your MINDSTORMS universe.

Chapter 2 is a basic introduction to leJOS, the Java platform for the RCX brick. It covers a bit of background on leJOS, the basic features that distinguish it from other RCX development tools, and instructions on how to install leJOS as well as a powerful IDE.

Chapter 3 is a high-speed introduction to Java. Those who are familiar with Java may opt to just skim the Notes and Warnings, which point out differences between leJOS Java and Sun's Java.

Chapter 4 demonstrates, through code examples, how to access motors, sensors, and other components of the RCX brick using Java.

Chapter 5 is an encyclopedia of the Robotics Invention System parts. It goes through each of the 129 unique parts of the kit so you can put a name to the part and identify all the uses. If you ever wondered what the other versions of the kit contained, this is where you can find out. There is also a section on common LEGO structures that will help you to rapidly build key structures.

Chapter 6 introduces the concept of Behavior Control programming, a technique of programming insect level, behavior based intelligence. The leJOS API contains several classes for programming your own behavior control, making this an easy and powerful addition to robotics programming.

Chapter 7 begins the concept of navigation. The first part of the chapter lays out the fundamental concepts of navigation and tries to impress upon the reader a true understanding of just what it is about navigation that makes it so difficult for robots. It then moves on to real world examples of navigation programming using leJOS.

Chapter 8 continues the topic of navigation, but this time using a pair of rotation sensors to achieve even more accurate navigation than possible with timing methods.

Chapter 9 presents unique ways of detecting objects before the robot collides with them. The first part of the chapter shows how to build a simple proximity detector using only the pieces contained in the kit. More ambitious MINDSTORMS users can build an accurate distance sensor from raw electronic components. I have endeavored to make the instructions for assembly as clear, simple and precise as possible so even those completely unfamiliar with electronics will be able build this powerful sensor. The last part of this chapter shows how to build a classic robot project, the wall follower.

Chapter 10 is the third and final chapter dealing with navigation. This chapter shows how to assemble a compass sensor, which is useful for determining the orientation of the robot using the earths magnetic field. Though more difficult than the proximity sensor, this sensor worked the very first time I plugged the components into the bread board, so most readers shouldn't encounter any problems with this project.

Chapter 11 introduces the topic of communications. The RCX is capable of communicating with other devices that use Infrared signals. This includes the PC, the LEGO Remote Control, and other RCX bricks. The powerful java.io API is available on the leJOS platform, making communications with a PC that much easier. This chapter also shows how to control the RCX brick from a PC across the Internet using a remote program, an embedded applet, or from a plain old web page.

Chapter 12, the final chapter of the book, covers advanced topics. Here you can learn everything you never wanted to know about leJOS. Since memory is always on the mind of an RCX programmer, this chapter describes memory saving strategies that can help you squeeze that last little bit of code on board the RCX. Another interesting aspect of the leJOS JVM is that Java is not the only language that it can execute! The leJOS JVM is also capable of running other languages, such as Forth, NetRexx, and dozens of others. There is also a writeup on how to port leJOS to other processors, something for only the most advanced users.

The appendices will give you some valuable information on leJOS and the RCX. There is a section on ordering sensors, kits, and other parts you may not even have known existed. Ordering electronics parts can be such an art-form that an entire Appendix is dedicated to this topic. There is also a section on the burgeoning utilities available for leJOS. Finally, no book on LEGO MINDSTORMS would be complete without a section of web resources.

Companion Web Site

This book has a companion Web site to provide you with updates and other material. It is located at www.phptr.com/bagnall



Below you will find updates and errata corrections.

Chapter 1

  • Pages 7-8. The RIS 1.5 does not contain an RCX 1.5 brick. It contains an RCX 1.0 brick without an A/C adapter port.
  • Page 53. Brake mode uses little or no battery power. The technical explanation is as follows: The motors are accessed via H-bridge. Braking the motor is accomplished by a short-circuit between both motor pins. (You can test this with a motor.) The braking effect is produced through the attempt of turning the motor-axle. The motor generates an electro-motive force with an opposite sign to the axle-motion. So, the only power consumption consists of what is added to the motor-axle and not from the power-supply. (Explanation courtesy of Claude Baumann.)
  • Page 54. The Prgm button selects the program, not View.

Chapter 2

Page 80. legOS currently allows floating point operations.

Chapter 7

  • Page 235. A loop needs to be added to the end of the main() method: for(;;);
  • Page 236: A loop needs to be added to the end of the main() method of both programs on this page: for(;;);

Chapter 8

Pages 280-281. The code for robots that use Navigator classes is highly interchangeable, however since Trilobot uses two bumper sensors and Tippy Senior uses only one sensor, the code must be altered slightly. To fix this, remove the LeftBump and RightBump objects, then replace them with a single Bump class that uses input S2 instead of S1 and S3.

Chapter 11

  • Some changes have been made to the leJOS communications API:
    • josx.platform.rcx.comm has been changed to josx.rcxcomm.
    • pc.irtower.comm has been changed to josx.rcxcomm.
    • RCXDataPort and PCDataPort have both been changed to RCXPort.
    • The RCXPort() constructor throws an IOException.
    • For specific changes, please see the source code for Chapter 11.
  • Pages 425 to 426. You do not have to install the Javacomm API. The new version of leJOS contains native methods to handle communications with the USB and Serial ports. The PC side JAR file must be placed in the classpath, however. Please consult the leJOS readme for full leJOS Comm API installation instructions.

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020