Skip to content

Instantly share code, notes, and snippets.

@pushmatrix
Created January 16, 2014 09:30
Show Gist options
  • Save pushmatrix/8452128 to your computer and use it in GitHub Desktop.
Save pushmatrix/8452128 to your computer and use it in GitHub Desktop.
Controlling a drone with google glass. Requires you install and run https://github.com/monteslu/Face on glass.
var WebSocket = require('ws');
var arDrone = require('ar-drone')
var ws = new WebSocket('ws://192.168.1.237:1338', {protocolVersion: 8});
ws.on('open', function() {
console.log('connected');
ws.send(Date.now().toString(), {mask: true});
});
ws.on('close', function() {
console.log('disconnected');
});
ws.on('message', function(data, flags) {
try {
data = JSON.parse(data);
processMessage(data);
} catch(err) {
console.log(err)
}
});
var drone = arDrone.createClient({
ip: '192.168.1.50'
});
var prevZ;
var prevX;
function processMessage(message) {
if(message.buttons.B){
console.log('land')
drone.land();
} else if (message.buttons.A){
console.log('takeoff')
drone.takeoff();
}
if(message.orientation){
console.log(message.orientation.roll)
var z = message.orientation.pitch;
var x = message.orientation.roll;
if(prevZ == null){
prevZ = z;
}
var direction;
if(z > -75){
direction = 'forward';
drone.front(1);
} else if(z < -100){
direction = 'backward';
drone.back(1);
} else {
direction = 'still';
drone.stop();
}
if(direction === 'still'){
if(x > 25){
drone.left(1);
} else if(x < -25){
drone.right(1);
} else {
drone.stop();
}
}
prevZ = z;
prevX = x;
} else {
drone.stop();
}
}
@pushmatrix
Copy link
Author

For installing and running face:

(with glass connected)

adb install ~/path/to/face
adb shell am start -n com.iceddev.face/.MainActivity

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