The RIS software simplifies this process in two important ways. First, it provides a graphic
programming environment that's very accessible, particularly for people who haven't
programmed before. Second, programs are downloaded to the RCX over the IR link and
stored in RAM. This feature eliminates the complexity of dealing with memory chips and
burners yourself.
The cross-compilation step is a little different, too, because RCX programs are bytecode
rather than machine code. But it's still cross-compilation: the end result is bytecode rather
than H8 machine code.
A Day in the Life of a Program
Let's examine the typical life of a robot program:
1. The program's life begins when you create something in RCX Code. RCX Code compiles your program to bytecode.
2. RCX Code uses Spirit.ocx to download the program to one of the RCX's five program slots. The compiled bytecode is transferred to the RCX via the IR link.
3. The program is now available in RAM. When you run it, the firmware interprets the bytecode in your program and performs the appropriate tasks.
NQC Overview
Where does NQC fit in? NQC is a replacement for the software on the PC, both RCX Code and Spirit.ocx. NQC source code is stored in simple text files, just like C, C++, or Java source code.
NQC compiles these source files to bytecode and can download them to the RCX using the IR tower. NQC is a good way to overcome the limitations of RCX Code. But because it produces
bytecode programs, it's still subject to the limitations of the firmware's bytecode interpreter.
Because NQC talks to the IR tower directly, without depending on Spirit.ocx, it is very portable. NQC runs on MacOS (using MPW), Linux, and of course Windows 95, 98, and NT. RCX Code,
by contrast, only runs on Windows.∗
NQC was developed by Dave Baum, who maintains the official web site at
If you're using NQC on Windows, you might want to also use RCX Command Center (RcxCC). RcxCC is a Windows application that wraps around NQC. It provides a syntax-colored program
editor, push-button compilation and downloading, real-time control of the RCX, and a host of other useful features. Although NQC is fairly easy to use all by itself, RcxCC gives you an even
smoother ride. See the "Online Resources" at the end of this chapter for a URL and more information.
This chapter covers the important commands of NQC. If you have a background in C programming, the syntax and control structures will look familiar. If you don't have a background in C, don't
worry: NQC is easy to learn. I've included lots of example programs to demonstrate how things work. I won't cover NQC exhaustively; several excellent web pages detail the entire language. See
the "Online Resources" section at the end of this chapter for details.
main
NQC programs are organized into one or more tasks. A task is simply some set of instructions that execute in order. A task is analogous to a thread in other programming environments. A single
program may consist of several tasks that execute at the same time.
Tasks have names. Every program should have a special tasks called main. When the Run button is pressed, the RCX begins the program by running main. If you define other tasks, you have to
explicitly start and stop them. The main task is the only one that is automatically run by the RCX. I'll explain more about starting and stopping tasks later.
∗ As this book goes to press, a standalone MacOS version of NQC is being released in beta test form. Now you can run NQC on MacOs without MPW.
http://www.enteract.com/~dbaum/lego/nqc/.
His web site also includes pithy documentation for the language.
Page 58
Need help?
Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?
Questions and answers