ruby-nxt

The ruby-nxt library lets you control the LEGO Mindstorms NXT robotics kit via Bluetooth using the Ruby language.

There are three interfaces:

  • High-Level: The NXT class provides multi-threaded, object-oriented interface to the motors, sensors, and most other core NXT functions.

  • NEW High-Level: The Commands module (included with NXTComm) provides a command object-based interface very similar to the Blocks in NXT-G. (this may replace the NXT class in the future)

  • Low-Level: The NXTComm class provides direct access to the NXT Bluetooth bytecode protocol. There is also the UltrasonicComm class which implements the I2C communications needed to interact with the ultrasonic sensor (via NXTComm).

ruby-nxt requires the ruby-serialport library which you must manually download and install from: rubyforge.org/projects/ruby-serialport

Tests & Examples

Most of the ruby-nxt library is well documented with example code. In particular, see NXT if you prefer high-level programming or NXTComm if you need access to low-level direct commands.

Additionally, the examples directory in the ruby-nxt distribution contains examples of some of the library’s functionality. nxt_remote_control.rb in particular provides a basic graphical (Tk) interface for controlling and monitoring the NXT.

The tests directory contains automated unit tests for testing the core NXT protocol (nxt_comm_test.rb) and and the motors (nxt_comm_test.rb), as well as an interactive test suite (test_sensor.rb) for testing the functionality of all of the sensors. It is recommended that you run all of these tests before attempting to use the ruby-nxt library in order to ensure that your NXT is behaving as expected.

To run the tests, be sure that all three motors and sensors are plugged in to the standard ports. The motors should not have any LEGO pieces attached.

How To Contribute

The ruby-nxt project is hosted on RubyForge under rubyforge.org/projects/ruby-nxt. If you have code that you would like to contribute, please contact one of the project admins via RubyForge so that we can grant you access to the subversion repository.

Read-only access to the repository is available anonymously at svn://rubyforge.org/var/svn/ruby-nxt/trunk/ruby