Dec 2, 2011

Lego Mindstorm NXT - Programming Options

Option 1: Lego Mindstorms NXT Software version 2.0
The first and the official programming option for the NXT is Lego Mindstorms NXT software version 2.0 that is based on Labview from National Instruments. It is delivered with 8547 LEGO® MINDSTORMS® NXT 2.0.

Mindstorms software is a graphical programming environment. The programming is made connecting bricks and data lines. It is "a great tool" for learning and teaching programming, and it is also fun. It is possible to do non trivial tasks like multi-threading and functions. But for non-small programs it is not practical.

Mindstorms software is used to make programs, to send the compiled programs to the NXT, to remote control the NXT, and to update NXT firmware. Both USB and Bluetooth are supported. I've tested it under Windows but it is also supported under Mac. It does not work under Linux.

See my enhanced color sorter program:
The main program. Note the two threads. The bottom is for the dispenser and color sensor, while the top controls the tray.

Function: tray_next

Function: tray_previous

This robot is running the code shown above.

You can download my program here. You will need Mindstorms software to open the files.

Mindstorms software is the perfect development environment for starting playing with Lego. It is as intuitive as connecting lego bricks and it is also beautiful. But is not practical for non small programs. I would not recommend to implement large software using it. But I would recommend this visual language to introduction to robotics and to programming languages.

There is lots of information about LabView at:

Option 2: RobotC
LabView was successful on allowing me implementing the enhanced color sorter algorithm. But it becomes clear that LabView is not practical for complex and large programs.

I found Robotc and tried it. There is a 30 days trial version that I used for two weeks.

The first step is to upgrade the NXT firmware so it can support Robotc binaries. Do not worry about firmware upgrades. It is easy and safe on the NXT. You can always upgrade the firmware to the Lego Offical Firmware using the LabView.

RobotC offers complete development environment with functions similar to the LabView. But instead of connecting bricks and data lines you write C programs.

I found some limitations when I was using more than one thread simultaneously. I'm quite sure that those limitations are not insurmountable, but I did not like RobotC. For the basics there are good documentation and tutorials but I did not find free detailed information.

Like labview, RobotC works on Windows and does not works on Linux.

See RobotC web site.

Option 3: NXC

"Not eXactly C (NXC) is a high level language, similar to C, built on top of the NBC compiler. It can also be used to program the NXT brick. NXC is basically NQC for the NXT. To compile NXC programs just use the NBC compiler with source code files that have a .nxc file extension. A reference guide for NXC is available. You can also access online API help for NXC or download a compiled HTML help file. To take advantage of multi-dimensional array support and native shift operations be sure to download the enhanced NBC/NXC firmware and install it on your NXT."

I liked NXC. "To me", it feels more like C gcc than RobotC and it works on Linux. If you are Windows user, you should try Bricx Command Center that uses NXC/NQC, but if you are Linux user, NXC is great option. I'm using two tools that are official Fedora 15 packages: NQC and NXTRC. NQC is the compiler for the NXC while NXTRC is a tool for remote controlling the NXT and to send files to the Brick using bluetooth. I'm using the following packages:




Installing both on Fedora 15 is as hard as:
# yum install nxtrc nbc

To compile the color sorter on Fedora 15:
$  nbc dispenser4.nxc -O=dispenser4.rxe -sm-

Then, to send it to the NXT using bluetooth:
$ nxtrc -a 00:16:53:13:9A:70 -W dispenser4.rxe

The documentation for NXT is complete and freely available. Also, working on Linux is also very good to me. The binaries made by NXT works on Offical Lego Firmware but you can update to a firmware that is announced to offer better performance. I did not tried the high performance firmware yet.

The source code of the color sorter can be downloaded from: dispenser4.nxc

There is more information about NXC here.

I would start with LabView for initial fun and learning about sensors and motors, then switch to NXC for the complex tasks.
RobotC may have better processing performance and also richer debugging than Bricx Command Center. But for now, processing performance and richer debugging interface are not features that I'm looking for. If you need processing speed and/or rich debugging interface, give RobotC a try.
Post a Comment