Created
January 16, 2014 09:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For installing and running face:
(with glass connected)
adb install ~/path/to/face
adb shell am start -n com.iceddev.face/.MainActivity