Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var RollingSpider = require('rolling-spider');
var temporal = require('temporal');
var keypress = require('keypress');
var record = require('node-record-lpcm16');
var Julius = require('julius-net');
var rollingSpider = new RollingSpider();
keypress(process.stdin);
process.stdin.setRawMode(true);
console.log("[drone event] connecting to rolling spider...");
rollingSpider.connect(function() {
rollingSpider.setup(function() {
rollingSpider.flatTrim();
rollingSpider.startPing();
rollingSpider.flatTrim();
console.log("[drone event] connected to rolling spider");
});
});
julius = new Julius({
host: '127.0.0.1',
port: 10500
});
julius.on('recognitionSuccess', function (recognition) {
var word = recognition[0]['words'][1]['word'];
console.log("[audio event] input : " + word);
if(word.indexOf("スタート") !== -1){
console.log("[drone event] send takeoff instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.takeoff({steps:12});
rollingSpider.flatTrim();
}
}
]);
}else if(word.indexOf("ストップ") !== -1){
console.log("[drone event] send land instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.land({steps:12});
}
}
]);
}else if(word.indexOf("アップ") !== -1){
console.log("[drone event] send up instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.up({steps:12});
}
}
]);
}else if(word.indexOf("ダウン") !== -1){
console.log("[drone event] send up instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.down({steps:12});
}
}
]);
}
});
process.stdin.on('keypress',function(c,key){
if(key && key.name === "up"){
console.log("[key event] input key : up");
console.log("[drone event] send forward instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.forward({steps:6});
}
}
]);
}else if(key && key.name === "down"){
console.log("[key event] input key : down");
console.log("[drone event] send backward instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.backward({steps:12});
}
}
]);
}else if(key && key.name === "left"){
console.log("[key event] input key : left");
console.log("[drone event] send tiltLeft instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.tiltLeft({steps:12});
}
}
]);
}else if(key && key.name === "right"){
console.log("[key event] input key : right");
console.log("[drone event] send tiltRight instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.tiltRight({steps:12});
}
}
]);
}else if(key && key.name === "u"){
console.log("[key event] input key : u");
console.log("[drone event] send up instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.up({steps:12});
}
}
]);
}else if(key && key.name === "d"){
console.log("[key event] input key : d");
console.log("[drone event] send down instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.down({steps:12});
}
}
]);
}else if(key && key.name === "t"){
console.log("[key event] input key : t");
console.log("[drone event] send takeoff instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.takeoff({steps:12});
rollingSpider.flatTrim();
}
}
]);
}else if(key && key.name === "l"){
console.log("[key event] input key : l");
console.log("[drone event] send land instruction");
temporal.queue([
{
delay: 5000,
task: function(){
rollingSpider.land({steps:12});
}
}
]);
}else if(key && key.ctrl && key.name === 'c'){
console.log("[key event] input key : ctrl + c");
console.log("[drone event] disconnect to rolling spider");
rollingSpider.disconnect();
process.stdin.pause();
process.exit();
}else{
if(key){
console.log("[key event] input key : "+key.name);
}else{
console.log("[key event] input key : undefined");
}
}
});
process.stdin.resume();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.