Chapter 1: Getting Started
Welcome to Dave Baum's Definitive Guide to LEGO MINDSTORMS. This book represents a journey through the exciting world of LEGO MINDSTORMS. We'll start slowly at first, introducing basic concepts and techniques, then proceed to constructing and programming a number of different robots. By the end of the book, you will be well prepared to build your own robotic creations.
if you haven't yet played with your LEGO MINDSTORMS Robotics Invention System, you should take a few moments now to open it up, read through the Quick Start card, and take care of the mundane tasks such as installing batteries and hooking up a serial cable. More detailed information on these tasks can be found in the first few chapters of the User Guide supplied with the set.
This chapter introduces the RCX (the brains inside a MINDSTORMS robot) and the programming environments featured in this book. A simple test program will be created, then downloaded and run on the RCX. This test program serves as a convenient way of controlling a motor for some of the examples in subsequent chapters.
This chapter assumes that the infrared (IR) transmitter-included in the LEGO MINDSTORMS set-is already hooked up to your computer, and that batteries are installed in both the IR transmitter and the RCX itself. When communicating, the IR transmitter and the RCX should face one another, about 6"apart. Communication can be adversely affected by direct sunlight or other bright lights. If communication between the IR transmitter and the RCX is unreliable, try adjusting the position of the RCX and shielding it from unwanted light.
Programs for the Rcx are created on a personal computer (called the host computer), then downloaded to the RCX. The RCX can then run these programs on its own without further intervention from the host computer. There are a number of different programming environments that can be used to create RCX programs. The software included with the Robotics Invention System can be used to write programs in RCX Code, which is an easy-to-use, graphical programming environment. Although limited in functionality, RCX Code does provide a friendly, intuitive way for beginners to start programming the RCX.
Not Quite C (NQC) is a more traditional, text-based computer language that can also be used to program the RCX. Versions of NQC for Windows, MacOS, and Linux are provided on the accompanying CD-ROM. NQC takes a little longer to learn, but it provides much more power than RCX Code.
RCX Code and NQC are the two languages featured in this book. Sample code is usually provided for both languages, although in some of the more complex cases only an NQC example is possible. Descriptions of some other programming environments can be found in Appendix C.
The original version of the Robotics Invention System was set #9719. Recently, an updated version called Robotics invention System 1.5 has been introduced (#9747). There are several differences between these two versions. The 1.5 version comes with updated software, new instructions, and a slightly different mixture of LEGO pieces. owners of the original version can upgrade to the 1.5 version. See Appendix A for more information.
For the most part, the material in this book applies to both the original and 1.5 version of the Robotics Invention System. There are, however, a few exceptions.
- Two of the projects require pieces from the original set that are not present in the 1.5 set. Further information on obtaining these parts can be found in appendix B.
- The appearance of several of the RCX Code blocks has changed in 1.5. The book uses 1.0-style blocks for illustrating RCX Code programs, so programs written with 1.5 software will look slightly different (although they will behave the same). The most significant changes occur in my commands, which are explained in chapter 7.
- Several limitations for RCX Code programs have been removed in 1.5. Most notably, stack controllers may be nested and my commands can call one another. This is explained further in chapter 7.
- The RCX in the 1.5 set cannot be powered from an external AC adapter.
The next few sections will guide you through the installation and use of NQC. If you wish to use RCX Code instead, you can skip to the section titled RCX Code Quick Start later in this chapter.
When the RCX is powered up for the first time, a special piece of software called firmware must be downloaded to the RCX. This firmware provides a sort of operating system for running your own programs. if you write programs in RCX Code, the firmware will automatically be downloaded whenever it is needed. If you use NQC, you must download the firmware manually. If the RCX's display looks like the illustration below, firmware has not yet been downloaded. once it is loaded, the RCX will remember the firmware even when it is turned off.
The firmware itself is on the Robotics invention System CD-ROM (not this book's CD-ROM) in a folder named FIRM. The name of the file depends on its version number. As of this writing, the current firmware file is FIRM0309.LGO; however, it is conceivable that a newer firmware version will be on future CDs. Check your own CD or use the latest file in the FIRM directory. There are actually several different NQC programming tools, and each of them has differ_ ent ways of downloading firmware. Details are provided in the Using RcxCC, Using MacNQC, and Using NQC for Windows sections below.
NQC Quick Start
NQC is a textual computer language. Programs are written in an editor, then compiled and downloaded to the RCX. The NQC compiler is primarily available as a command line tool. This means that it must be invoked by typing the proper commands into a command shell (such as the MS-DOS Prompt for Windows 95/98). Integrated Development Environments (IDEs), which provide a program editor and a graphical user interface to the NQC compiler, exist on some platforms. RcxCC is one such IDE that runs under Microsoft Windows, and MacNQC is a Macintosh-based IDE (both are included on the accompanying CD-ROM). IDEs make using NQC a bit easier and more friendly, and they are, in general, the preferred solution where available. One important point, however, is that all of these solutions use the exact same language to specify an NQC program. For example, a program written with RcxCC can also be used with the Linux version of the NQC compiler. Quick Start information is provided for three different versions of NQC: RcxCC, MacNQC, and NQC for Windows.
Using MAC RcxCC relies on one of the software components normally installed by the RCX Code software. For this reason, it is advisable to install the RCX Code software prior to using RcxCC. Refer to the Robotics Invention System User Guide for more information on installing this software.
RcxCC has its own folder within the Tools folder of the CDROM. To install RcxCC, run the Setup.exe program found within the RcxCC folder. After installation, an RCX Command Center folder will be added within the Start menu's Programs folder.
When you launch RcxCC it will display a dialog box that allows you to specify which serial port the IR transmitter is connected to. You can either select the appropriate COM port or let RcxCC automatically check each port and decide for itself. The dialog box also allows you to choose between Mindstorms; and CyberMaster. Assuming that you are using an RCX, you may leave this item set to Mindstorms. Make sure the RCX is turned on and facing the IR transmitter, then click the OK button.
if RcxCC has trouble communicating with the RCX it will display an error and let you try again. If you click Cancel, RcxCC will still start, but those functions that require communication with the RCX (such as downloading a program) will be disabled.
Once started, RcxCC will show two windows: the main window and a floating templates window. The templates window is a sort of cheat sheet for remembering the various NQC commands. For our present example we can ignore it.....