Posts Tagged ‘ mindstorms ’

nxt-python in OS X

Setting up nxt-python in OS X requires a little extra effort. As described on its installation page, you will need to install LightBlue, which is Bluetooth API for Python. And in order to install LightBlue to OS X 10.6, a few manual operation needs to be done.

Nevertheless, the installation of LightBlue failed. It turns out I need to add the directory of PyObjC to my PYTHONPATH in order for it to work, which in my case (Python 2.6) is:


Also, wherever you have placed the LightAquaBlue directory (the one in Step 2 for Mac OS 10.6 users, not the one in Step 3) will need to be in PYTHONPATH, too, e.g.:


Then you should be able to setup and install nxt-python without a problem.

NXT++ working, plus a Python interface

NXT++ provides a Visual Studio 2008 (VS9.0) solution file for building its library, it builds without a problem. The developers dropped support for Linux at v0.6 (v0.5 should still work).

Using the library is rather simple, I have written a CMakeLists.txt and the project was successfully built on the first try (usually not the case). The downside is that this project does not seem to be really active, the wiki is there but there’s no help, no mailing list, and no community. Oh, and it does not support the new color sensor. I am including the content of the CMakeLists.txt here in case you want to try it out:



FIND_PATH(NXTPP_ROOT_DIR include/NXT++.h HINTS "C:/nxtpp")




FILE(GLOB SRCS "*.c" "*.cpp" "*.cxx")

ADD_EXECUTABLE(nxtpp-test ${HDRS} ${SRCS})

TARGET_LINK_LIBRARIES(nxtpp-test debug ${NXTPP_DEBUG_LIB} optimized ${NXTPP_LIB})

For Anders’ C++ communication library, I found that it is just a bunch of header files so it should be even easier to use (and it does have color sensor support). More on this later.

Another interesting findings on the Wikipedia is the Python interface to the NXT, nxt-python. Installation is very easy, only a few clicks of effort and it worked right off the bat. Although it lacks documentation, the project is quite active and I foresee myself using it quite a bit.


Before beginning trying out NXT++ today, I found this MATLAB toolbox from the wiki. The installation is quite simple, no need custom firmware, hence may worth some of my attention in the future. Setting up in either OS X or Windows requires you to know the series port the Bluetooth connection is using. A more dummy-proof version of the installation guide can be found here.

It works! Now it’s time to try NXT++.

Progress on programming on the NXT

I have built the “Quick Start” model yesterday and played with it a little bit (video), at least we know that the motors are working, Bluetooth connection is working and the communication between NXT and the motors is working. To my surprise the mobile application software from LEGO includes a java application for my old Sony Ericsson W800, which can act like a remote control for the NXT, yay!

Then I googled three topics on the NXT:

  1. Camera for the NXT
  2. Focus puller using LEGO
  3. Programming C/C++ on the NXT

There is some wireless camera that costs about $40 and is of reasonable size, but the particular model is sold out. Nevertheless, I realized that any wireless camera should do in this case since most of the computation has to be done on the terminal (some computer) and the NXT robot only needs to “hold” the camera and receive instructions from the terminal, so there is really no need for a camera designed specifically for direct communication with the NXT (although there is some).

I have a Canon 5D Mark II so I am really interested in the idea of auto-focus puller. A couple of months back our studio was shooting a short video and in one of the scenarios I had to manually rotate the focusing ring to follow the actress that is walking towards the camera. It was difficult. Hence if I could build a focus-pulling rig with programmable motor, I could tell it to focus from a distance to another in a given speed. That would be very cool! Some work has been done towards this end (Solutions 1, 2 and 3). For me ideally I would like to have some standard follow focus gear that could interface with some of the LEGO gears, but this solution might be expensive and the teeth might not engage well. I am no mechanical engineer so I would like to use components that are readily available (can be purchased), as you can tell from the fact that I bought a LEGO-based robot. The first and the third solutions, although don’t seem quite polished, should work just fine. But we will see.

For the third topic, I came across this comparison chart which I find very useful (here’s another one). From the look of it, I would probably try RobotC first and then LEJOS OSEK. The problem with RobotC is that it is not free (sorry I am cheap), but I will try it out and drop the $30 if I like it. What’s good about RobotC is that it uses the standard firmware and its execution speed is much faster than its peers. As for LEJOS OSEK, it is more C-like but it does require custom firmware and it runs much slower (comparing to RobotC).

Besides the solutions for writing programs that execute directly on the NXT, I also found some interfacing libraries in C++ that can communicate with the NXT via Bluetooth: NXT++ and Anders’ C++ communication library. Both look very easy to use and worth trying. I am also assuming that these libraries require an active Bluetooth connection with the NXT, instead of initialize the connection themselves. A question remains: how do they know which COM port is being used for the connection though? I will find out tonight if the ease of use comes with a catch.


Too bad, it doesn’t come with batteries and the NXT needs 6 AA while I only had 4. I went on installing the software on my MBP using the Snow Leopard fix downloaded from MINDSTORMS website. Unfortunately I got the “A required file is broken” message when starting NXT-G, a quick search suggested that re-run one of the driver packages (legodriver.pkg) that come with the CD would fix the problem.

Then I noticed the program crashes upon exiting. Again a quick search suggested that it does not work well with Adobe Flash Player 10.1. Removing the flash player using the uninstaller provided by Adobe and installing instead the version supplied with the CD fixed the problem.

Then somehow I am getting an error message:

Insecure Startup Items folder detected. Items in the Startup Items folder ("/Library/StartupItems/") have not been started because the folder does not have the proper security settings.

Once again a quick search showed that a file permission repair may fix the problem and luckily it did work for me.

Google rocks!