8. fly.js
var arDrone = require('ar-drone'); //RTFM for flying commands etc
var http = require('http');
var client = arDrone.createClient();
var options = {host: '127.0.0.1’, port: 3000, path: '/api/raw', method: 'POST'};
var counter = 0; // naïve sampling counter
client.config('general:navdata_demo', 'FALSE'); // get all the data from the sensors
client.takeoff();
client
.after(3000, function() {
this.down(0.1);
})
.after(1000, function(){
this.stop();
this.land();
});
9. fly.js - logging to dashboard
client.on('navdata', function(data){ // on receiving navdata, send data to dashboard
counter = counter + 1;
if(counter > 50){ // only send every 50th data header
counter = 0;
var raw_data_header = new Object();
if(data.rawMeasures && data.demo && data.pwm){ // data not always contains demo & pwm
raw_data_header = {
header: {
time: data.time
, sequenceNumber: data.sequenceNumber
, flying: data.droneState.flying
, batteryMilliVolt: data.rawMeasures.batteryMilliVolt
, altitude: data.demo.altitude
, velocity: {x: data.demo.xVelocity
, y: data.demo.yVelocity
, z: data.demo.zVelocity}
, throttle: {forward: data.pwm.gazFeedForward
, height: data.pwm.gazAltitude}
}
};
}else{
18. views/index.ejs
<script>
$(document).ready(function(){
$("#throttle").knob();
$("#throttleHorizontal").knob();
});
var throttleHorizontal = io.connect('http://localhost/throttle_horizontal'); // connect to socket.io namespace
var throttleHorizontal_data = new Array(); // array for the horizontal throttle data
var throttleHorizontal_graph;
// see next slide
...
</script>
19. views/index.ejs
<script>
...
throttleHorizontal.on('throttle', function(data){
$("#throttleHorizontal").val(data.value);
$("#throttleHorizontal").trigger("change"); // trigger the knob to redraw itself
throttleHorizontal_data.push({x: (new Date()).getTime(), y: parseInt(data.value)});
if(!throttleHorizontal_graph){
//console.log("Altitude graph doesn't yet exist, drawing it for the first and only time.");
throttleHorizontal_graph = new Rickshaw.Graph( {
element: document.querySelector("#throttleHorizontal_chart"),
width: 80,
height: 60,
renderer: "line",
interpolation: "step-after",
series: [{
color: '#66cc66',
data: throttleHorizontal_data
}]
});
throttleHorizontal_graph.render();
}else{
20. views/index.ejs
<script>
...
throttleHorizontal.on('throttle', function(data){
...
}else{
//Throttle graph already exists so just update the data and rerender.
throttleHorizontal_graph.series[0].data = throttleHorizontal_data;
throttleHorizontal_graph.render();
}
});
...
</script>