Skip to content

Commit

Permalink
Merge pull request #18 from shundroid/gifter-labo
Browse files Browse the repository at this point in the history
fixed #17
  • Loading branch information
yammmt committed Mar 12, 2016
2 parents 6fe96f6 + 4776fc6 commit f51401d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backside.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ module.exports = {
connect: function(port, callback) {
var orb = sphero(port);
orb.connect(function() {
orb.detectCollisions(); // 衝突判定を有効化
console.log("準備開始");
console.log("準備開始");
orb.startCalibration(); // 位置関係の補正
setTimeout(function() {
console.log("準備終了");
orb.finishCalibration();
orb.detectCollisions(); // 衝突判定を有効化
callback(orb);
}, 10000);
});
Expand Down
21 changes: 21 additions & 0 deletions isStop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var sphero = require("sphero");
var orb = sphero("COM3");

orb.connect(function() {
orb.startCalibration();
setTimeout(function() {
orb.finishCalibration();
orb.streamAccelerometer(10);
setInterval(function() {
orb.roll(255, 0);
}, 500);
orb.on("accelerometer", function(data) {
console.log(data.xAccel.value[0] + ", " + data.zAccel.value[0]);
// if (data.xAccel.value[0] < -600 || data.zAccel.value[0] < -600) {
// console.log("動いている");
// } else {
// console.log("止まっている");
// }
});
}, 5000);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "main.js",
"dependencies": {},
"devDependencies": {
"keypress": "^0.2.1",
"sphero": "^0.7.0"
},
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions velocity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var sphero = require("sphero");
var orb = sphero("COM7");

orb.connect(function() {
orb.startCalibration();

setTimeout(function() {
orb.finishCalibration();
orb.streamAccelerometer();
setInterval(function() {
orb.roll(255, 0);
}, 500);
orb.on("accelerometer", function(data) {
console.log("data:");
console.log(" xAccel:", data.xAccel);
console.log(" yAccel:", data.yAccel);
console.log(" zAccel:", data.zAccel);
});
}, 5000);
});
21 changes: 16 additions & 5 deletions ziguzagu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var backside = require("./backside");
var keypress = require("keypress");

// 自分の Sphero の ID に置き換える
var port = "/dev/tty.Sphero-YRW-AMP-SPP";
Expand All @@ -10,20 +11,31 @@ var angles = [
];
var currentAnglePoint = 0;

var graph = [];

// 接続された時に呼び出されます。
function connect() {
orb.color(orbDefaultColor);
setTimeout(loop, loopInterval);
// ここに処理を書きます
backside.move(255,angles[currentAnglePoint%5], orb);
currentAnglePoint++;
backside.move(255,angles[Math.max(currentAnglePoint++, angles.length)], orb);

orb.streamAccelerometer();

orb.on("accelerometer", function(data) {
if (Math.abs(data.xAccel.value[0]) < 1000) {
console.log("止まっている");
} else {
console.log("動いている");
}
});
// ここまで
}

// メインとなるループ処理(上のloopIntervalの間隔で呼び出されます)
function loop() {
// ここに処理を書きます

// ここまで
setTimeout(loop, loopInterval);
}
Expand All @@ -35,8 +47,7 @@ function collision() {
setTimeout(function() {
orb.color("green");
}, 500);
backside.move(255,angles[currentAnglePoint%5], orb);
currentAnglePoint++;
backside.move(255,angles[Math.max(currentAnglePoint++, angles.length)], orb);
// ここまで
}

Expand Down

0 comments on commit f51401d

Please sign in to comment.