SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
node.js & AR.Drone
#njugbe meetup 3 - 13 March 2013
@stevenbeeckman
AR.Drone?




                                        2
                                    ith ’s!
                                   w ra
     wifi controlled quadricopter       e
                                   am
node.js packages
                           bes
ar-drone                        tm
                                   aint
https://npmjs.org/package/ar-drone     aine
                                              d
ardrone
https://npmjs.org/package/ardrone
ardrone-web
https://npmjs.org/package/ardrone-web
hello world
var arDrone = require('ar-drone');
var client = arDrone.createClient();

client.animateLeds('blinkGreenRed', 5, 10);

client.on('navdata', console.log);
Real-time Dashboard?
In the browser?
Real-time Dashboard
Express.js for the server
Socket.io for push to the browser (web sockets!)
Client-side:
  jQuery Knob
  Rickshaw.js
Schematics



  AR.Drone’s wifi network
                                     browser - http://localhost:3000/

                                                      socket.io

                              http
                node fly.js           node rtdashboard.js


                             MacBook
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();
  });
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{
fly.js - logging to dashboard
 	   	   	   raw_data_header = {
 	   	   	   	    header: {
 	   	   	   	    	    time: data.time
 	   	   	   	    	    , sequenceNumber: data.sequenceNumber
 	   	   	   	    	    , flying: data.droneState.flying
 	   	   	   	    	    , batteryMilliVolt: 0
 	   	   	   	    	    , altitude: 0
 	   	   	   	    	    , velocity: {x: 0
 	   	   	   	    	    	       	      	     , y: 0
 	   	   	   	    	    	       	      	     , z: 0}
 	   	   	   	    	    , throttle: {forward: 0
 	   	   	   	    	    	       	      	     , height: 0}
 	   	   	   	    }
 	   	   	   };
 	   	   }
fly.js - logging to dashboard
 	     	   var data_to_be_sent = JSON.stringify(raw_data_header);
 	     	   var headers = {
 	     	   	     'Content-Type': 'application/json'
 	     	   	     , 'Content-Length': data_to_be_sent.length
 	     	   };
 	     	   options.headers = headers;

 	     	   var req = http.request(options, function(res){
 	     	   });

 	     	   req.on('error', function(e){
 	     	   	     // per http://nodejs.org/api/http.html#http_http_request_options_callback
 	     	   	     console.log("Problem with request: " + e.message);
 	     	   })

 	     	   req.write(data_to_be_sent);
 	     	   req.end();
 	     }
 });
rtdashboard.js
 var app = express();
 setupApp();

 function setupApp(){
     ...
     db = mongoose.createConnection(app.set('db-uri'));
     db.on('error', console.error.bind(console, 'Connection error:'));

     db.once('open', function(){
         console.log("Connected to database");
         app.use(app.router);
         setupRoutes();
         startServer();
     });
 }
rtdashboard.js
 function setupRoutes(){
 	       app.get('/', routes.index); // contains the dashboard

 	       app.post('/api/raw', addDb, addAltitude, addSpeed, addHeading,
              addThrottleVertical, addThrottleHorizontal, addBattery, routes.raw);
              // receives some navdata from fly.js

 	       app.get('*', function(req, res){
 	       	    console.log("Page not found: " + req.originalUrl);
 	       	    res.render('404');
 	       });
 }

 function addDb(req, res, next){
 	       req.db = db; // contains the database
 	       next();
 }

 function addAltitude(req, res, next){
 	       req.altitude = altitude; // contains a socket.io namespace object, see startServer()
 	       next();
 }
rtdashboard.js
 function startServer(){
 	       server = http.createServer(app);
 	       io = io.listen(server);

 	      server.listen(app.get('port'), function(){
 	      	     console.log("Express server started.");
 	      });

 	      // each sensor gets its own socket.io namespace
 	      altitude = io.of('/altitude');
 	      speed = io.of('/speed');
 	      heading = io.of('/heading');
 	      throttle_vertical = io.of('/throttle_vertical');
 	      throttle_horizontal = io.of('/throttle_horizontal');
 	      battery = io.of('/battery');
 }
routes/index.js
 exports.index = function(req, res){
     res.render('index', { });
 };

 exports.raw = function(req, res){
 	      if(req.body.header){
 	      	      var header = new Object();
 	      	      header.rawData = req.body.header;

 	       	     // send data to dashboard on socket.io
 	       	     req.altitude.emit('altitude', {value: header.rawData.altitude});
 	       	     req.throttle_vertical.emit('throttle', {value: header.rawData.throttle.height});
 	       	     req.throttle_horizontal.emit('throttle', {value: header.rawData.throttle.forward});
 	       	     req.battery.emit('battery', {value: header.rawData.batteryMilliVolt})

 	       	      res.json({message: "Success"});
 	       }else{
 	       	      res.json({message: "No header received."});
 	       }
 }
