-
Notifications
You must be signed in to change notification settings - Fork 427
Add remaining navdata options #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 40 commits
95cd887
efc4841
6b08477
dfdb6b3
bac622c
ddde825
b613e99
154d4c9
9877ea0
7ca3214
2f89091
c2c6615
01e008e
d1d3dc5
ae85943
af8c0d8
d8d5af6
0e10a64
ff9be5c
7d73d46
a14ff5c
c8cfd40
cc061b9
28b868d
86ee70c
074e839
6fefecb
8a32645
0cdd93a
f97da77
8f71098
ae591cf
7e80cad
3a4b716
f3a5900
b84a4f5
4a87e5b
136eae4
ef89029
0508a55
7261424
e0b18c2
513dd17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var arDrone = require('..'); | ||
var constants = require('../lib/constants'); | ||
var maskingFunctions = require('../lib/navdata/maskingFunctions'); | ||
var TAG_TYPE_MASK = maskingFunctions.TAG_TYPE_MASK; | ||
var maskFromNavdataOptions = maskingFunctions.maskFromNavdataOptions; | ||
|
||
// get a reference to the drone | ||
var client = arDrone.createClient(); | ||
|
||
// log all errors | ||
client.on('error', function (err) { | ||
console.log('ERROR:', err); | ||
}); | ||
|
||
// increase the frequency of the navadata updates | ||
client.config('general:navdata_demo', 'FALSE'); | ||
|
||
// control the keys in the navdata | ||
var optionsMask = maskFromNavdataOptions( | ||
constants.options.DEMO, | ||
constants.options.VISION_DETECT, | ||
constants.options.EULER_ANGLES | ||
); | ||
client.config('general:navdata_options', optionsMask); | ||
|
||
// detect multiple tag types | ||
client.config('detect:detect_type', constants.CAD_TYPE.MULTIPLE_DETECTION_MODE); | ||
|
||
// look for oriented roundel underneath | ||
var vMask = TAG_TYPE_MASK(constants.TAG_TYPE.H_ORIENTED_ROUNDEL); | ||
client.config('detect:detections_select_v', vMask); | ||
|
||
// look for a shell tag in front | ||
var hMask = TAG_TYPE_MASK(constants.TAG_TYPE.SHELL_TAG_V2); | ||
client.config('detect:detections_select_h', hMask); | ||
|
||
// log navdata | ||
client.on('navdata', console.log); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var arDrone = require('..'); | ||
var constants = require('../lib/constants'); | ||
var maskingFunctions = require('../lib/navdata/maskingFunctions'); | ||
var maskFromNavdataOptions = maskingFunctions.maskFromNavdataOptions; | ||
|
||
// get a reference to the drone | ||
var client = arDrone.createClient(); | ||
|
||
// log all errors | ||
client.on('error', function (err) { | ||
console.log('ERROR:', err); | ||
}); | ||
|
||
// increase the frequency of the navadata updates | ||
client.config('general:navdata_demo', 'FALSE'); | ||
|
||
// control the keys in the navdata | ||
var optionsMask = maskFromNavdataOptions( | ||
constants.options.DEMO, | ||
constants.options.VISION_DETECT, | ||
constants.options.EULER_ANGLES | ||
); | ||
client.config('general:navdata_options', optionsMask); | ||
|
||
// detect multiple tag types | ||
client.config('detect:detect_type', constants.CAD_TYPE.ORIENTED_ROUNDEL); | ||
|
||
// set the drone's "flying mode" | ||
var flyingMode = constants.FLYING_MODE.HOVER_ON_TOP_OF_ORIENTED_ROUNDEL; | ||
client.config('control:flying_mode', flyingMode); | ||
|
||
// set the altitude where the drone should hover | ||
var millimeters = 1000; | ||
client.config('control:hovering_range', millimeters); | ||
|
||
// log navdata | ||
client.on('navdata', console.log); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Run this to receive a png image stream from your drone. | ||
|
||
var arDrone = require('..'); | ||
var http = require('http'); | ||
var server = http.createServer(function(req, res) { | ||
|
||
var pngStream; | ||
if (!pngStream) { | ||
pngStream = arDrone.createPngStream(); | ||
pngStream.on('error', function (err) { | ||
console.error('pngStream ERROR: ' + err); | ||
}); | ||
} | ||
|
||
var boundary = 'boundary'; | ||
res.writeHead(200, { | ||
'Content-Type': 'multipart/x-mixed-replace; boundary=' + boundary | ||
}); | ||
|
||
pngStream.on('data', function writePart(pngBuffer) { | ||
// part header | ||
res.write('--' + boundary + '\n'); | ||
res.write('Content-Type: image/png\n'); | ||
res.write('Content-length: ' + pngBuffer.length + '\n'); | ||
res.write('\n'); | ||
// part body | ||
res.write(pngBuffer); | ||
}); | ||
}); | ||
|
||
var port = 8080; | ||
server.listen(port, function () { | ||
console.log('Serving latest png on', port); | ||
}); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,16 @@ var arDrone = require('..'); | |
var http = require('http'); | ||
|
||
console.log('Connecting png stream ...'); | ||
|
||
var pngStream = arDrone.createPngStream(); | ||
|
||
var lastPng; | ||
pngStream | ||
.on('error', console.log) | ||
.on('data', function(pngBuffer) { | ||
.on('data', function (pngBuffer) { | ||
lastPng = pngBuffer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use spaces after the function keyword in an unnamed function (to keep in sync with the style used in the project). |
||
}); | ||
|
||
var server = http.createServer(function(req, res) { | ||
var server = http.createServer(function (req, res) { | ||
if (!lastPng) { | ||
res.writeHead(503); | ||
res.end('Did not receive any png data yet.'); | ||
|
@@ -25,7 +24,7 @@ var server = http.createServer(function(req, res) { | |
res.end(lastPng); | ||
}); | ||
|
||
server.listen(8080, function() { | ||
server.listen(8080, function () { | ||
console.log('Serving latest png on port 8080 ...'); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var arDrone = require('..'); | ||
var client = arDrone.createClient(); | ||
client.createRepl(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var arDrone = require('..'); | ||
var client = arDrone.createClient(); | ||
|
||
// return all navdata | ||
client.config('general:navdata_demo', 'FALSE'); | ||
|
||
// log navdata | ||
client.on('navdata', function (navdata) { | ||
console.log('// NAVDATA\n', navdata); | ||
}); | ||
|
||
client.on('error', function (err) { | ||
console.log('ERROR:', err); | ||
}); | ||
|
||
client | ||
.after(2*1000, function () { | ||
console.log('// TAKEOFF\n'); | ||
this.takeoff(); | ||
}) | ||
.after(8*1000, function () { | ||
console.log('// LAND\n'); | ||
this.land(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ Client.prototype.resume = function() { | |
this._udpNavdatasStream | ||
.on('error', this._maybeEmitError.bind(this)) | ||
.on('data', this._handleNavdata.bind(this)); | ||
return this; | ||
}; | ||
|
||
Client.prototype._handleNavdata = function(navdata) { | ||
|
@@ -134,30 +135,39 @@ Client.prototype._sendCommands = function() { | |
|
||
Client.prototype.disableEmergency = function() { | ||
this._disableEmergency = true; | ||
return this; | ||
}; | ||
|
||
Client.prototype.takeoff = function() { | ||
this._ref.fly = true; | ||
return true; | ||
return this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be part of this patch. In fact, there is a second pull request open that tries to achieve this as well, but it's problematic for the REPL: |
||
}; | ||
|
||
Client.prototype.land = function() { | ||
this._ref.fly = false; | ||
return true; | ||
return this; | ||
}; | ||
|
||
Client.prototype.stop = function() { | ||
this._pcmd = {}; | ||
return true; | ||
return this; | ||
}; | ||
|
||
Client.prototype.config = function(key, value) { | ||
if (typeof key === "object") { | ||
for (var k in key) { | ||
if (Object.hasOwnProperty.call(key, k)) this.config(k, key[k]); | ||
} | ||
return this; | ||
} | ||
|
||
// @TODO Figure out if we can get a ACK for this, so we don't need to | ||
// repeat it blindly like this | ||
var self = this; | ||
this._repeat(10, function() { | ||
self._udpControl.config(key, value); | ||
}); | ||
return this; | ||
}; | ||
|
||
Client.prototype.animate = function(animation, duration) { | ||
|
@@ -167,6 +177,7 @@ Client.prototype.animate = function(animation, duration) { | |
this._repeat(10, function() { | ||
self._udpControl.animate(animation, duration); | ||
}); | ||
return this; | ||
}; | ||
|
||
Client.prototype.animateLeds = function(animation, hz, duration) { | ||
|
@@ -176,6 +187,7 @@ Client.prototype.animateLeds = function(animation, hz, duration) { | |
this._repeat(10, function() { | ||
self._udpControl.animateLeds(animation, hz, duration); | ||
}); | ||
return this; | ||
}; | ||
|
||
Client.prototype._repeat = function(times, fn) { | ||
|
@@ -196,7 +208,7 @@ pcmdOptions.forEach(function(pair) { | |
this._pcmd[pair[0]] = speed; | ||
delete this._pcmd[pair[1]]; | ||
|
||
return speed; | ||
return this; | ||
}; | ||
|
||
Client.prototype[pair[1]] = function(speed) { | ||
|
@@ -205,6 +217,6 @@ pcmdOptions.forEach(function(pair) { | |
this._pcmd[pair[1]] = speed; | ||
delete this._pcmd[pair[0]]; | ||
|
||
return speed; | ||
return this; | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var constants = require('../constants'); | ||
|
||
exports.NAVDATA_NUM_TAGS = Object.keys(constants.options).length; | ||
exports.NAVDATA_OPTION_FULL_MASK = (1<<exports.NAVDATA_NUM_TAGS) - 1; | ||
|
||
exports.TAG_TYPE_MASK = function (tagtype) { | ||
return (tagtype == 0) ? 0 : 1 << (tagtype - 1); | ||
}; | ||
|
||
exports.NAVDATA_OPTION_MASK = function (option) { | ||
return 1 << option; | ||
}; | ||
|
||
exports.maskFromNavdataOptions = function (options) { | ||
if (!Array.isArray(options)) { | ||
options = Array.prototype.slice.call(arguments); | ||
} | ||
|
||
var masks = options.map(exports.NAVDATA_OPTION_MASK); | ||
var mask = masks.reduce(function (prev, curr) { | ||
return prev | curr; | ||
}); | ||
|
||
return mask; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet example. I'm happy to merge it along with this patch, but it doesn't really belong to it I think.