Skip to content

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

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
95cd887
Make JSHint happy.
Nov 11, 2012
efc4841
Add lookup for detection types.
Nov 11, 2012
6b08477
Add flying modes
Nov 11, 2012
dfdb6b3
Add new types based on structs from C SDK.
Nov 11, 2012
bac622c
Add two utility functions.
Nov 11, 2012
ddde825
Alter `demo` navdata block.
Nov 11, 2012
b613e99
Use `droneTimeToMilliseconds` utility function.
Nov 11, 2012
154d4c9
Be consistent with `gyrometers`
Nov 11, 2012
9877ea0
Alter `demo` navdata block.
Nov 11, 2012
7ca3214
Add all missing navdata blocks (`magneto`, `windSpeed`, `games`, etc).
Nov 11, 2012
2f89091
Add functions required for dealing with navdata masks.
Nov 11, 2012
c2c6615
Addressing spacing and syntax errors from a borked commit.
Nov 11, 2012
01e008e
Need to supply context b/c NavdataReader methods use `this`.
Nov 11, 2012
d1d3dc5
Remove detritus which is causing errors.
Nov 11, 2012
ae85943
Adding items which, somehow, were omitted from 7ca3214.
Nov 12, 2012
af8c0d8
Not entirely sure this is correct, but going with it.
Nov 12, 2012
d8d5af6
chaining
Nov 12, 2012
0e10a64
config test
Nov 12, 2012
ff9be5c
s/gyrometers/gyroscopes/g
Nov 12, 2012
7d73d46
Whitespace change
Nov 12, 2012
a14ff5c
Display wifi signal strength as a percentage
Nov 12, 2012
c8cfd40
Adding some example scripts
Nov 12, 2012
cc061b9
Updated to resemble `examples/png-stream.js`.
Nov 12, 2012
28b868d
Whitespace change.
Nov 13, 2012
86ee70c
Missed one in ff9be5c.
Nov 13, 2012
074e839
Merge branch 'master' of git://github.com/Contra/node-ar-drone
Nov 13, 2012
6fefecb
Try to ensure we're only calling properties of the passed object.
Nov 13, 2012
8a32645
Maintain consistency across examples.
Nov 16, 2012
0cdd93a
Clean up `png-stream-replace` example.
Nov 17, 2012
f97da77
fix the `navdata.demo` tests I broke.
Nov 17, 2012
8f71098
Fix `navdata.rawMeasures` tests I broke.
Nov 17, 2012
ae591cf
Reverting to approach that allows test to pass.
Nov 18, 2012
7e80cad
Fix two typos in the `navdata` keys.
Nov 18, 2012
3a4b716
Add two properties for navdata option masks.
Nov 18, 2012
f3a5900
Some guesses about units for various navdata properties.
Nov 18, 2012
b84a4f5
It's already in the `rawMeasures` object, it doesn't need `Raw` as as…
Nov 18, 2012
4a87e5b
It's in the `rawMeasures` object. It doesn't need `Raw` as a suffix, …
Nov 18, 2012
136eae4
Revert "It's in the `rawMeasures` object. It doesn't need `Raw` as a …
Nov 18, 2012
ef89029
And so ends, "`rebase -i` Fail. A four-commit play", by John Schulz.
Nov 18, 2012
0508a55
Be consistent. Units are not included in other keys.
Nov 18, 2012
7261424
Rollback d8d5af6 (especially b/c it's involved in felixge/#28).
Nov 19, 2012
e0b18c2
Revert "config test"
Nov 19, 2012
513dd17
Maintain consistent formatting.
Nov 19, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/camera-detection.js
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);
37 changes: 37 additions & 0 deletions examples/hover-over-roundel.js
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);
34 changes: 34 additions & 0 deletions examples/png-stream-replace.js
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);
});
Copy link
Owner

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.

1 change: 0 additions & 1 deletion examples/png-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var arDrone = require('..');
var http = require('http');

console.log('Connecting png stream ...');

var pngStream = arDrone.createPngStream();

var lastPng;
Expand Down
3 changes: 3 additions & 0 deletions examples/repl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var arDrone = require('..');
var client = arDrone.createClient();
client.createRepl();
24 changes: 24 additions & 0 deletions examples/takeoff-and-land.js
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();
});
57 changes: 54 additions & 3 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var constants = module.exports;

