NXT-Python is a package for controlling a LEGO NXT robot using the Python programming language. It can communicate using either USB or Bluetooth. It is available under the Gnu GPL v3 license. It is based on NXT_Python, where releases halted in May 2007.
python-bluez
in deb-based linuxes)See http://code.google.com/p/nxt-python/wiki/Installation.
Take a look at the examples directory. Feel free to copy that code into your scripts and don't be afraid to experiment! If you are having trouble with something, you may find the solution in the docstrings (for example, help('nxt.sensor.Ultrasonic')) or even in the source code (especially for digital sensors).
I have tried to put the most important stuff first, but it would be a good idea to read the whole section. In any case, read it all the way through before asking for help. Thanks!
This version is part of the 2.x series of releases. Programs designed for NXT_Python or for the 1.x series of nxt-python will not work with this version. If you are trying to get an old program to work, it most likely needs a 1.x series release, which can be downloaded from the nxt-python downloads page at googlecode. New projects should use a 2.x series release (hint: this is one!) due to the new features and API improvements. Converting old projects is somewhat difficult and not officially supported, though as always you're welcome to ask for help.
Support for a number of sensors has not been tested at all, due to lack of hardware. I have started a project to test this code, but the going is slow and I still can't test everything. If you have a problem with a digital sensor, see the troubleshooting guide below and don't forget to report your trouble!
The Synchronized Motor support has not been extensively tested for accuracy. It seems to mostly work well but the accuracy of the braking function and the closeness of the two motors to each other have not been given a formal scientific assessment.
NXT-Python has not been tested and may not work with custom nxt firmware versions (if you don't know what that means, you don't need to worry about it). However, if the firmware supports the standard LEGO USB/BT communications protocol, everything should more or less work. NXT-Python has been tested with bricks using LEGO firmware version up to 1.29 and is compatible with protocol version 1.124 (used by most if not all of the official firmwares). It has also been reported working with LeJOS.
The arduino directory of an svn checkout (not included with release packages) contains a digital sensor unit test system called nxtduemu. It is intended for developers and advanced users who are looking to experiment with sensors and the digital sensor framework and classes. See Arduino/README for more info and usage instructions.
nxt.brick
, nxt.telegram
, nxt.direct
, and nxt.system
:
nxt.locator
:
nxt.motor
:
nxt.sensor
:
nxt.error
:
If you are getting errors, strange behavor, or incorrect values from a digital sensor, chances are that there is a bug in our code. Follow these instructions to try and find out what's wrong:
If you get to here and are still having a problem, you can either go ahead and report it now or continue to try and find and fix the problem and then report it (or not report it at all, but that wouldn't be very nice...). Python experience required beyond this point.
Read the spec for the sensor to determine how the given value should be read, then start at the sample method and read through it, checking for problems as you go. If it seems right, go back to the I2C_ADDRESS chunk (near the top of the class) and make sure that the correct struct format string is being used. The most common problem here is values that are off by plus or minus 128 or 32768 because of an incorrect signed/unsigned setting. This can be fixed by switching the case (as in upper or lower) of the letter in the string. Other problems could include the wrong size (B, H, or L) being used, or, in the two latter ones, the wrong byte order (< or >). As always, common sense required.