Skip to content

Instantly share code, notes, and snippets.

@napolux
Created September 29, 2015 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save napolux/3f5e37f1a54e5a4b1e58 to your computer and use it in GitHub Desktop.
Save napolux/3f5e37f1a54e5a4b1e58 to your computer and use it in GitHub Desktop.
Connecting to a Parrot Rolling Spider Drone with Node.js
'use strict';
var keypress = require('keypress');
var Drone = require('rolling-spider');
var colors = require('colors');
// Change this with your drone name...
var DRONE_NAME = 'RS_W123456';
var ACTIVE = true;
var STEPS = 4;
function cooldown() {
ACTIVE = false;
setTimeout(function () {
ACTIVE = true;
}, STEPS * 12);
}
// Setup...
keypress(process.stdin);
process.stdin.setRawMode(true);
process.stdin.resume();
// call "node test.js debug" to print out debug...
if (typeof(process.argv[2]) != 'undefined' && process.argv[2] == 'debug') {
var d = new Drone({'logger': console.log});
} else {
var d = new Drone();
}
d.connect(function () {
d.setup(function () {
console.log('[INFO] Connected to:'.green, d.name.green);
if(d.name != DRONE_NAME) {
console.log('[ERROR] Connected to the wrong drone: '.red + d.name.red);
console.log('[ERROR] Goodbye!'.red);
try {
d.disconnect();
} catch(err) {
console.log('[ERROR] '.red + err.red);
}
console.log('***** GOODBYE! *****'.rainbow);
process.exit();
}
// Initial ping...
d.flatTrim();
d.startPing();
d.flatTrim();
d.on('battery', function () {
if(+d.status.battery <= 20) {
console.log('[WARNING] Battery low: '.red + d.status.battery.toString().red + '%'.red);
}
});
setTimeout(function () {
console.log('[INFO] Ready to fly'.green);
ACTIVE = true;
}, 1000);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment