Introduction: Autonomous AR Parrot Drone 2.0 Flying
This instructable will give you an EXTREMELY simple and quick way (< 15 minutes) to have an AR Parrot Drone 2.0 fly autonomously with code written by you! The best part of this project is it only requires the drone and a laptop (mac or windows). No modifications to the drone. I will also show you how to stream the video from the drone onto your laptop. Check out a sample program I wrote for my drone:
People have done CRAZY stuff with this, including having a drone that can follow peoples faces or be attracted to objects that are red. This guide is a step-by-step on how to use Felixge's node library to control your drone. Definitely check out what he's done. I did this through trial and error and pared it down to the essentials, best of luck!
Step 1: The Drone
To program your drone, you will first need a drone! I am using an AR Parrot Drone 2.0. The first version may work, but no promises. You can find them at Radioshack, Amazon, etc.
First you will need to get comfortable just controlling the drone with you smartphone/tablet. Download one of the apps such as 'AR.FreeFlight 2.4' to control it. It might be a good idea to leave the indoor bumper hull on at first to minimize damage from collisions. I also suggest flying in an open field or park.
Step 2: Node JS
The first thing needed for autonomously programming our drone is to download Node JS. It's awesome for web applications with JavaScript and if you are interested you can learn a bit more about it. For our purposes though just download the file. I recommend making a new folder on your computer in your 'C' drive and naming it something like 'Drone'. Move the program into this new folder.
You are halfway to controlling your drone with your laptop!
Step 3: Command Line
Now we will do a bit of work with the command line. Follow the instructions for your type of computer.
FOR WINDOWS:
The command line program is called 'Command Prompt' and on recent windows versions can be opened by going to 'Start' and searching through the programs or viewing 'all apps'. If confused refer to this help. Once you have the program open type the following line of code and then hit enter:
npm install ar-drone
This will give you access to Felixge’s node.js library so that you can use high level commands such as 'takeoff()' and 'leftFlip' to control the drone. As long as the Command Prompt doesn't throw any errors you are all set to start controlling the drone with your computer! For help using the Command Prompt check this resource.
FOR MAC:
The command line program on a mac is called Terminal. The easiest way to open it is to click in the Spotlight search bar in the upper right hand of your desktop screen and type 'Terminal'. Then just click on the program called Terminal. Once open type the following line of code and hit enter:
sudo npm install ar-drone
This will give you access to Felixge’s node.js library so that you can use high level commands such as 'takeoff()' and 'leftFlip' to control the drone. As long as Terminal doesn't throw any errors you are all set to start controlling the drone with your computer! For help using Terminal check this resource.
Step 4: Testing
Now that you have Node.js installed with the ar-drone library we can control it with your laptop! To do this, first turn the drone on by plugging in the battery.
Next connect you laptop to the Wi-Fi network named something similar to 'drone######'.
Open up the node.js program.
Type the next four lines of code into the node.js window and hit enter after each line. (WARNING: as soon as you hit enter on the third line the drone will take off and hover a few feet off the ground until you type the fourth line and hit enter again). Please make sure the drone is in an open space.
var arDrone = require('ar-drone');
var client = arDrone.createClient();
client.takeoff();
client.land();
It works! Woohoo! This is a good way to check that everything was installed correctly. If you come across any errors you may need to go back to the last step and download the 'ar-drone' library again.
Step 5: Autonomous Program
Now the exciting part! We will make some autonomous programs for the drone. This is a huge advantage over what we just did because rather than typing the code line by line we can send a whole program to the drone and it will execute it sequentially for some flawless and exciting flight.
To do this we will need to write programs in JavaScript. Don't fear if you don't know JavaScript we will mostly be using the same cut and paste commands. If you are interested you can read up on it HERE. We will need a text editor to write our code in, I recommend Sublime Text. Just download it and then upon opening it will open a new file we will type all the lines of our code directly into Sublime Text, as shown in the picture for this step. Then when saving the program make sure to save the file with '.js' at the end of the name and it will automatically become a JavaScript file!
For now copy my simple program in the picture and save it as 'test.js'. This will have the drone takeoff, hover for a few seconds, and then land. Check the next step on how to run this program.
Step 6: Running Programs
To run the program 'test.js' we first need to know where we saved the file. Move the program into the 'Drone' folder you made in your 'C' drive. Once again we will need to use the command line, for Windows open Command Prompt, and for Mac open Terminal.
Turn your drone on and connect the laptop to its Wi-Fi connection. Type the following line of code and hit enter:
node c:\Drone\test.js
What this is doing is having the node.js program run the file test.js which is stored in the 'Drone' folder in the 'C' directory. By looking at the line of code hopefully this makes sense. When running a different program only the name 'test.js' needs to be changed as long as the program is located in the 'Drone' folder.
If the drone took off, hovered, and landed you did it!
Step 7: Functions
Now you have everything you need to autonomously fly your drone. To write more complicated programs you will just have to know a few functions that the drone is capable of. Below I show the name and describe what they do. You should also check out Felixge's README file that was included with the ar-drone library as it has tons of beneficial information.
takeoff() - has the drone takeoff and hover above the ground
land() - has the drone land
up(speed) - has the drone gain altitude at a speed between 1 (max speed) and 0 (still).
down(speed) - makes the drone reduce altitude
clockwise(speed) - drone spins clockwise
counterClockwise(speed) - drone spins counter-clockwise
front(speed)/back(speed) - changes the pitch causing horizontal movement
left(speed)/right(speed) - changes the roll causing horizontal movement
stop() - keeps the drone hovering in place
(for complex functions like flips and manuevers, check out the README file linked above)
All of these functions can be used in a long list with a dedicated time between them by using the format:
client
.after(5000, function() {
this.clockwise(0.5);
})
.after(3000, function() {
this.stop();
});
The amount 5000 is the time in milliseconds that the drone will turn clockwise for at 0.5 of its top turning rate (1 being max and 0 being still). We can see for the stop function that it doesn't have a speed because it takes care of that itself. By making a long list of commands like this we can set up an autonomous task list to carry out. I have copied the code that my drone ran, in the video on the first page, below:
var arDrone = require('ar-drone');
var client = arDrone.createClient();
client.takeoff();
client
.after(2000, function() {
this.up(1);
})
.after(2000, function() {
this.animate('flipAhead',500);
})
.after(1000, function() {
this.animate('flipBehind', 500);
})
.after(1000, function() {
this.animate('flipLeft',500);
})
.after(1000, function() {
this.animate('flipRight', 500);
})
.after(5000, function() {
this.front(1.0);
})
.after(2000, function() {
this.clockwise(0.5);
})
.after(5000, function() {
this.back(0.8);
})
.after(2000, function() {
this.land();
});
Hopefully this will give you a good idea of how your program outline will look.
Step 8: Streaming Video
For all the super awesome applications like face tracking you will have to stream the video from the ar drone. One easy way to do it is to download ffmpeg. After downloading go ahead and run it. A command line type window will pop open (you can see a picture of mine on this step). You will need to make a new JavaScript program using the Sublime Text editor as described in step 5. Copy and paste the code below into a file and save it as 'video.js' in your 'Drone' folder (Sorry I couldn't upload any '.js' files).
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 ...');
});
Now run this program by typing the following line into the command line window that opened when you ran ffmpeg. Don't forget to hit enter.
node c:\Drone\video.js
Go to your web browser (any one will work) and go to the following website (you can just copy/paste it):
http://localhost:8080/
You will now be getting a stream of the video that your drone is viewing through the front camera! You can see a picture of what mine was viewing along with some of my bookmarks :)
CONGRATS! You are now set to begin doing some awesome stuff with you drone. Feel free to check out Felixge's library if you are interested in using the video feed from the drone to do things such as track and follow people's faces (this uses a program called OpenCV). Best of luck.

