Skip to content

Commit

Permalink
initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Dec 23, 2012
0 parents commit c39e1b4
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
90 changes: 90 additions & 0 deletions index.js
@@ -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
}
34 changes: 34 additions & 0 deletions package.json
@@ -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"
}
}
29 changes: 29 additions & 0 deletions readme.md
@@ -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
3 changes: 3 additions & 0 deletions test.js
@@ -0,0 +1,3 @@
var logodrone = require('./')()
var logoScript = 'RT 90 FD 200 RT 200'
logodrone.convertAndSend(logoScript)

0 comments on commit c39e1b4

Please sign in to comment.