OCaml Mindstorm is a library that enables to drive LEGOŽ mindstorm robots from OCaml through a Bluetooth or USB connection.
Mindstorm |
OCaml-mindstorm is a library that enables you to drive Lego
mindsotrm NXT bricks from OCaml (the computer is the master and
the brick is the slave).
|
Index of types
Index of exceptions
Index of values
Index of modules
You need to create a serial port connection using the instructions
below for your platform. Then use Mindstorm.connect_bluetooth
to
create a handle for the brick.
First make sure your kernel has bluetooth support (this is likely) and that the bluez and bluez-gnome (or kdebluetooth) pakages are installed. You should see a bluetooth applet icon. Then do (the text after the $ sign is what you type, underneath is the answer):
$ hcitool scan Scanning ... 00:16:53:03:A5:32 NXT
to discover the address of your brick. Then use
Mindstorm.connect_bluetooth "00:16:53:03:A5:32"
to establish the
connection (of course, replace "00:16:53:03:A5:32" by your actual
bluetooth address) -- the first time, the brick will ask you to enter
a code and the bluetooth applet will pop up a box in which you need to
copy the very same code (this is to forbid unwanted connections).
We follow here the instructions "Bluetooth Serial Port To NXT in OSX":
NXT
(or whatever your brick is called but NXT
is the factory
setting so we'll use that from now on) from the list and click continue;NXT
(or whatever your brick is
called) listed, select it, then click "Edit Serial Ports";NXT-DevB-1
(replace NXT
by the name of your
brick), if not click add, use Port Name: NXT-DevB-1
, Device
Service: Dev B, Port type: RS-232. Click Apply.
You're done! You should now have a /dev/tty.NXT-DevB-1
.
Now you can connect to the brick using Mindstorm.connect_bluetooth
"/dev/tty.NXT-DevB-1"
. Beware that if you rename the brick with
Mindstorm.set_brick_name
, you will have to change the TTY device
accordingly.
From windows, open the bluetooth control panel, create a new
connection to the NXT brick, right click on your connection and select
"details" to see which serial port is used, for example COM40. Then
use Mindstorm.connect_bluetooth "COM40"
to connect to the brick from
your programs. ATM, you have to always start by establishing the
connection by hand before you can use the brick. Patches are welcome
so that is is enough to pass the bluetooth address to
Mindstorm.connect_bluetooth
and the library performs the
connection.
Windows Vista uses different ports for outgoing and incoming connections (e.g. COM4 for outgoing connections and COM5 for incoming ones). With this library, you must use the outgoing port.
See also ruby-serialport/nxt on Windows with Cygwin.
Once the fantom drivers are on your machine (which is the case if you installed the LEGOŽ NXTG software), the above method does not work anymore. It is then probably necessary to use these drivers through the Driver SDK. This will be investigated in a subsequent revision of this library.
Create a lego
group, add your user to it and create a file
/etc/udev/rules.d/70-lego.rules
containing
# Lego NXT -*-conf-*- BUS=="usb", SYSFS{idVendor}=="0694", GROUP="lego", MODE="0660" # Links for specific bricks (use udevinfo to find the serial) SYSFS{idVendor}=="0694", SYSFS{serial}=="xxxxxxxxxxxx", SYMLINK+="lego"
To be completed.
TBD.
you need the LEGOŽ Mindstorms NXT software installed, as its USB
drivers are used. ???