Page 69 - The Unofficial Guide to Lego Mindstorms Robots
P. 69
58
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.
N QC 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 limit ations 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 port able. NQC runs on MacOS (using
M PW), 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 http://www.enteract.com/~dbaum/lego/nqc/.
His web site also includes pithy documentation for the language.
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 c hapter 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
e xample programs to demonstrate how things work. I won't cover NQC exha ustively; several excellent web pages detail the
entire language. See the "Online Resources" section at the end of this chapter for details.
m ain
NQC programs are organized into one or more tasks. A task is sim ply some set of instructions that execute in order. A task is
analogous to a thread in other programming environments. A singl e program may consist of several tasks that execute at the
sa me 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
o ne that is a utomatically run by the RCX. I'll explain more about starting and stopp ing tasks later.
∗ As this book goes to press, a standalone MacOS version of NQC is being released in beta test form. N ow you can run NQC
on MacOs without MPW.