Participated in the
Full Spectrum Laser Contest

Participated in the
Robot Contest
50 Comments
4 years ago on Step 8
It is a very cool project. Well done. I am a Linux user, will it work?
Question 5 years ago on Step 4
Hey I’ve been trying to do this step for a while now but the only thing that says is that there is no ar-drone module. Can you help me out on how I can add it? I’ve already typed the npm instal ar-drone command. I’m stuck in this step
7 years ago
Hi all, Im fairly new in regard to programming for a drone so please bare with me if my questions sound "newb-ish". Everything regarding programming for the Parrot AR drone is a few years old. It seems odd because I've found alot of cool things with the AR drone 2.0. Has anyone else noticed that? Is there a better, more accurate, newer model of a drone for this sort of programming? My background is in C++ but I'm open to trying any language to make an autonomous obstacle avoiding drone.
Reply 6 years ago
You can try the Parrot Bebop 1 or Parrot Bebop 2.
Thanks!
6 years ago
Hey great work but i would like to know would this be possible of a self made fpv drone , what all components would be needed and how would it be programmed ?
6 years ago
Great instructable Patrick! One very quick question. Would this work with the first generation of Parrot Drone ? I'm not too familiar with the protocols used as my drones all use 2.4GHz transmitter/receiver. Is the basic communication API the same between the 2 Parrot versions. Many Thanks
7 years ago
Great instructions. Love it! Just one thing I wanted to mention to the community, your example program in step five doesn't work (for me at least). It is having the drone takeoff, immediately land (so fast that it doesn't even take off), then land again after a certain amount of time. I believe it should be:
var arDrone = require('ar-drone');
var client = arDrone.createClient();
client.takeoff();
client
.after(5000, function() {
this.land();
});
Thanks.
7 years ago
This is awesome!!! I had no idea I could do this with my parrot
7 years ago
Will this program work with other drones?
7 years ago
Wow, that actually sounds pretty interesting. Definitely worth checking out and maybe upgrading the Parrot if I can do it right :) Thanks! If I may, you can also check out this review, and take a look how these guys took a different approach with this model.
7 years ago
Someone please help me before I shoot myself. I had everything going well, then started a 'client.createrepl()' in node. Now I can't do anything because within terminal everything I write comes back with:
ReferenceError: client is not defined
at repl:1:1
at REPLServer.defaultEval (repl.js:262:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:431:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:211:10)
at REPLServer.Interface._line (readline.js:550:8)
at REPLServer.Interface._ttyWrite (readline.js:827:14)
I have tried stopping it, ctrl D, system/stop 0 and nothing works. Now I am at a loose end and considering suicide.
Please help me. Thank you in advance.
Reply 7 years ago
Not sure if you figured this out already but the command should be as followed: client.createRepl()
Take not of the capital letter on the command. :)
Be sure that you are defining the ar-drone library and create the client before trying the command:
var arDrone = require('ar-drone');
var client = arDrone.createClient();
Reply 7 years ago
Thank you, eventually I did figure it out. Each time I closed the terminal it wanted me to reinstall the library. I didn't know this so was just trying to continue as I was. It was driving me crazy.
Eventually i changed to using Ruby as the programming language and everything fell into place perfectly. I need to remember there's always more than one way to skin a cat (program a drone).
I very much appreciate you taking the time to reply. Thank you again.
Reply 7 years ago
You're very welcome!
Have fun :)
7 years ago
I'm currently working on a 3d reconstruction project. so i need to capture multiple view images of the object. Anyone knows how to make the drone go in a circular orbit around an object? Please help!
Reply 7 years ago
ardrone-autonomy would be able to approach this "mission". You could get it to orbit an object fairly easily.
7 years ago
Anyone knows if it is possible that the ar.drone can fly alone without existing wirelless connection during the flight ? Since there is only connection when the command is given by the node.js and send it to certain points GPS
9 years ago on Step 3
I'm on a windows 8.1 and I've done everything correctly yet npm install ar-drone command keeps giving me an ENOENT error. Is this not compatible with windows 8.1? Please advise !!
Reply 9 years ago on Introduction
open command prompt.
type: cd c:\[NameOfYourFolder] [enter]
type: npm install npm -g [wait]
when complete,
type: npm install ar-drone [enter\
it should work from here.
I would like to note that when writing scripts, there is no way to stop your drone unless it finishes the script, so start small and work your way up. or try ez-builder.
Reply 7 years ago
i got to my folder n when i got to ur 2nd part type: npm install npm -g [wait] nothing happens? do i wait longer?