README
api-node
LocoRobo Control for Node.js
Install
$ npm install --save api-node
Installation Special Cases
The library we use for serial communication requires special build tools to be installed on your computer. The following contains instructions taken from the serialport library.
This assumes you have everything on your system necessary to compile ANY native module for Node.js. This may not be the case, though, so please ensure the following are true for your system before filing an issue about "Does not install". For all operatings systems, please ensure you have Python 2.x installed AND not 3.0, node-gyp (what we use to compile) requires Python 2.x.
Windows:
- Windows 7 or Windows 8.1 are supported.
- Install Visual Studio Express 2013 for Windows Desktop.
- If you are hacking on an Arduino, be sure to install the drivers.
- Install node.js 0.10.x matching the bitness (32 or 64) of your operating system.
- Install Python 2.7.6 matching the bitness of your operating system. For any questions, please refer to their FAQ. Default settings are perfect.
- Open the 'Visual Studio Command Prompt' and add Python to the path.
Mac OS X:
Ensure that you have at a minimum the xCode Command Line Tools installed appropriate for your system configuration. If you recently upgraded the OS, it probably removed your installation of Command Line Tools, please verify before submitting a ticket.
Desktop (Debian/Ubuntu) Linux:
You know what you need for you system, basically your appropriate analog of build-essential. Keep rocking! Ubuntu renamed the node
binary nodejs
which can cause problems building node-serialport
. The fix is simple, install the nodejs-legacy package that symlinks /usr/bin/nodejs => /usr/bin/node
or install the more up to date nodejs package from Chris Lea's PPA.
# Ubuntu node
sudo apt-get install nodejs nodejs-legacy
# Or Chris Lea's PPA Node (more up to date)
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install build-essential
npm install locorobo
Raspberry Pi Linux:
- Starting with a a vanilla New Out of the Box Software (NOOBS) Raspbian image (currently tested: 5/25/2013)
- Log into your Raspberry Pi through whatever means works best and ensure you are on a terminal prompt for the remaining steps. This could be local or through an SSH (or a serial connection if you like).
- Issue the following commands to ensure you are up to date:
sudo apt-get update
sudo apt-get upgrade -y
- Download and install node.js:
wget http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-arm-pi.tar.gz
tar xvfz node-v0.10.12-linux-arm-pi.tar.gz
sudo mv node-v0.10.12-linux-arm-pi /opt/node/
- Set up your paths correctly:
echo 'export PATH="$PATH:/opt/node/bin"' >> ~/.bashrc
source ~/.bashrc
- Install using npm, note this will take a while as it is actually compiling code and that ARM processor is getting a workout.
npm install locorobo
Usage
var api = require('locorobo-node');
return api.start('/dev/tty.usbmodem1')
.then(function(){
return api.startScanning(500)
})
.then(api.getRobots)
.then(function(robots){
return robots[Object.keys(robots)[0]];
})
.call('connect')
.call('activate')
.call('allLights', api.Color.MidnightBlue)
.call('move', api.MotorDirection.Forward, api.MotorDirection.Backward, 1, 1)
.delay(2000)
.call('kill')
.delay(500)
.call('disconnect')