Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c39e1b4
Showing
5 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
var logo = require('logo') | ||
var arDrone = require('ar-drone') | ||
|
||
function LogoDrone(droneOptions) { | ||
this.droneOptions = droneOptions | ||
this.drone = arDrone.createClient(this.droneOptions) | ||
return this | ||
} | ||
|
||
module.exports = function(droneOptions) { | ||
return new LogoDrone(droneOptions) | ||
} | ||
|
||
module.exports.LogoDrone = LogoDrone | ||
|
||
LogoDrone.prototype.convert = function(commands, cb) { | ||
var self = this | ||
logo.convert(commands, function(err, obj) { | ||
if (err) return cb(err) | ||
var droneCommands = self.translateToDroneLanguage(obj) | ||
cb(false, droneCommands) | ||
}) | ||
} | ||
|
||
LogoDrone.prototype.convertAndSend = function(logoString) { | ||
var self = this | ||
self.convert(logoString, function(err, instructions) { | ||
console.log('sending', logoString, 'to drone:') | ||
self.sendInstructions(instructions) | ||
}) | ||
} | ||
|
||
LogoDrone.prototype.sendInstructions = function(instructions) { | ||
var self = this | ||
var time = 0 | ||
var tookoff = false | ||
self.drone.disableEmergency() | ||
instructions.map(function(cmd) { | ||
if (cmd.command === "takeoff" && tookoff) cmd.command = "land" | ||
setTimeout(function() { self.drone[cmd.command](cmd.arg) }, time) | ||
console.log(cmd.command, cmd.arg ? cmd.arg : '', 'at', time) | ||
if (cmd.duration) { | ||
time = time + cmd.duration | ||
setTimeout(self.drone.stop, time) | ||
console.log('stop', 'at', time) | ||
if (['front', 'back'].indexOf(cmd.command) > -1) { | ||
time = time + 2000 | ||
} | ||
} | ||
if (cmd.command === "takeoff") tookoff = true | ||
}) | ||
} | ||
|
||
LogoDrone.prototype.convertTurnToTime = function(degrees) { | ||
return +degrees * 20 | ||
} | ||
|
||
LogoDrone.prototype.convertDistanceToTime = function(degrees) { | ||
return +degrees | ||
} | ||
|
||
LogoDrone.prototype.translateToDroneLanguage = function(commands) { | ||
var self = this | ||
var droneable = ['begin', 'move', 'turn', 'end'] | ||
var cmds = [] | ||
commands.map(function(cmd) { | ||
var key = Object.keys(cmd)[0] | ||
if (droneable.indexOf(key) > -1) { | ||
if (key === 'begin') cmds.push({command: 'takeoff', duration: 6000}) | ||
if (key === 'end') cmds.push({command: 'land', duration: 4000}) | ||
if (key === 'turn') { | ||
var degrees = cmd[key] | ||
if (degrees >= 0) { | ||
cmds.push({command: 'clockwise', arg: 0.5, duration: self.convertTurnToTime(degrees)}) | ||
} else { | ||
cmds.push({command: 'counterClockwise', arg: 0.5, duration: self.convertTurnToTime(degrees)}) | ||
} | ||
} | ||
if (key === 'move') { | ||
var distance = cmd[key] | ||
if (distance >= 0) { | ||
cmds.push({command: 'front', arg: 0.5, duration: self.convertDistanceToTime(distance)}) | ||
} else { | ||
cmds.push({command: 'back', arg: 0.5, duration: self.convertDistanceToTime(distance)}) | ||
} | ||
} | ||
} | ||
}) | ||
return cmds | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "logo-drone", | ||
"description": "control the parrot AR drone using the LOGO programming language", | ||
"version": "0.0.1", | ||
"main": "index.js", | ||
"bin": { | ||
"logodrone": "bin.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/maxogden/logo-drone.git" | ||
}, | ||
"keywords": [ | ||
"drone", | ||
"parrot", | ||
"ardrone", | ||
"logo", | ||
"nodecopter" | ||
], | ||
"scripts": { | ||
"test": "node test.js" | ||
}, | ||
"dependencies": { | ||
"logo": "0.1.2" | ||
}, | ||
"author": { | ||
"name": "Max Ogden", | ||
"email": "max@maxogden.com" | ||
}, | ||
"license": "BSD", | ||
"engine": { | ||
"node": ">=0.6.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# logo-drone (aka turtle-drone) | ||
|
||
control the parrot AR drone (aka [the nodecopter](http://nodecopter.com)) using the LOGO programming language | ||
|
||
uses the excellent js [streaming LOGO interpreter](http://github.com/thisandagain/logo) written by [@thisandagain](http://github.com/thisandagain) | ||
|
||
## usage | ||
|
||
```javascript | ||
var logodrone = require('logo-drone')(droneClientOptions) | ||
var logoScript = 'RT 90 FD 200 RT 200' | ||
|
||
logodrone.convert(logoScript, function(err, instructions) { | ||
logodrone.sendInstructions(instructions) | ||
}) | ||
|
||
// or more simply: | ||
|
||
logodrone.convertAndSend(logoScript) | ||
``` | ||
|
||
## videos | ||
|
||
http://www.youtube.com/watch?v=weV9ePxKo68 | ||
http://www.youtube.com/watch?v=M3s9Iwx2NsQ | ||
|
||
## license | ||
|
||
BSD |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var logodrone = require('./')() | ||
var logoScript = 'RT 90 FD 200 RT 200' | ||
logodrone.convertAndSend(logoScript) |