Posts Tagged ‘ python ’

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.