Search This Blog

Wednesday, November 22, 2017

Control A.R. Drones with Q.R. Codes


It's been a while since my last post about quadcopters, but I will be showing you a really amazing A.R. Drone trick today.  In this post, I will demonstrate how to let QR Codes generated from a script's text control your A.R. Drone.
Before starting, it is important to note that this guide is for Linux users only (I used Debian, so some parts of the procedure might be different).  The scripts needed to enable the QR reading functionality work best in Linux environments because many of them have a lot of dependencies; it would be a pain to compile, configure, and set the correct paths for those files in Windows (some cannot even be compiled and configured in the newer versions of Windows).  Additionally, make sure that you have node.js, npm, the A.R. Drone modules (refer to my previous guides about programming A.R. Drones) and ffmpeg installed in Linux.

To install node.js and npm:
sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

To install ffmpeg:
sudo apt-get install ffmpeg

Then, install the following dependencies:
sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev

Next:
npm install qrar

By this point, you are nearly ready to make your A.R. Drone read QR codes.  You will also need to create three scripts in the same folder.

Name the first script decoder.js and put this code in it:

var QRAR = require('qrar');
var drone = require('ar-drone');

var codes = new QRAR(drone);

codes.on('qrcode', function (code) {
  console.log(code);
});

codes.start();

Name the second script main.js and put this code in it:

var arDrone = require('ar-drone');
arDrone.createClient().createRepl();

Name the last script qrcodelauncher.sh, and place the following script in it.

node decoder.js | node main.js

Moreover, also generate a few QR codes; only the text of the script is needed in the QR code (Ex. If you want the drone to take off when it sees the QR code, simply generate a QR code representing "takeoff()").  For a list of all possible functions, check out the Client API section of this link.

Now, you can finally show a QR code to your A.R. Drone.  As long as it is valid, your drone will respond!  However, you might have to wave it a few times for it to respond (your console will also output what it sees from the QR code).  I attached a few QR codes to get you started.

To takeoff:


To land:

Stay tuned for more cool A.R. Drone guides!