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: http://www.ni.com/academic/mindstorms/



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:

nxtrc-2.3-4.fc15.x86_64

and

nbc-1.2.1.r3-3.fc15.x86_64

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.


Conclusion:
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.

Dec 1, 2011

Lego Mindstorm NXT - Open Source Rules

The bad news: My NXT brick was not working properly when I took it from the box. The sensor port 2 was not working. I do not think that there is warranty coverage for Lego Mindstorms in Brazil. I had no better option than try to fix it.

The good news: Lego delivers all information about the NXT electronics and its embedded software. It is a true open source platform.

I've downloaded the schematics from:
http://mindstorms.lego.com/en-us/support/files/default.aspx

And I've noticed a missing component near the port 2. R59 was not there. For lucky it is a common 1k resistor. Thanks to my father's SMD lab, we were able to solder a new resistor, and push hot air over port 2 components. After that port 2 started to work.

I'm deeply happy with Lego's open source policy for this product. I was wondering how happy I'll be when my car becomes open source. Lego gave us the power to fix the problem without any limitation. It is clear to me now that open source is great for hardware too. Is there open source tendencies for industry?

R59 was not there when I've opened my NXT for the first time. The schematics is from Lego web site.


What kind of information is freely and officially available about the Lego NXT:
- NXT Brick hardware schematics
- Sensors schematics
- I2C Communication protocol used for sensors
- Bluetooth interface specification
- Hardware Developer Kit
- Executable File Specification
- Mobile Application Software
- Mobile Application Documentation
- Open Source Firmware

And...

Lego has supported the development of a remote control to the NXT that runs on Android. The source code is released under GPL3.


About my non-working brick, I'm quite sure that this kind of problem happens very few times. Lego Mindstorms NXT 2.0 is clearly a high quality product. I believe that I'm the only in many many many owners who had this kind of trouble. And I admit: It was fun to fix it! :-D

2017 Update: Schematics are available here.

Lego Mindstorm NXT

Want to have some fun with Robotics? 8547 LEGO® MINDSTORMS® NXT 2.0 is the right kit for you!

   
Color Sorter with a bit more complex algorithm

 To me Lego Mindstorms NXT is a dream come true. Why? Robotics! Robotics! Robotics!

What's inside the box?
- The NXT programmable Brick with Bluetooth, USB, 7 I/O ports for sensors and motors, speaker, buttons, and LCD display.
- 4 Sensors: Ultrasonic, light and color, 2 touch sensors
- Some cables
- 600+ pieces for assembling machines animals and humanoids.
- Software for Windows and Mac for programming the NXT.