Programming the NXT with NBC/NXC
NXC was the first tool I used to program my NXT.
NXC works by compiling C-like source code to NXT compatible byte code. This means the generated code can be uploaded to the standard NXT bot running Lego's original firmware.
Getting started
Download the NBC/NXC compiler from the NBC/NXC web site. To install it I copied the nbc executable to /usr/bin/.
I found it very usefull to read through the NXC-tutorial and the NXC-guide is a must have.
Once you have your first script you will need to compile it:
nbc your_script.nxc
If there are any error, they will be reported.
To build an executable file that you can upload to the NXT run:
nbc your_script.nxc -O=your_script.rxe
Now you can upload the program to the NXT. I use nxt_push from NXT Python, which I copied into /usr/bin/. Connect the NXT to your machine and run the following command.
nxt_push your_script.rxe
Now your programm should be on your NXT. Select and run it.
After a while this gets a bit annoying so I wrote a little script that compiled and pushed the executable to the NXT. I called it nxc and placed it in /usr/bin/.
#!/bin/sh dirName=`dirname $1` fileName=`basename $1 .nxc` nbc "$dirName/$fileName.nxc" -O="$dirName/$fileName.rxe" nxt_push "$fileName.rxe"
This made life a bit simpler.
NXC and SciTE
If you like using Scite the following properties may be usefull. I added them to my User Properties.
#associate *.nxc with the C lexer file.patterns.cpp=$(file.patterns.cpp);*.nxc #point to the API file containing all NXC function signatures. api.*.nxc=nxc.api #various build commands command.go.*.nxc=nxc "$(FileNameExt)" command.compile.*.nxc=nbc "$(FileNameExt)" command.build.*.nxc=nbc "$(FileNameExt)" -O="$(FileName).rxe"
With those settings you get nice syntax highliting and can compile/upload your programs to the NXT with a simple push of a button.
The Lego/nxc/nxc.api is taken from NXC's readme.txt You can find it the SVN repository.
NXC programs
See the NXC - examples. Or check them out using SVN from http://jan.kollhof.net/svn/Lego/nxc.
svn checkout http://jan.kollhof.net/svn/Lego/nxc