/node-roboticscape

Node.js bindings for libroboticscape for BeagleBoard.org BeagleBone Blue or Robotics Cape

Primary LanguageC++MIT LicenseMIT

node-roboticscape

Node.js bindings for libroboticscape for BeagleBoard.org BeagleBone Blue or Robotics Cape

libroboticscape documentation

http://www.strawsondesign.com/#!manual-init-cleanup

Installation

From npm

$ sudo npm install --global roboticscape

From source

$ git clone https://github.com/jadonk/node-roboticscape
$ cd node-roboticscape
$ sudo npm install --global

Usage

var rc = require('roboticscape');

/* Allocate the userspace usage of the robotics cape features */
rc.initialize();

/* Set the state to RUNNING */
rc.state("RUNNING");

/* Exercise the robotics cape hardware */
rc.led("GREEN", true);
rc.on("PAUSE_PRESSED", function() { 
    console.log("PAUSE pressed");
    
    /* Set the state to EXITING */
    rc.state("EXITING");
});
rc.motor("ENABLE");
rc.motor(0.3);

/* Read encoder every second until PAUSE button pressed */
setInterval(function() {
    if(rc.state() == "RUNNING") {
        var enc1 = rc.encoder(1);
        console.log("encoder 1 = " + enc1);
    } else {
        /* The robotics cape userspace interface is automatically freed on exit */
        process.exit();
    }
}, 1000);

API

Table of Contents

initialize

Allocate the userspace usage of the robotics cape features and initialize the hardware functions.

See the Init and Cleanup libroboticscape documentation.

Examples

var init = rc.initialize();

Returns Number where

  • -2 : invalid contents in PID_FILE
  • -1 : existing project failed to close cleanly and had to be killed
  • 0 : No existing program is running
  • 1 : An existing program was running but it shut down cleanly.

state

Set or read the libroboticscape program state.

See the Program Flow State libroboticscape documentation.

Examples

rc.state("RUNNING");
var state = rc.state();

Parameters

  • state String state to enter must be one of "UNINITIALIZED", "RUNNING", "PAUSED" or "EXITING". If undefined, the current state will be returned instead of entering a new state.

Returns String when no arguments are provided with one of the following values

  • "UNINITIALIZED"
  • "RUNNING"
  • "PAUSED"
  • "EXITING"

led

Set the red and green user LEDs.

See the LEDs libroboticscape documentation.

Examples

rc.led("GREEN", true);

Parameters

  • led String led name to set state should be either "RED" or "GREEN".
  • state Boolean true for on and false for off.

on

Register event callbacks. Currently, only the button press events have been implemented.

See the Buttons libroboticscape documentation.

Examples

rc.on("MODE_RELEASED", function() { console.log("MODE button released."); });

Parameters

  • event String name of event should be one of "PAUSE_PRESSED", "PAUSE_RELEASED", "MODE_PRESSED" or "MODE_RELEASED".
  • callback Function function doesn't take any arguments.

motor

Control the DC motor outputs.

See the DC Motors libroboticscape documentation.

Examples

rc.motor("ENABLE");
rc.motor(1, 0.3);

Parameters

  • motor Number the motor to target. (Optional, defaults to setting the value for all motors. Remove if not used; do not just set to undefined.)
  • value String | Number value or mode to set motor or motors. Can be one of "ENABLE", "DISABLE", "FREE_SPIN", "BRAKE" or a number from -1 to 1. The "ENABLE" and "DISABLE" arguments can currently only be applied when no motor is specified.

encoder

Read and set the count on the quadrature encoder input counters.

See the Quadrature Encoder Counting libroboticscape documentation.

Examples

var enc1 = rc.encoder(1);
rc.encoder(1, 0);

Parameters

  • encoder Number the index of the encoder to read or set.
  • value Number value to which to set the encoder count. (Optional, defaults to reading only.)

Returns Number current encoder count.

adc

Read a channel of the analog-to-digital converter.

See the Analog to Digital Converter libroboticscape documentation.

Examples

var value = rc.adc(1);

Parameters

  • channel Number | String the channel to read. Possible values are "BATTERY", "DC_JACK", 0, 1, 2 or 3.

Returns Number voltage measured by the ADC on the specified channel.

imu

Read the inertial measurement unit sensor (IMU).

See the Inertial Measurment Unit libroboticscape documentation.

Examples

var state = rc.imu();

Parameters

Returns Object IMU state

  • state.accel Array<Number> accelerometer state in meters per second squared
  • state.gyro Array<Number> gyroscope state in degrees per second
  • state.mag Array<Number> magnetometer state in microteslas
  • state.temp Number thermometer state in degrees Celcius