We’re not out of the woods
just yet. The nxtcom program
cannot be executed; we have to
change its file attributes. To make
nxtcom executable, type chmod
+x nxtcom. Now, we can
assemble NBC files with the nbc
program and download them to
the NXT with nxtcom.
As I said before, I didn’t
know any of this when I started
so I asked my friend Joe (thanks
Joe!) to help me out. He sent me
a simple Makefile that showed
the steps to use to compile and
download NXC code to the NXT
brick. In Listing 1, you will see
the Makefile which is a UNIX
scripting language that
“simplifies” using compilers, linkers, programmers, and
other complicated command line things so you can type
short and simple commands to get things done. (More on
this later.) One key thing that you need to remember about
a Makefile is that it needs to have the “M” at the beginning
of the name capitalized. Why? Don’t know, it’s just an
ancient UNIX custom.
It would take a whole column to explain this Makefile,
so I won’t do that. I’ll just point out that it sets up where
the compiler and download program are (nbc and nxtcom),
and the compiler options to use to compile your code and
download it over the USB port. Using the Bluetooth port
can be set too. If anyone is interested, I’ll do that question
separately since it’s more fun setting up the Bluetooth
connections.
Listing 1 shows Joe’s Makefile after I modified it. We’ll
come back to it later to explain what is
going on and why I made the changes
that I did. Joe initially put all of his
source files in the same directory as
the nbc assembler. I like to put
applications in the Applications folder
and programming projects in the
Documents folder, so before we go
any further, let’s create a NXC projects
folder here: Documents/NXC/projects/
first.
You can create this folder path in
Finder or you can do it in your terminal
window if you know the UNIX
commands to do so (mkdir). (I did
mine in Finder.)
Next, we’ll create a simple
program to read a SONAR sensor and
display the results on the NXT screen.
Listing 2 shows this source. This was
my first program written in NXC. These
files are in the first folder we created
Figure 2. NXC application folder layout.
in the last paragraph.
Let’s see ... we’ve installed the NXC compiler, have a
Makefile, and a source file — we’re ready to go. I tried to
make the program and it failed. The compiler could not find
the NXCDefs.h file. I searched the SourceForge site and
Googled everything that I could to find out where to get
this file. I found no mention of it. When you take the “road
less traveled” (Mac) and are using open source tools, you
must be ready to dust off your brain cells to figure out how
to get things to work. Many open source tools are built for
the fun of it and out of the kindness of some hard working
person. Usually, there are holes in the documentation that
we must fill in while actually figuring out how things work.
This was one such time.
After my fruitless search, I realized that NXC is a turnkey solution for Bricx Command Center. For the command
Figure 3. Successful compiler results.
SERVO 09.2010 17