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:

/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC

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

/Library/Python/2.6/site-packages

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:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(nxtpp-test)

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

SET(NXTPP_INCLUDE_DIR ${NXTPP_ROOT_DIR}/include)

FIND_LIBRARY(NXTPP_LIB NXT++ "${NXTPP_ROOT_DIR}/bin/win32")
FIND_LIBRARY(NXTPP_DEBUG_LIB NXT++d "${NXTPP_ROOT_DIR}/bin/win32")

INCLUDE_DIRECTORIES(${NXTPP_INCLUDE_DIR}
${PROJECT_SOURCE_DIR})

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

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.

RWTH – MINDSTORMS NXT Toolbox (MATLAB)

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.

Yay! MINDSTORMS NXT 2.0

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!

Rediscover QQ/TM

QQ, formerly known as OICQ was set out to be a localized version of ICQ. I don’t remember when Tencent released the very first version but it began to gain popularity when I was in high school. Back then it was a real exciting thing to chat with friends and strangers online. You can query based on QQ (in China it is also referred to the numerical ID of your QQ account, other than the client itself), nickname, city, etc., in order to find a stranger to chat. This might seem a bit weird nowadays but back then it was a good way to escape from reality.

The earlier version of QQ was very lite. The setup file was only 700kB and can easily fit onto a floppy disk. But it had done its job well. I liked it so much that I purchased one year of premium membership, which gave me a chance to select some special QQ id along with a bunch of other benefits. I selected a 6-digit QQ with the last three being my birthday. By the way, even now a lot of people would be amazed by special QQ id (i.e., 88888888, 123456789) and are willing to pay a premium for it.

After a couple years of evolution, Tencent has expanded its platform. There was this notion of costumes that you can use to customize your avatar. Some of those were free while the fancier ones would cost money. They don’t deal with cash directly but you purchase QQ cash instead. Since the exchange rate is 1:1 for Chinese Yuan (not sure about now), QQ cash has become a very popular currency in the QQ community. But that’s not all, QQ has incorporated QQ games, anti-virus, browser, QQ space, downloader, etc. It almost as if the only thing Tencent did not have is its own operating system. As a result the client got very bulky and slowed down my computer quite a bit. I checked if there’s a way of not installing the unnecessary components but came up with no solution (not sure about how it is now). I also got very tired/bored of being harassed by strangers, and finally gave up QQ for MSN messenger. MSN (now renamed to Windows Live Messenger), interestingly, seems to follow the same path of QQ by trying to incorporate many community services and most annoying of all, flash advertisements (I don’t think even QQ has this “feature”). It is consuming a lot more memory than it used to be (and I started to favor Google Talk), more on that probably in another post.

What I do like are two of the features QQ provides: group chat and resumable file transfer. You can basically establish groups and invite people to join, and the group remains there until if the owner wants to delete it. The whole idea is for a group of people sharing the same interests to have a common ground to, well, have conversation. I know that MSN had the feature of inviting people to start group chat long time ago, but only recently did Windows Live Messenger incorporate the feature of groups. And of all IMs I have used, I don’t know any clients other than QQ that support resumable file transfer. To make things even more cumbersome (perhaps only for me }:-), many people now use those “one-for-all” type of IMs: Pidgin, Adium, Meebo (web-based) or IM within Gmail. This on one hand makes it really convenient for communicating with different IM accounts, but on the other hand you give up all the nice features of the particular IM clients: drag-n-drop file transferring, video/audio chat, screen-sharing (iChat). Nonetheless, it really boils down to personal preference, if my friends like it that way I just have to live with sending files as email attachments.

Although I abandoned QQ for quite a while, I have to admit that QQ has a significant success of marketing in China (considering ICQ almost dead in US). Furthermore, they are trying to improve. There is another IM client sharing the same account but with only the essential features of QQ, called Tencent Messenger (TM). It is “designed for communications among business people” hence those unnecessary components were stripped away. Couple of years ago Tencent finally released the English version of QQ and TM, this was a push for me to restart using my QQ id with TM (I mainly use English OS with US regional settings). QQ now also has versions for Linux and OS X (links to Chinese website, English website only has download for Windows version) it also finds its way to other mobile platforms as well. Particularly, I was amazed when I found out that the developers have ported QQ to iPhone OS. Although the clients on all the other platforms are not full-fledged – the interfaces look simple and the features are limited, I think they’ve made good effort and progress in trying to transport QQ onto other platforms.

Another interesting feature that I would like to emphasize is screen-grabbing during chats. Basically you click on the button and it enters screenshot mode, you drag the mouse to determine a region and then double click. The image will be copied to your sending box (where you type your messages, since it can now include images, it is not quite accurate to be called “textbox”), hence sharing information couldn’t be more easier (this works in both individual chat and group chat). Imagine if you want to send a piece of code for some one to read, with this you can send a nicely formatted version with a few clicks (if you want to argue that you cannot copy-n-paste directly from IM window to wherever else, meh, I am just illustrating an example here). I really like this feature and I don’t see any other IMs have it (actually one of the reasons I started to use TM again).

There are still improvements that can be made. First of all, the TM client (not sure about QQ) does not work well in multiple monitor setup. The main window automatically attaches to the right edge of the left screen (and “hides” itself in the right screen) if you try to drag it to your right screen. You will not be able to maximize the chat window in the secondary screen (the chat window will just disappear but not closed) and the screen-grabbing feature does not work on the secondary screen. Lastly, I would love it if QQ/TM saves chat histories on the servers (just like Gtalk/Gmail) since from time to time I do need access to them. Not everyone wants this though (especially when they are more of keep-it-off-the-record type of people).

I never thought I’d say this, but I do feel very proud of the developers of QQ/TM. For some of you who are interested, I highly recommend you to try it out and let your friends know about it. The English version can be downloaded here (Windows only, I will check if OS X and Linux version have English language option).

gtest + CMake + Visual Studio

I should have posted this sooner, but all kinds of things got in the way and… Okay, that was just some lame excuse, it is because my laziness that this site has been left unattended.

I suddenly felt the urge of writing this post because the other day I saw my friend Dat was trying to get gtest to work with Visual Studio but ended up getting cryptic messages from linking errors. This has happened to me before, and I have investigated this issue.

In fact, using gtest library with CMake is fairly easy and straightforward. All you need to do is to find the corresponding library and the include path, and then link the gtest library against the executable. This works without a problem in Linux. However, it becomes a bit tricky when used in Windows (as expected?).

The main issue is the Runtime Library setting in Visual Studio:

By default, it tries to load DLL, but I was feeding it LIB file. No wonder it complains. Suppose I am building in debug mode, I need to specify gtestd.lib to be my target library and select “Multi-threaded Debug (/MTd)” as the runtime library, whereas in release mode gtest.lib needs to be specified and “Multi-threaded (/MT)” should be selected.

So, is there any workarounds to avoid this manual hassle? Sure, simply do

SET(CMAKE_CXX_FLAGS_DEBUG "/MTd")

in the CMakeLists.txt, and it will be set automatically (somehow I was under the impression that I have tested this before and it was not working, but it did work just now).

Of course, you can specifically indicate that you want a DLL to be built in gtest. Yet so far I haven’t found a way to utilize the DLL (such that it can work with /MD or /MDd), I would have to defer this problem to some C++ gurus, i.e. George Toderici (if Google Alert ever alerts him about the existence of this post), to answer.

Follow

Get every new post delivered to your Inbox.