You are on page 1of 46

Advanced Programming with

#nodecopter
Laurent Eschenauer
#njugbe August 2013

Laurent Eschenauer
http://eschnou.com
@eschnou

Entrepreneur, software hacker & rock climber. Cofounder/CTO of @comodit. Builder of the
#indieweb with @storytlr. Flying #nodecopter
robots with #nodejs.

ardrone-webflight

Browser-based GCS (Ground Control Station)


http://eschnou.github.io/ardrone-webflight/

ardrone-autonomy

Library to support autonomous flights


https://github.com/eschnou/ardrone-autonomy

Parrot AR Drone 2.0 http://ardrone2.parrot.com/

https://www.youtube.com/watch?v=jl5v3bsMH_E

var arDrone = require('ar-drone');


var client = arDrone.createClient();
client.takeoff();
client
.after(5000, function() {
this.clockwise(0.5);
})
.after(3000, function() {
this.animate('flipLeft', 15);
})
.after(1000, function() {
this.stop();
this.land();
});

Nodecopter Berlin, Oct 2012 Photo by Jan Marsch

Javascript
and
Robotics

client.front(speed)

client.goto(x,y,z,callback)

#1
state estimation

client.on('navdata', callback);

"controlState": "CTRL_LANDED",
"flyState": "FLYING_OK",
"batteryPercentage": 59,
"rotation": {
"pitch": -0.165,
"roll": 0.151,
"yaw": -139.978,
},
"velocity": {
"x": -1.1502487330672384e-11,
"y": -5.620504929526593e-12,
"z": 0
}

yaw

roll

pitch

vz

vx

vy

distance = speed x time

var dx
var dy

= vx * dt;
= vy * dt;

x = x + dx * Math.cos(yaw) - dy * Math.sin(yaw);
y = y + dx * Math.sin(yaw) + dy * Math.cos(yaw);

Estimating state by integrating the drone odometry

How to improve?

client.config('detect:detect_type', 12);

{
"visionDetect": {
"xc": [
259
],
"yc": [
233
],
"width": [
340
],
"height": [
454
],
"dist": [
40
],
"orientationAngle": [
3.7453956604003906
]
}

From pixels to
coordinates

Back projection from image coordinates to real world


Planar mapping from world to image space
http://www.dandiggins.co.uk/arlib-6.html

1. Predict position
2. Predict tag position
3. Observe real position (if tag visible)
4. Measure error
5. Correct pose estimate

Extended Kalman Filter

// Linear algebra in Javascript is possible :-)


var sylvester

= require('sylvester');

var Matrix
var Vector

= sylvester.Matrix;
= sylvester.Vector;

s = Matrix.I(3).subtract(K.multiply(H)).multiply(s);

Odometry only

With correction step

How to improve?

VSLAM (Visual - Simultaneous localization and mapping)

Tum AR Drone, autonomous flight with PTAM-based visual navigation for the Parrot AR.Drone.
http://www.ros.org/wiki/tum_ardrone

#2
motion control

Model of a PID controller


Wikipedia, PID Controller
https://en.wikipedia.org/wiki/File:PID_en_updated_feedback.svg

Shower Nr2 by PhotoAtelier, CC BY 2.0


http://www.flickr.com/photos/glenbledsoe/5845417144/

PID.prototype.getCommand = function(e) {
var time = Date.now();
var dt = (time - this._last_time) / 1000
var de = 0;
// Compute de (error derivation)
if (this._last_error < Infinity) {
de = (e - this._last_error) / dt;
}
// Integrate error
this._error_sum += e * dt;
// Update our trackers
this._last_time = time;
this._last_error = e;
// Compute commands
var command = this._kp * e
+ this._ki * this._error_sum
+ this._kd * de;
}

return command;

Moving the drone forward 1 meter with a PID controller

Hovering above a tag using PID contol


https://www.youtube.com/watch?v=PA0voAWISYo

#3
path planning

mission.takeoff()
.hover(500)
.altitude(2)
.forward(2)
.right(2)
.backward(2)
.go({x:0, y:0})
.hover(500)
.land();
mission.run(function (err, result) {
if (err) {
mission.client().stop();
mission.client().land();
} else {
process.exit(0);
}
})

Demo of a fully autonomous flight


https://www.youtube.com/watch?v=wPXsG_fjncM

#4
objects detection
& tracking

Open Source Computer Vision

var cv = require('opencv');
var face_cascade = new cv.CascadeClassifier('frontalface.xml');
function detectFaces() {
cv.readImage( lastPng, function(err, im) {
var opts = {};
face_cascade.detectMultiScale(im, function(err, faces) {
var face;
var biggestFace;
for(var k = 0; k < faces.length; k++) {
face = faces[k];
if( !biggestFace
|| biggestFace.width < face.width ) {
biggestFace = face;
}
}
}

io.sockets.emit('face', face);

Face tracking in WebFlight


https://github.com/eschnou/webflight-copterface

one more thing...

// Land on ctrl-c
process.on('SIGINT', function() {
mission.control().disable();
mission.client().land(function() {
process.exit(0);
});
});

References
node-ar-drone library
https://github.com/felixge/node-ar-drone
Ardrone 2.0 SDK
https://projects.ardrone.org/
Visual Navigation for Flying Robots
http://vision.in.tum.de/teaching/ss2013/visnav2013

You might also like