Fixed null pointer in tag detection

Esse commit está contido em:
Laurent Eschenauer
2013-06-19 07:08:48 +02:00
commit 05ee621bfe
2 arquivos alterados com 55 adições e 14 exclusões
+47 -13
Ver Arquivo
@@ -1,13 +1,32 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var df = require('dateformat'); var df = require('dateformat')
var arDrone = require('ar-drone'); , arDrone = require('ar-drone')
var autonomy = require('..'); , arDroneConstants = require('ar-drone/lib/constants')
, autonomy = require('..');
var client = arDrone.createClient(); var client = arDrone.createClient();
var ctrl = new autonomy.Controller(client, {debug: false}); var ctrl = new autonomy.Controller(client, {debug: false});
var repl = client.createRepl(); var repl = client.createRepl();
function navdata_option_mask(c) {
return 1 << c;
}
// From the SDK.
var navdata_options = (
navdata_option_mask(arDroneConstants.options.DEMO)
| navdata_option_mask(arDroneConstants.options.VISION_DETECT)
| navdata_option_mask(arDroneConstants.options.MAGNETO)
| navdata_option_mask(arDroneConstants.options.WIFI)
);
// Connect and configure the drone
client.config('general:navdata_demo', true);
client.config('general:navdata_options', navdata_options);
client.config('video:video_channel', 1);
client.config('detect:detect_type', 12);
// Add a ctrl object to the repl. You can use the controller // Add a ctrl object to the repl. You can use the controller
// from there. E.g. // from there. E.g.
// ctrl.go({x:1, y:1}); // ctrl.go({x:1, y:1});
@@ -15,16 +34,31 @@ var repl = client.createRepl();
repl._repl.context['ctrl'] = ctrl; repl._repl.context['ctrl'] = ctrl;
// Log navdata and estimated state - for debugging // Log navdata and estimated state - for debugging
// var folder = df(new Date(), "yyyy-mm-dd_hh-MM-ss");
// var folder = df(new Date(), "yyyy-mm-dd_hh-MM-ss"); fs.mkdir(path.join('/tmp', folder), function() {
// fs.mkdir(path.join('/tmp', folder), function() { dataStream = fs.createWriteStream(path.join('/tmp', folder, 'data.txt'));
// navStream = fs.createWriteStream(path.join('/tmp', folder, 'navdata.txt')); });
// stateStream = fs.createWriteStream(path.join('/tmp', folder, 'state.txt'));
// });
//client.on('navdata', function(data) { client.on('navdata', function(data) {
// navStream.write(JSON.stringify(data) + "\n"); var state = ctrl.state()
// stateStream.write(JSON.stringify(ctrl.state()) + "\n"); , cmds = ctrl.commands()
//}); , vx = data.demo.velocity.x / 1000
, vy = data.demo.velocity.y / 1000
, vz = data.demo.velocity.z / 1000
, x = state.x
, y = state.y
, z = state.z
, yaw = state.yaw
, cx = cmds.cx
, cy = cmds.cy
, cz = cmds.cz
, cyaw = cmds.cyaw
, tag = (data.visionDetect && data.visionDetect.nbDetected > 0)
;
dataStream.write(x + "," + y + "," + z + "," + yaw + ","
+ vx + "," + vy + "," + vz +"," + cx + ","
+ cy + "," + cz + "," + cyaw + "," + tag + "\n");
});
+8 -1
Ver Arquivo
@@ -23,6 +23,7 @@ function Controller(client, options) {
this._enabled = false; this._enabled = false;
this._client = client; this._client = client;
this._goal = null; this._goal = null;
this._cmds = {cx: 0, cy: 0, cz: 0, cyaw: 0};
var self = this; var self = this;
client.on('navdata', function(d) { client.on('navdata', function(d) {
@@ -56,6 +57,10 @@ Controller.prototype.state = function() {
return this._state; return this._state;
} }
Controller.prototype.commands = function() {
return this._cmds;
}
/* /*
* Sets a new goal and enable the controller. When the goal * Sets a new goal and enable the controller. When the goal
* is reached, the callback is called with the current state. * is reached, the callback is called with the current state.
@@ -105,7 +110,7 @@ Controller.prototype._processNavdata = function(d) {
// back-projecting the pixel position p(x,y) to the drone // back-projecting the pixel position p(x,y) to the drone
// coordinate system P(X,Y). // coordinate system P(X,Y).
// TODO: Should we use dist or the measure altitude ? // TODO: Should we use dist or the measure altitude ?
var measured = camera.p2m(xc + wc/2, yc + hc/2, dist); var measured = this._camera.p2m(xc + wc/2, yc + hc/2, dist);
// Rotation is provided by the drone, we convert to radians // Rotation is provided by the drone, we convert to radians
measured.yaw = yaw.toRad(); measured.yaw = yaw.toRad();
@@ -192,6 +197,8 @@ Controller.prototype._control = function() {
} }
} }
this._cmds = {cx: cx, cy: cy, cz: cz, cyaw: cyaw};
if (this._debug) { if (this._debug) {
console.log("--------------------- Control step ----------------------------------------------"); console.log("--------------------- Control step ----------------------------------------------");
console.log("Goal: \t %d,%d,%d,%d", this._goal.x, this._goal.y, this._goal.z, this._goal.yaw); console.log("Goal: \t %d,%d,%d,%d", this._goal.x, this._goal.y, this._goal.z, this._goal.yaw);