constants.getName = function(group, value) {
var group = this[group];
group = this[group];

for (var name in group) {
if (group[name] === value) {
Expand All @@ -28,7 +28,7 @@ constants.ports = {
AT : 5556,
RAW_CAPTURE : 5557,
PRINTF : 5558,
CONTROL : 5559,
CONTROL : 5559
};

// from ARDrone_SDK_2_0/ARDroneLib/Soft/Common/config.h
Expand Down Expand Up @@ -98,5 +98,56 @@ constants.options = {
HDVIDEO_STREAM : 25,
WIFI : 26,
ZIMMU_3000 : 27,
CKS : 65535,
CKS : 65535
};

constants.CAD_TYPE = {
HORIZONTAL : 0, /*<! Deprecated */
VERTICAL : 1, /*<! Deprecated */
VISION : 2, /*<! Detection of 2D horizontal tags on drone shells */
NONE : 3, /*<! Detection disabled */
COCARDE : 4, /*<! Detects a roundel under the drone */
ROUNDEL : 4, /*<! Detects a roundel under the drone */
ORIENTED_COCARDE : 5, /*<! Detects an oriented roundel under the drone */
ORIENTED_ROUNDEL : 5, /*<! Detects an oriented roundel under the drone */
STRIPE : 6, /*<! Detects a uniform stripe on the ground */
H_COCARDE : 7, /*<! Detects a roundel in front of the drone */
H_ROUNDEL : 7, /*<! Detects a roundel in front of the drone */
H_ORIENTED_COCARDE : 8, /*<! Detects an oriented roundel in front of the drone */
H_ORIENTED_ROUNDEL : 8, /*<! Detects an oriented roundel in front of the drone */
STRIPE_V : 9,
MULTIPLE_DETECTION_MODE : 10, /* The drone uses several detections at the same time */
CAP : 11, /*<! Detects a Cap orange and green in front of the drone */
ORIENTED_COCARDE_BW : 12, /*<! Detects the black and white roundel */
ORIENTED_ROUNDEL_BW : 12, /*<! Detects the black and white roundel */
VISION_V2 : 13, /*<! Detects 2nd version of shell/tag in front of the drone */
TOWER_SIDE : 14, /*<! Detect a tower side with the front camera */
NUM : 15 /*<! Number of possible values for CAD_TYPE */
};

constants.TAG_TYPE = {
NONE : 0,
SHELL_TAG : 1,
ROUNDEL : 2,
ORIENTED_ROUNDEL : 3,
STRIPE : 4,
CAP : 5,
SHELL_TAG_V2 : 6,
TOWER_SIDE : 7,
BLACK_ROUNDEL : 8,
NUM : 9
};

constants.FLYING_MODE = {
FREE_FLIGHT : 0, /**< Normal mode, commands are enabled */
HOVER_ON_TOP_OF_ROUNDEL : 1 << 0, /**< Commands are disabled, drones hovers on top of a roundel - roundel detection MUST be activated by the user with 'detect_type' configuration. */
HOVER_ON_TOP_OF_ORIENTED_ROUNDEL : 1 << 1 /**< Commands are disabled, drones hovers on top of an oriented roundel - oriented roundel detection MUST be activated by the user with 'detect_type' configuration. */
};

constants.ARDRONE_DETECTION_COLOR = {
ORANGE_GREEN : 1, /*!< Cameras detect orange-green-orange tags */
ORANGE_YELLOW : 2, /*!< Cameras detect orange-yellow-orange tags*/
ORANGE_BLUE : 3, /*!< Cameras detect orange-blue-orange tags */
ARRACE_FINISH_LINE : 0x10,
ARRACE_DONUT : 0x11
};
37 changes: 37 additions & 0 deletions lib/navdata/NavdataReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,43 @@ NavdataReader.prototype.float32 = function() {
return this.float32LE();
};

NavdataReader.prototype.char = function() {
return this._buffer[ this._offset ];
};

NavdataReader.prototype.bool = function() {
return !!this.char();
};

NavdataReader.prototype.matrix33 = function() {
return {
m11 : this.float32(),
m12 : this.float32(),
m13 : this.float32(),
m21 : this.float32(),
m22 : this.float32(),
m23 : this.float32(),
m31 : this.float32(),
m32 : this.float32(),
m33 : this.float32()
};
};

NavdataReader.prototype.vector31 = function() {
return {
x : this.float32(),
y : this.float32(),
z : this.float32()
};
};

NavdataReader.prototype.screenPoint = function() {
return {
x : this.int32(),
y : this.int32()
};
};

NavdataReader.prototype.mask32 = function(mask) {
var value = this.uint32();
return this._mask(mask, value);
Expand Down
25 changes: 25 additions & 0 deletions lib/navdata/maskingFunctions.js
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;
};
Loading