Our resident expert on all things
robotic is merely an email away.
roboto@servomagazine.com
Tap into the sum of allhumanknowledge and get your questions answered here!
From software algorithms to material selection, Mr. Roboto strives to meet you
where you are — and what more would you expect from a complex service droid?
by
Dennis Clark
I’m pondering the meaning of this year’s First LEGO
League (FLL) topic “Body Forward” — a bio-medical robotics
topic. What could it mean? How will my team do? What
will the pizza cost? Just by coincidence, I received a LEGO
NXT question! FLL does not allow teams to use anything
but the official Mindstorms programming language, but
that doesn’t stop you robot builders out there from using
it! So, with that in mind, let’s get right into the big
question this month.
Q. I’ve heard that there is a way to program the Mindstorms NXT in C without using the LEGO Mindstorms graphical programming language.
Can you tell me how?
— Erik
A. There is such a thing, but it isn’t really C. It just looks like it. It is called NXC which stands for Not eXactly C. NXC is basically a set of macros laid over
the top of the actual programming language for the NXT
brick called NBC — an acronym for Next Byte Codes. The
NBC assembler takes source written in NBC and compiles
it to the byte codes used by the NXT brick firmware
interpreter. Both NBC and NXC are open source projects
that can be found here at http://bricxcc.sourceforge.
net/nbc.
The project keeper of the keys is John Hansen,
according to the sourceforge.net project pages. John has
a “Power Users” NXC programming book in its second
edition that is very well thought of, called LEGO
Mindstorms NXT Power Programming: Robotics in C. Use it
to show yourself the ropes of using the NXC language.
There is also an on-line NXC programmer’s reference here
at http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/
index.html.
I must admit that I didn’t know anything about this
language or its usage until I researched it to answer this
question. Since I have a couple of Mindstorms NXT kits
(I coach my kid’s school FLL team), I thought that it
would be a great thing to learn. I am a big fan of Dave
Baum’s MacNQC program that brought Not Quite C to
the Macintosh “way back when.” Unfortunately, no one
carried the Mac flag forward for NXC beyond the
command line compiler support. If you are a Windows
user, you are in luck however, since the well-supported GUI
program Bricx Command Center has recently come out
with NXC support in the 3. 3 versions. There is more
information and downloads available at http://bricxcc.
sourceforge.net.
Step One: Get the NBC compiler.
The very latest NBC/NXC compiler is 1.2.1 r3
(June 30, 2010). Go to http://bricxcc.sourceforge.
net/nbc and click on “Mac OSX (universal binary)” to
get the NBC assembler. This will get you the file nbc-
1.2. 1.r3.osx.tgz. Don’t be alarmed by the weird name —
your Mac can deal with it. When you click on the
download link, you’ll get a window that suggests saving
the file; go ahead and save it. When the download
completes, double-click on the file in the Downloads
window (I’m using Firefox; every browser has a downloads
window named something like that). Now, create a folder
under your Applications folder or wherever you put stuff
like this. I called mine “NXC.” (That isn’t very original, but it
IS very obvious.) In Finder, find where your browser
downloads stuff (most likely in <login name>/Downloads).
When you doubled-clicked on the downloaded funky file
name, it created a directory in your download folder called
nbc-1.2.1.r3.osx. Move this folder to your NXC folder (or
whatever you decided to call it).
SERVO 09.2010 15