Rev 1 | Blame | Last modification | View Log | Download
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- saved from url=(0046)http://www.baumfamily.org/nqc_old/doc/faq.html --><HTML><HEAD><TITLE>NQC FAQ</TITLE><META http-equiv=Content-Type content="text/html; charset=windows-1250"><!-- Copyright 1998 Dave Baum --><META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD><BODY bgColor=#ffffff><H2>NQC FAQ</H2><H3>General</H3><UL><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#nqc">What isNQC?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#mindstorms">Whatis LEGO MINDSTORMS?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#RIS2">Does NQCsupport RIS 2.0?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#firmware">How canI get the RCX 2.0 firmware?</A> </LI></UL><H3>NQC Compiler Usage</H3><UL><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#dos">I'm usingWindows, and when I click on NQC a window with some text flashes on the screenthen disappears. What's going on?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#-Trcx2">I'm usingthe RCX 2.0 firmware but get errors when trying to call 2.0 functions (e.g.SetUserDisplay). What's wrong?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#errors">How can Iredirect errors to a file?</A><LI><Ahref="http://www.baumfamily.org/nqc_old/doc/faq.html#spiritinstall">Where isSpirit.ocx? RcxCC complains that it is not installed.</A> </LI></UL><H3>IR Communication</H3><UL><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#usb">How do I getNQC to work with my USB IR tower?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#control">How do Iuse a computer to control the RCX?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#irusb">How do Iuse the IR tower with a USB Macintosh?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#irdebug">Help,RcxCC/MacNQC/NQC can't communicate with my RCX!</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#irlaptop">How do Iuse my computer IR port with the RCX?</A><LI><A href="file:///Users/dave/WebSite/nqc/doc/faq.html#irxp">How can I getthe USB IR tower to work under Win XP?</A> </LI></UL><H3>Miscellaneous</H3><UL><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#spirit">Whydoesn't NQC use the Spirit OCX?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#vision">Does NQCsupport Vision Command?</A><LI><A href="http://www.baumfamily.org/nqc_old/doc/faq.html#build">Whatcomputers/tools/etc do you use to develop NQC?</A> </LI></UL><P></P><HR align=left><P></P><H3><A name=nqc></A>What is NQC?</H3><P>NQC (Not Quite C) is a programming language for several LEGO MINDSTORMSproducts including the RCX, CyberMaster, and Scout. NQC's syntax is very similarto the C programming langauge, so experienced C programmers (and Javaprogrammers) should find it very easy to get started with. Even if you aren't anexperienced programmer, NQC is relatively easy to learn.</P><P>The two primary reasons people move up to NQC from the standard tools (RCXCode and Robolab) is that NQC is a textual langauge, and it is more powerful.Graphical languages are often easier to learn (no syntax errors!) but aregenerally more tedious to use than a textual langauge. The graphical metaphorsof RCX Code (and to a certain extent Robolab) also significantly limit the typesof programs you can write.</P><P>NQC uses the same firmware as LEGO's standard tools (RCX Code and Robolab).This means it is possible to have RCX Code, Robolab, and NQC programs loadedonto the RCX at the same time. NQC also benefits from the stability and userinterface (e.g. the View button) provided by the standard firmware. On the minusside, NQC must live within the constraints of the standard firmware. Forexample, since the firmware does not provide floating point support, NQC cannotprovide it either. Other altermatives for programming the RCX (notably legOS andpbForth) do not have such restrictions.</P><P></P><HR align=left><P></P><H3><A name=mindstorms></A>What is LEGO MINDSTORMS?</H3><P>LEGO MINDSTORMS is a series of LEGO sets that use special programmable bricksto allow construction of robots. The most versatile programmable brick is theRCX, which can be found in the Robotics Invention System set. A simpler brick,the Scout, can be found in the Robotics Discovery set. The simplest brick, MicroScout, is featured in two sets with a Star Wars theme: Droid Developer Kit, andDark Side Developer Kit. Even though it is the most expensive, the RCX based setis still the best value due to the versatility of the RCX itself. The Scout is abit more limited, but still can be programmed (using NQC) to do some interestingthings. The Micro-Scout is extremely limited, and it useful mainly as anaccessory to another programmable brick such as the RCX or Scout. Furtherinformation on MINDSTORMS sets can be found at the official site: <Ahref="http://www.legomindstorms.com/"target=_blank>http://www.legomindstorms.com/</A>.</P><P></P><HR align=left><P></P><H3><A name=RIS2></A>Does NQC Support RIS 2.0?</H3><P>The RCX in the RIS 2.0 is nearly identical to the 1.0 RCX. However, newfirmware is used to give the RCX some new capabilities. Fortunately for existingRCX owners, this firmware is available for download from www.legomindstorms.com(as part of the RIS 2.0 SDK). NQC supports this new firmware (see <Ahref="http://www.baumfamily.org/nqc_old/doc/faq.html#-Trcx2">here for moreinfo</A>).</P><P>RIS 2.0 also uses a new IR tower with a USB connection (instead of theeariler RS-232 based towers). Support for the USB tower under Windows and Mac OSX is currently in <Ahref="http://www.baumfamily.org/nqc_old/beta/index.html">beta test</A>. Supportfor Mac OS 9 will be added shortly and several other people are working on Linuxsupport.</P><H3><HR align=left><A name=firmware></A>How can I get the RCX 2.0 firmware?</H3><P>The RCX 2.0 firmware is contained in a file named FIRM0328.LGO and isinstalled on your PC when you install the standard LEGO software. It is alsoinstalled as part of the Vision Command software and the 2.0 SDK.</P><P>Unfortunately, all previously mentioned sources for the firmware requiresoftware to be installed on a Windows computer. If you are using a differentoperating system, then you will need to download the earlier Beta version of the2.0 SDK which was packaged as a .zip file rather than a full installer. This.zip file may then be expanded to get the FIRM0328.LGO file. The SDK 2.0 Betacan be found at <A href="http://mindstorms.lego.com/sdk2beta/default.asp"target=_blank>http://mindstorms.lego.com/sdk2beta/default.asp</A>.</P><P></P><HR align=left><P></P><H3><A name=dos></A>I'm using Windows, and when I click on NQC a window withsome text flashes on the screen then disappears. What's going on?</H3><P>NQC is a command line based tool - normally you run it by typing anappropriate command into an MS-DOS window. When you double-click the exe file itlaunches an MS-DOS console, runs NQC within it, then since NQC finishes almostimmediately, the entire window disappears.</P><P>Some people prefer command line based tools because they allow you to use thetext editor of your choice, etc. It also makes for identical behavior underWindows, Mac, and Linux. In order to use the command line version of NQC you'llneed to do two things:</P><P>1) Use some sort of text editor (such as Notepad) to edit and save a sourcefile for NQC to compile.</P><P>2) From an MS-DOS window type the appropriate NQC command. Its usually bestto either put all of your programs and nqc.exe in the same directory, or makesure the directory containing NQC is in your command path. For example, tocompile and download the program "test.nqc" using the default serial port youwould type the following command:</P><P>nqc -d test.nqc</P><P>An alternative is to use the <A href="http://www.cs.uu.nl/~markov/lego/"target=_parent>RCX Command Center</A> by Mark Overmars, which is a familiarWindows style application that provides a front end to the NQC compiler.</P><P></P><HR align=left><P></P><H3><A name=-Trcx2></A>I'm using the RCX 2.0 firmware but get errors when tryingto call 2.0 functions (e.g. SetUserDisplay). What's wrong?</H3><P>When NQC compiles a program it needs to know what kind of programmable brickyou want it to generate code for (this is called the <I>target</I> for thecompile). By default, NQC assumes you are targetting RCX 1.0. If you want to useRCX 2.0 features, you need to tell the compiler you are using an RCX 2.0 target.If you are using a command line version of NQC, then add <TT>-Trcx2</TT> to thecommand line:</P><P><TT>nqc -Trcx2 -d foo.nqc</TT></P><P>If you don't want to type <TT>-Trcx2</TT> all the time, then just use theenvironment variable <TT>NQC_OPTIONS</TT> - NQC reads this environment variableand inserts any options in this variable at the front of the command line. Forexample, if <TT>NQC_OPTIONS</TT> was set to <TT>-Trcx2</TT> and you issued thefollowing command</P><P><TT>nqc -d foo.nqc</TT></P><P>NQC would behave as if you actually typed</P><P><TT>nqc -Trcx2 -d foo.nqc</TT></P><P>The specifics of setting environment variables depends on your operatingsystem and shell. For example, under Windows you could type the following in acommand shell:</P><P><TT>set NQC_OPTIONS=-Trcx2</TT></P><P>If you want to always use RCX 2.0, then you can make this setting permamentby editing the AUTOEXEC.BAT file and adding the above command to the end of thefile. This way, the variable will get set every time Windows is started.</P><P>If you are using a GUI based version of NQC (such as MacNQC), then thereshould be some preference setting for the target - just make sure it is set to"RCX 2.0". Unfortunately, RcxCC does not have an "RCX 2.0" setting, but there isa workaround. Leave the target as "RCX" (which means RcxCC won't specify anytarget information and just rely on the fact that NQC defaults to RCX), then usethe <TT>NQC_OPTIONS</TT> environment variable to specify RCX 2.0 (as describedabove).</P><P></P><HR align=left><P></P><H3><A name=errors></A>How can I redirect errors to a file?</H3><P>Compile errors are written to stderr, not stdout. This is to allow thecalling program to separate errors from the program listing (-l option) thatappears on stdout. The normal redirection facility of a shell only redirectsstdout, thus the errors will still be printed to the screen. Most shells haveadditional syntax that allows the stderr stream to be redirected (use"option->" in MPW, or "2>" for WinNT). I do not know of any mechanism toredirect stderr in Win95 command.com.</P><P>In addition, nqcc now supports (verion 1.1 b1) the ability to route errormessages to stdout with the -E option.</P><P></P><HR align=left><P></P><H3><A name=spiritinstall></A>Where is Spirit.ocx? RcxCC complains that it isnot installed.</H3><P>NQC has never used Spirit.ocx, but RcxCC used to require Spirit.ocx forcommunication with the RCX. Lego no longer supports Spirit.ocx as of RIS 2.0,but fortunately RcxCC has been updated to no longer require it. In addition,RcxCC has been renamed to BricxCC (due to trademark concerns from Lego). You candownload the latest version of BricxCC <Ahref="http://members.aol.com/johnbinder/bricxcc.htm" target=_blank>here</A>.</P><P></P><HR align=left><P></P><H3><A name=usb></A>How do I get NQC to work with my USB IR tower?</H3><P>Presently, USB towers are only supported under Mac OS X and Windows. I willbe releasing Mac OS 9 support shortly. Some other developers are working on aLinux solution.</P><P>USB support is in beta test and requires version 2.4a4 of NQC.</P><P><B>IMPORTANT</B>- you need to tell NQC that you want it to look for a USBtower, otherwise it assumes you have a serial tower and uses the default serialport for your operating system (e.g. COM1 under Windows). Add <TT>-Susb</TT> tothe command line or set the <TT>RCX_PORT</TT> environment variable to<TT>usb</TT>. When adding a command line option, put it near the beginning ofthe command:</P><P><TT>nqc -Susb -d test.nqc</TT></P><P><B>Windows only:</B> NQC uses the USB driver installed by the Lego RIS 2.0software, so you will need to install the RIS software and run it once with theUSB tower connected in order for the driver to be correctly installed.</P><P><B>Mac OS X only:</B> NQC talks directly to the USB tower. There is nodriver, so you'll never see the tower show up in /dev.<BR></P><P><SPAN style="FONT-WEIGHT: bold">FreeBSD (unoffical port):</SPAN> As of NQC2.5 a5, the USB tower is supported when running a FreeBSD build from 02/28/03 orlater (the upcoming FreeBSD 5.1 will work).<BR></P><P></P><HR align=left><P></P><H3><A name=control></A>How do I use a computer to control the RCX?</H3><P>There are two basic ways to do this: send raw commands to the RCX, or send'messages' which are then listened to by a program running on the RCX.</P><H4>Sending Messages</H4><P>This is generally the simplest way to interact with the RCX. First you writea program for the RCX that continuously checks for received messages (using theMessage() and ClearMessage() calls) and then dispatches the messagesaccordingly. The messages may have any value between 1 and 255. There is nopredefined meaning for these messages - your program can do whatever it wantswith each message.</P><P>There are several ways to send the message. You can use another RCX (or aScout) by calling the SendMessage() function. You can also use the nqc commandwith the -msg option, for example to send message #3:</P><P>nqc -msg 3</P><P>You can use the LEGO remote control to send messages 1, 2, or 3. It is alsopossible to send the message by sending the appropriate command packet (seebelow)</P><H4>Sending Raw Commands</H4><P>Sending raw commands gives you complete control over the RCX. The commands(a.k.a. opcodes or bytecodes) and the general packet format are unofficiallydocumented at <A href="http://graphics.stanford.edu/~kekoa/rcx/"target=_parent>http://graphics.stanford.edu/~kekoa/rcx/</A>. For example, tomake the RCX play system sound #3 (upward tones), you would send a two-bytecommand (shown in hex):</P><P>51 03</P><P>Messages are just a specific type of command - F7 followed by the messagevalue, so message #4 would be the packet</P><P>F7 04</P><P>If you are using NQC, you can let NQC take care of all the details of packetformatting, getting an acknowledgement from the RCX, and retrying if a failureoccurs. You do this with the -raw option, which takes a single parameter listingall of the bytes (in hex format) for the command:</P><P>nqc -raw 5103</P><P>If you are writing your own program, you can build up the packet yourself. Asuitable packet (for the plays sound command) would be:</P><P>55 ff 00 51 ae 03 fc 54 ab</P><H3><HR align=left><A name=irusb></A>How do I use the IR tower with a USB Macintosh?</H3><P>Since a USB version of the IR tower doesn't exist (yet), you will need a USBto serial converter (such as the Keyspan TWIN adapter). If the adapter providesa 9-pin serial connector, then you should be able to use the standard Mindstormscable between the adapter and the IR tower. If the adapter provides mac-styleserial connector, then you will also need an appropriate cable as desribed <Ahref="http://www.baumfamily.org/lego/macmind/cables.html">here</A>.</P><P><I>Note: I have heard several reports of the Palm USB adapter not working. Iam not sure if this is a problem with the adapter itself, or some unusualinteraction between it and the OS. If you have been able to use a Palm USBadapter with MacNQC or NQC, please let me know. I would like to get a definitiveanswer on whether this adapter can be made to work. Personally, I use theKeyspan Twin adapter (USA-28X), and I've heard that both the Keyspan PDA adapter(USA-19) and Xircom PortGear USB also work.</I></P><P>If you are using MacNQC, then the popup menu in the Preferences dialog boxwill list all available serial ports (including those provided by USBconverters).</P><P>If you are using the MPW version of NQC, then you will need to specify theserial port either on the command line (using the -S option) or in the RCX_PORTenvironment variable. Both methods require that you know the name of the serialport driver. The easiest way to make this work is to use the adapter's controlpanel to configure the serial port to "emulate the printer port". This willcause the serial port to be named "B", thus you could do either of thefollowing:</P><P><TT>nqc -SB -d foo.nqc</TT></P><P>or</P><P><TT>set -e RCX_PORT B</TT></P><P><TT>nqc -d foo.nqc</TT></P><P>If you choose the second option, the <TT>set</TT> command only needs to beexecuted once per MPW session - adding it to a Startup file will make lifesimpler.</P><H3><HR align=left><A name=irdebug></A>Help, RcxCC/MacNQC/NQC can't communicate with my RCX!</H3><P>In most cases, problems like this boil down to a configuration issue, badcable, or dead battery. Here are some troubleshooting tips.</P><P>If the program says it cannot open the serial port, then this is almostcertainly a configuration problem. For MacNQC, make sure you have a valid serialport selected in the Preferences dialog box. For NQC, make sure you havespecified the appropriate serial port name (default is modem port, "B" is theprinter port, see <Ahref="http://www.baumfamily.org/nqc_old/doc/faq.html#irusb">above</A> for USBbased macs). For RcxCC, I suggest trying once with auto-detection, and if thatfails, then manually set the serial port in the RcxCC program.</P><P>If the program reports that it cannot communicate with the IR device, theneither the program is talking to the wrong serial port (see the previous item),or there's a problem with the cable and/or battery. Make sure you have a fresh9v battery installed in the IR tower, and if possible use the cable supplied byLego.</P><P>If the program reports that it cannot communicate with the RCX, thencommunication with the IR tower is probably OK, and the problem is between thetower and the RCX.</P><UL><LI>Certain light sources (bright sunlight, certain projection TVs) can causeinterference...try using a towel or other item to shield the IR tower and RCXfrom other light.<LI>The tower and RCX should be about 6 inches apart. Tty the switch on thefront of the tower in both positions - some people report better success with"near" mode, and some with "far" mode.<LI>Make sure you have firmware downloaded into the RCX. If the display onlyshows "1" on it, then firmware isn't installed yet...download the firmwareusing the Lego software or the -firmware option for NQC (the firmware itselfmust be copied from the Lego CD or downloaded from <Ahref="http://www.legomindstorms.com/"target=_blank>http://www.legomindstorms.com/</A>). Once the firmware isinstalled you should see something like "00.00 1" on the display. </LI></UL><P>If you have a terminal program (e.g. HyperTerminal for Windows, Zterm for theMac), then you can check the IR tower directly. Open up a session to theappropriate serial port at 2400 baud, 1 stop bit, odd parity, and 8 data bits.Turn off local echo. Start typing a few characters. A green LED on the front ofthe IR tower should light up, and the characters you typed should be echoed backto the screen (with an occasional mistake depending on how much interferencethere is).</P><P>If you are using the command line version of NQC, then you can have it logany serial communication. This is helpful in trying to isolate wherecommunication is failing. A good general-purpose test is</P><P><TT>nqc -v -raw 10</TT></P><P>Please include the output of this test in any e-mail to me regarding IRcommunication problems.</P><P></P><HR align=left><P></P><H3><A name=irlaptop></A>How do I use my computer IR port with the RCX?</H3><P>You can't. At least not easily.</P><P>Most computers use the IrDA protocols for IR communication. The RCX uses aproprietary protocol developed by Lego for communication. Quite simply, theseprotocols are incompatable.</P><H4>What about IrCom? Doesn't that let me use the IR port as a regular serialport?</H4><P>Yes and no. From an application's point of view, IrCom looks like a serialport (complete with hardware handshaking and control lines). However, the IrComlayer actually resides on top of normal IrDA communication, so what appears tothe application to be async serial communication, is in fact a bunch of IrDApackets getting sent back and forth. Since the RCX doesn't understand IrDApackets, it can't understand IrCom either.</P><H4>What if I access the hardware directly?</H4><P>Even if you bypassed the IrDA protocol stacks on the computer and somehowmanaged to control the hardware directly (a task that is likely to be differentfor different computer vendors), it still may not be possible. The Legoprotocols encode bits using a 38kHz carrier frequency. This frequency isgenerated an filtered in hardware. IrDA doesn't really use a carrier frequency,and the actual specs on bit times provide a lot of lattitued to devicemanufacturers. As a result, it is difficult to get generic IrDA hardware togenerate the required 38kHz carrier reliably. Filtering the recieve side is evenmore problematic.</P><P>I would hesitate to say that this problem is "impossible" to solve, butpeople have been asking about this for over a year, and to my knowledge nogeneral solution has emerged. There are, however, specialized solutions forspecific pieces of hardware (usually PDAs or other handled devices such as aPalm III).<BR></P><HR align=left><H3><A name=irxp></A>How can I get the USB IR tower to work under Win XP?</H3><P>There appear to be some timing related difficulties when using NQC with theUSB tower under Windows XP. If you are having difficulty downloadingprograms, open the LEGO USB Tower control panel, select the Advanced Tab, andset the Read Timeout to 300 msec. This generally fixes theproblem.<BR></P><H3><HR align=left><A name=spirit></A>Why doesn't NQC use the Spirit OCX?</H3><P>The Spirit OCX is only available on the PC. My personal preference is to usea Macintosh, so I needed to have a platform independent means for communicatingwith the RCX.</P><H3><HR align=left><A name=vision></A>Does NQC Support Vision Command?</H3><P>Vision command programs run in two places...all of the image processingsoftware runs on the PC, then sends messages to a program running on the RCX.The messages that are sent are ordinary RCX messages, and by using Message() andClearMessage(), NQC programs can respond to them. Mike Gasperi calls this "<Ahref="http://www.plazaearth.com/usr/gasperi/vcsensor.htm" target=_blank>UsingVision Command as a Smart Sensor</A>".</P><P>Note that I have never tried this myself (Vision Command doesn't run on Mac),so I can't really help if things don't work as expected.</P><H3><HR align=left></H3><H3><A name=build></A>What computers/tools/etc do you use to develop NQC?</H3><P>All of the NQC development takes place on my Macintosh PowerBook. I useMetrowerks CodeWarrior to write and debug the code as a Macintoshapplication.</P><P>The Code Warrior project also has targets to build the MPW version of NQC aswell as the Win32 version. Regression tests on the compiler are done on the PPCversion of the MPW tool (via a couple of MPW scripts and a bunch of sampleprograms). Some minimal testing of the Win32 version is done from within VirtualPC - I just make sure that the build went fine and that the serial port workssince that is really the only code custom to Win32.</P><P>For the source release, I boot into Mac OS X, copy over the NQC source treeand build it (using make, gcc, etc). A simple test (again just to make sure theserial port code for Unix is working) is performed. I then use a shell script tocreate a source release tree, strip out any unwanted binaries, and package theentire thing up as a .tar.gz. Recently, I've also been packaging up a Mac OS Xbinary version.</P><P>So there you have it...development for Mac, Windows, and Unix all done on mytrusty PowerBook.</P><P></P><HR align=left><TABLE height=24 cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR><TD width="50%" height=17> <Ahref="http://www.baumfamily.org/nqc_old/doc/index.html"target=_parent>[Home]</A></TD><TD align=right width="50%"> <IMG height=31src="NQC FAQ_soubory/contact.gif" width=128 align=bottomnaturalsizeflag="3"></TD></TR></TBODY></TABLE></BODY></HTML>