views/index.ejs
 <!DOCTYPE HTML>
 <html>
 	       <head>
 	       	     <title>Real-Time Dashboard</title>
 	       	     <link rel='stylesheet' href='/bootstrap/css/bootstrap.min.css' />
 	       	     <link rel="stylesheet" href="/css/rickshaw.min.css"/>
 	       	     <script src="/js/jquery-1.9.1.min.js"></script>
 	       	     <script src="/js/jquery.knob.js"></script>
 	       	     <script src="/js/d3.v2.js"></script>
 	       	     <script src="/js/rickshaw.min.js"></script>
 	       	     <script src="/socket.io/socket.io.js"></script>
               <script>
                     ... <!-- see second next slides -->
               </script>
           </head>
           <body>
               ... <!-- see next slide -->
           </body>
  </html>
views/index.ejs
 <body>
    ...
    <div class="span4">
         <h3>Horizontal Throttle</h3>
         <div class="span2">
              <input type="text" id="throttleHorizontal" data-fgColor="#66cc66" data-min="-400"
                  data-max="400" data-cursor=true data-angleOffset=-180 data-width="70" value="0"
                  data-readOnly=true> <!-- jQuery Knob -->
 	      </div>
    	 <div style="float: left;" id="throttleHorizontal_chart"> <!-- rickshaw graph -->
    	 </div>
    </div>
    ...
 </body>
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>
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{
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>
Fork it
https://github.com/stevenbeeckman/ardrone-controller
https://github.com/stevenbeeckman/ardrone-dashboard
Demo time
Way ahead
Access the videostreams
Front & bottom camera

Use OpenCV for computer vision
Node.js on the AR.Drone
https://gist.github.com/maxogden/4152815


                      autonomous AR.Drone!
                       interface with Arduino
Questions?
My name is @stevenbeeckman.
Thanks for listening.

Más contenido relacionado

La actualidad más candente

Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Fwdays
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]Nilhcem
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with ChromeIgor Zalutsky
 
Loadrunner
LoadrunnerLoadrunner
Loadrunnerdanwrong
 
{{components deepDive=true}}
{{components deepDive=true}}{{components deepDive=true}}
{{components deepDive=true}}raytiley
 
Angular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental FeatureAngular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental FeatureJonathan Magen
 
The Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous BeastsThe Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous BeastsFederico Galassi
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?Anna Su
 
CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!amadour
 
Curso de Node.js e MongoDB - 16
Curso de Node.js e MongoDB - 16Curso de Node.js e MongoDB - 16
Curso de Node.js e MongoDB - 16Luiz Duarte
 
start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()Kiwamu Okabe
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run themFilipe Ximenes
 
Testing & deploying terraform
Testing & deploying terraformTesting & deploying terraform
Testing & deploying terraformFarid Neshat
 
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileFirefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileRobert Nyman
 
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
[Quase] Tudo que você precisa saber sobre  tarefas assíncronas[Quase] Tudo que você precisa saber sobre  tarefas assíncronas
[Quase] Tudo que você precisa saber sobre tarefas assíncronasFilipe Ximenes
 
HTML5: Fullscreen, tilt and vivration
HTML5: Fullscreen, tilt and vivrationHTML5: Fullscreen, tilt and vivration
HTML5: Fullscreen, tilt and vivrationDavid Goemans
 

La actualidad más candente (20)

Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
 
Debugging JavaScript with Chrome
Debugging JavaScript with ChromeDebugging JavaScript with Chrome
Debugging JavaScript with Chrome
 
Loadrunner
LoadrunnerLoadrunner
Loadrunner
 
{{components deepDive=true}}
{{components deepDive=true}}{{components deepDive=true}}
{{components deepDive=true}}
 
Spine.js
Spine.jsSpine.js
Spine.js
 
Angular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental FeatureAngular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental Feature
 
The Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous BeastsThe Strange World of Javascript and all its little Asynchronous Beasts
The Strange World of Javascript and all its little Asynchronous Beasts
 
Why Redux-Observable?
Why Redux-Observable?Why Redux-Observable?
Why Redux-Observable?
 
World of Logging
World of LoggingWorld of Logging
World of Logging
 
CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!CocoaHeads Paris - CATransaction: What the flush?!
CocoaHeads Paris - CATransaction: What the flush?!
 
Curso de Node.js e MongoDB - 16
Curso de Node.js e MongoDB - 16Curso de Node.js e MongoDB - 16
Curso de Node.js e MongoDB - 16
 
RingoJS
RingoJSRingoJS
RingoJS
 
start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run them
 
Testing & deploying terraform
Testing & deploying terraformTesting & deploying terraform
Testing & deploying terraform
 
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileFirefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobile
 
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
[Quase] Tudo que você precisa saber sobre  tarefas assíncronas[Quase] Tudo que você precisa saber sobre  tarefas assíncronas
[Quase] Tudo que você precisa saber sobre tarefas assíncronas
 
HTML5: Fullscreen, tilt and vivration
HTML5: Fullscreen, tilt and vivrationHTML5: Fullscreen, tilt and vivration
HTML5: Fullscreen, tilt and vivration
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 

Similar a node.js and the AR.Drone: building a real-time dashboard using socket.io

Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性Hidenori Fujimura
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datosphilogb
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSphilogb
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationAlex Hardman
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015NoSQLmatters
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hacksteindistributed matters
 
Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...Amazon Web Services
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013Laurent_VB
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfacesmaccman
 
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】tsuchimon
 
Alpha Streaming Realtime
Alpha Streaming RealtimeAlpha Streaming Realtime
Alpha Streaming RealtimeMark Fayngersh
 

Similar a node.js and the AR.Drone: building a real-time dashboard using socket.io (20)

Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性Web+GISという視点から見たGISの方向性
Web+GISという視点から見たGISの方向性
 
Pengenalan blaast platform sdk
Pengenalan blaast platform sdkPengenalan blaast platform sdk
Pengenalan blaast platform sdk
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
 
Express JS
Express JSExpress JS
Express JS
 
NoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael HacksteinNoSQL meets Microservices - Michael Hackstein
NoSQL meets Microservices - Michael Hackstein
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Asynchronous Interfaces
Asynchronous InterfacesAsynchronous Interfaces
Asynchronous Interfaces
 
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
AWS IoTで家庭内IoTをやってみた【JAWS DAYS 2016】
 
Alpha Streaming Realtime
Alpha Streaming RealtimeAlpha Streaming Realtime
Alpha Streaming Realtime
 

Más de Steven Beeckman

An Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial IntelligenceAn Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial IntelligenceSteven Beeckman
 
Digital transformation in other countries' governments
Digital transformation in other countries' governmentsDigital transformation in other countries' governments
Digital transformation in other countries' governmentsSteven Beeckman
 
csv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizationscsv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizationsSteven Beeckman
 
Boondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBusBoondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBusSteven Beeckman
 
BlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera APIBlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera APISteven Beeckman
 
Testing & Deploying node.js apps
Testing & Deploying node.js appsTesting & Deploying node.js apps
Testing & Deploying node.js appsSteven Beeckman
 
4 Simple Rules of Design
4 Simple Rules of Design4 Simple Rules of Design
4 Simple Rules of DesignSteven Beeckman
 
BlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetupBlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetupSteven Beeckman
 
Node.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetupNode.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetupSteven Beeckman
 
Think Before You Act or Rapid Prototyping
Think Before You Act or Rapid PrototypingThink Before You Act or Rapid Prototyping
Think Before You Act or Rapid PrototypingSteven Beeckman
 

Más de Steven Beeckman (13)

An Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial IntelligenceAn Incomplete Introduction to Artificial Intelligence
An Incomplete Introduction to Artificial Intelligence
 
Digital transformation in other countries' governments
Digital transformation in other countries' governmentsDigital transformation in other countries' governments
Digital transformation in other countries' governments
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Arduino & node.js
Arduino & node.jsArduino & node.js
Arduino & node.js
 
csv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizationscsv,conf 2014 - Open data within organizations
csv,conf 2014 - Open data within organizations
 
Boondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBusBoondoggle Bright - Hackathing - StartupBus
Boondoggle Bright - Hackathing - StartupBus
 
Intro
IntroIntro
Intro
 
BlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera APIBlackBerry 10 Core Native Camera API
BlackBerry 10 Core Native Camera API
 
Testing & Deploying node.js apps
Testing & Deploying node.js appsTesting & Deploying node.js apps
Testing & Deploying node.js apps
 
4 Simple Rules of Design
4 Simple Rules of Design4 Simple Rules of Design
4 Simple Rules of Design
 
BlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetupBlackBerry Developers Group Belgium - 1st meetup
BlackBerry Developers Group Belgium - 1st meetup
 
Node.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetupNode.js User Group Belgium - 1st meetup
Node.js User Group Belgium - 1st meetup
 
Think Before You Act or Rapid Prototyping
Think Before You Act or Rapid PrototypingThink Before You Act or Rapid Prototyping
Think Before You Act or Rapid Prototyping
 

Último

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

node.js and the AR.Drone: building a real-time dashboard using socket.io

  • 1. node.js & AR.Drone #njugbe meetup 3 - 13 March 2013 @stevenbeeckman
  • 2. AR.Drone? 2 ith ’s! w ra wifi controlled quadricopter e am
  • 3. node.js packages bes ar-drone tm aint https://npmjs.org/package/ar-drone aine d ardrone https://npmjs.org/package/ardrone ardrone-web https://npmjs.org/package/ardrone-web
  • 4. hello world var arDrone = require('ar-drone'); var client = arDrone.createClient(); client.animateLeds('blinkGreenRed', 5, 10); client.on('navdata', console.log);
  • 6. Real-time Dashboard Express.js for the server Socket.io for push to the browser (web sockets!) Client-side: jQuery Knob Rickshaw.js
  • 7. Schematics AR.Drone’s wifi network browser - http://localhost:3000/ socket.io http node fly.js node rtdashboard.js MacBook
  • 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{
  • 10. fly.js - logging to dashboard raw_data_header = { header: { time: data.time , sequenceNumber: data.sequenceNumber , flying: data.droneState.flying , batteryMilliVolt: 0 , altitude: 0 , velocity: {x: 0 , y: 0 , z: 0} , throttle: {forward: 0 , height: 0} } }; }
  • 11. fly.js - logging to dashboard var data_to_be_sent = JSON.stringify(raw_data_header); var headers = { 'Content-Type': 'application/json' , 'Content-Length': data_to_be_sent.length }; options.headers = headers; var req = http.request(options, function(res){ }); req.on('error', function(e){ // per http://nodejs.org/api/http.html#http_http_request_options_callback console.log("Problem with request: " + e.message); }) req.write(data_to_be_sent); req.end(); } });
  • 12. rtdashboard.js var app = express(); setupApp(); function setupApp(){ ... db = mongoose.createConnection(app.set('db-uri')); db.on('error', console.error.bind(console, 'Connection error:')); db.once('open', function(){ console.log("Connected to database"); app.use(app.router); setupRoutes(); startServer(); }); }
  • 13. rtdashboard.js function setupRoutes(){ app.get('/', routes.index); // contains the dashboard app.post('/api/raw', addDb, addAltitude, addSpeed, addHeading, addThrottleVertical, addThrottleHorizontal, addBattery, routes.raw); // receives some navdata from fly.js app.get('*', function(req, res){ console.log("Page not found: " + req.originalUrl); res.render('404'); }); } function addDb(req, res, next){ req.db = db; // contains the database next(); } function addAltitude(req, res, next){ req.altitude = altitude; // contains a socket.io namespace object, see startServer() next(); }
  • 14. rtdashboard.js function startServer(){ server = http.createServer(app); io = io.listen(server); server.listen(app.get('port'), function(){ console.log("Express server started."); }); // each sensor gets its own socket.io namespace altitude = io.of('/altitude'); speed = io.of('/speed'); heading = io.of('/heading'); throttle_vertical = io.of('/throttle_vertical'); throttle_horizontal = io.of('/throttle_horizontal'); battery = io.of('/battery'); }
  • 15. routes/index.js exports.index = function(req, res){ res.render('index', { }); }; exports.raw = function(req, res){ if(req.body.header){ var header = new Object(); header.rawData = req.body.header; // send data to dashboard on socket.io req.altitude.emit('altitude', {value: header.rawData.altitude}); req.throttle_vertical.emit('throttle', {value: header.rawData.throttle.height}); req.throttle_horizontal.emit('throttle', {value: header.rawData.throttle.forward}); req.battery.emit('battery', {value: header.rawData.batteryMilliVolt}) res.json({message: "Success"}); }else{ res.json({message: "No header received."}); } }
  • 16. views/index.ejs <!DOCTYPE HTML> <html> <head> <title>Real-Time Dashboard</title> <link rel='stylesheet' href='/bootstrap/css/bootstrap.min.css' /> <link rel="stylesheet" href="/css/rickshaw.min.css"/> <script src="/js/jquery-1.9.1.min.js"></script> <script src="/js/jquery.knob.js"></script> <script src="/js/d3.v2.js"></script> <script src="/js/rickshaw.min.js"></script> <script src="/socket.io/socket.io.js"></script> <script> ... <!-- see second next slides --> </script> </head> <body> ... <!-- see next slide --> </body> </html>
  • 17. views/index.ejs <body> ... <div class="span4"> <h3>Horizontal Throttle</h3> <div class="span2"> <input type="text" id="throttleHorizontal" data-fgColor="#66cc66" data-min="-400" data-max="400" data-cursor=true data-angleOffset=-180 data-width="70" value="0" data-readOnly=true> <!-- jQuery Knob --> </div> <div style="float: left;" id="throttleHorizontal_chart"> <!-- rickshaw graph --> </div> </div> ... </body>
  • 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>
  • 24. Access the videostreams Front & bottom camera Use OpenCV for computer vision
  • 25. Node.js on the AR.Drone https://gist.github.com/maxogden/4152815 autonomous AR.Drone! interface with Arduino
  • 26. Questions? My name is @stevenbeeckman. Thanks for listening.