Search This Blog

Wednesday, June 29, 2016

AR-drone Programming Update

About a month ago, I posted an article about controlling the A.R. Drone with the computer.  Since my last post, I have learned a lot about coding the drone.  I've got it to move around with the computer and I 've made pre-scripted codes that run directly from Node.js command prompt.  

Here are a few examples of the coding I have done :
var arDrone = require('ar-drone');
var client = arDrone.createClient();
client.takeoff();
client
  .after(5000, function() {
    this.clockwise(0.5);
  })
  .after(3000, function() {
    this.front(1.0);
  })
  .after(1000, function() {
    this.stop();
    this.land();
  });
This will make the drone take off, rotate, fly forward, and land.
var arDrone = require('ar-drone');
 var http    = require('http');
 console.log('Connecting png stream ...');
 var pngStream = arDrone.createClient().getPngStream();
 var lastPng;
 pngStream
   .on('error', console.log)
   .on('data', function(pngBuffer) {
     lastPng = pngBuffer;
   });
 var server = http.createServer(function(req, res) {
   if (!lastPng) {
     res.writeHead(503);
     res.end('Did not receive any png data yet.');
     return;
   }
   res.writeHead(200, {'Content-Type': 'image/png'});
   res.end(lastPng);
 });
 server.listen(8080, function() {
   console.log('Serving latest png on port 8080 ...');
});
This will stream the video live (you will need ffmpeg installed for this to work) from the drone into your browser at http://localhost:8080/ (this trick was taught to me by instructables)
var arDrone = require('ar-drone');
var client = arDrone.createClient();
client.config('control:altitude_max', 100000);
Since the Ar-drone module sets the default max height to three meters, this code would set it to 100 meters.
var arDrone = require('ar-drone');
var client = arDrone.createClient();
client.takeoff();
client
  .after(5000, function() {
 this.animate('flipLeft', 15);
})
  .after(1000, function() {
    this.stop();
    this.land();
  });
This code would make the drone to a flip.  I recommend that you add a height code to make sure the drone does not hit the ground during the flip.
To control your drone from your browser, download nodecopter-monitor:
:
var arDrone = require('ar-drone'),
    client = arDrone.createClient();
require('nodecopter-monitor').init(client);
For the list of controls, click here.
For more amazing modules (such as AI flying and taking panaromas go to www.nodecopter.com)


Currently, I am working on getting the A.R. Drone to identify and follow the commands of QR codes.  Right now, all I know is that one would need opencv and qrar (can only be used if you have ffmpeg, gtk, and npm).  
Some people might wonder how to control the small Bluetooth drones.  My friends and I have found an app for the ipad/iPhone to control it.  The app is called "Tickle."  It has a Scratch-like interface (drag and drop coding) and is very easy to use.  We held a competition to see who can get it to fly a definite path (it was very hard to manipulate the distance variables) and land at the right destination.  
I will post more stuff about A.R. Drone programming later on.  Stay tuned!

No comments:

Post a Comment