An API for interacting with an iRobot Create. Because robots are fun.
The iRobot Create provides a low-level serial protocol called the "Open Interface" (OI) documented here. What this library attempts to do is implement a simple and intuitive API on top of OI in node.js using the great serialport library.
npm install --save create-oi
After plugging in your Create USB cable you'll need to find out what serial port your operating system has assigned your Create.
On linux:
$ dmesg | grep tty
On a mac:
$ ls /dev/tty.*
On a windows box, open device manager and look under "Ports":
C:\> mmc devmgmt.msc
In your code you'll probably want to start with these two lines:
var robot = require("create-oi");
robot.init({ serialport: "/dev/tty.usbserial-A2001nf6", version: 1 }); // use version: 2 if using a Create2
Make sure to set your serialport to the device name you found earlier.
On my mac for me this is "/dev/tty.usbserial-A2001nf6". Yours will be different.
The API is event-based, meaning all the important stuff happens in event callbacks.
The first event you'll need to deal with is the ready event which gets fired when
the module sucessfully connects to the Create over the serial port. Note that the
this context for all your callback handlers will be set to the create-oi module
itself, so you can easily call drive, rotate or any other module method within a
callback. Several events such as bump or wheeldrop will contain information about
which specific sensor was triggered inside the event parameter passed into your
callback function.
robot.on('ready', function() {
// twirl towards freedom
this.rotate(100);
});
robot.on('bump', function(bumpEvent) {
console.log(bumpEvent.direction);
...
});
Working examples (provided you change the serial port) can be found in the examples directory.
See the API Reference on the wiki.
Hacker News (1)
JavaScript
100.0%
An API for interacting with an iRobot Create. Because robots are fun.
The iRobot Create provides a low-level serial protocol called the "Open Interface" (OI) documented here. What this library attempts to do is implement a simple and intuitive API on top of OI in node.js using the great serialport library.
npm install --save create-oi
After plugging in your Create USB cable you'll need to find out what serial port your operating system has assigned your Create.
On linux:
$ dmesg | grep tty
On a mac:
$ ls /dev/tty.*
On a windows box, open device manager and look under "Ports":
C:\> mmc devmgmt.msc
In your code you'll probably want to start with these two lines:
var robot = require("create-oi");
robot.init({ serialport: "/dev/tty.usbserial-A2001nf6", version: 1 }); // use version: 2 if using a Create2
Make sure to set your serialport to the device name you found earlier.
On my mac for me this is "/dev/tty.usbserial-A2001nf6". Yours will be different.
The API is event-based, meaning all the important stuff happens in event callbacks.
The first event you'll need to deal with is the ready event which gets fired when
the module sucessfully connects to the Create over the serial port. Note that the
this context for all your callback handlers will be set to the create-oi module
itself, so you can easily call drive, rotate or any other module method within a
callback. Several events such as bump or wheeldrop will contain information about
which specific sensor was triggered inside the event parameter passed into your
callback function.
robot.on('ready', function() {
// twirl towards freedom
this.rotate(100);
});
robot.on('bump', function(bumpEvent) {
console.log(bumpEvent.direction);
...
});
Working examples (provided you change the serial port) can be found in the examples directory.
See the API Reference on the wiki.
Hacker News (1)
JavaScript
100.0%