Skip to content

Instantly share code, notes, and snippets.

@miya0001
Created September 8, 2014 18:03
Show Gist options
  • Save miya0001/435057dd685e4aeeb636 to your computer and use it in GitHub Desktop.
Save miya0001/435057dd685e4aeeb636 to your computer and use it in GitHub Desktop.
sphero-sensor
var Cylon = require('cylon');
Cylon.robot({
connection: [
{ name: 'sphero', adaptor: 'sphero', port: '/dev/cu.Sphero-PRO-AMP-SPP' }
],
device: [
{ name: 'sphero', driver: 'sphero' }
],
work: function(my) {
after((1).seconds(), function() {
console.log("Setting up Collision Detection...");
my.sphero.detectCollisions();
// To detect locator, accelOne and velocity from the sphero
// we use setDataStreaming.
// sphero API data sources for locator info are as follows:
// ['locator', 'accelOne', 'velocity']
// It is also possible to pass an opts object to setDataStreaming():
var opts = {
// n: int, divisor of the max sampling rate, 400 hz/s
// n = 40 means 400/40 = 10 data samples per second,
// n = 200 means 400/200 = 2 data samples per second
n: 100,
// m: int, number of data packets buffered before passing them to the stream
// m = 10 means each time you get data it will contain 10 data packets
// m = 1 is usually best for real time data readings.
m: 1,
// pcnt: 1 -255, how many packets to send.
// pcnt = 0 means unlimited data Streaming
// pcnt = 10 means stop after 10 data packets
pcnt: 0,
};
my.sphero.setDataStreaming(['locator'], opts);
my.sphero.configureLocator(1, 0, 0, 0);
my.sphero.startCalibration();
my.sphero.stop();
});
my.sphero.on('data', function(data) {
console.log("data:");
console.log(data);
});
my.sphero.on('collision', function(data) {
my.sphero.finishCalibration();
});
}
}).start();
{
"name": "sphero",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"cylon": "^0.18.0",
"cylon-sphero": "^0.14.1"
}
}
@miya0001
Copy link
Author

miya0001 commented Sep 8, 2014

起動するとキャリブレーションが始まって叩くと、キャリブレーションが終了。
その後、センサーの情報が送られてくる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment