Auto-Pilot the Parrot AR.Drone from Python (or Matlab or C)
C Python Makefile Matlab
Latest commit 42d16fc May 20, 2016 @simondlevy No commit message


Auto-Pilot the Parrot AR.Drone from Python (or Matlab or C)

This repository contains source code for building a stubbed version of the AR.Drone AutoPylot program, which allows you to auto-pilot the Parrot AR.Drone 1.0 or 2.0 from source code written in Python, on a computer running 64-bit Ubuntu.
This video gives you an idea of what you can do with the drone in Python, using this package (see below for instructions). As the video shows, the update rate is fast enough to enable interesting experiments. With the AR.Drone 2.0 and my Sony VAIO Pro laptop, I have obtained update rates of around 30 Hz.

If you're interested in a more graphical-interface approach, you might also look into URBI or ROS.

Please note that I am only supporting this project on 64-bit Ubuntu, using the latest SDK and firmware from Parrot (currently SDK 2.0.1). I do not have the resources to support other OSs or backward compatibility.

Getting Started

To get started, you should download the current AR.Drone SDK (registration required). Also make sure your AR.Drone has the current firmware -- easiest way is to download the current version of FreeFlight from the AppStore.

If you have a Logitech Extreme 30 Pro joystick or

Playstation PS3 controller, the only file you should need to modify immediately in the repository is the autopylot.makefile, whose first non-commented lines you should change to reflect where you put the AR.Drone SDK. You should also modify the lines right below there that specify which kind of controller you have and its hexadecimal ID (which you can find by issuing the lsusb command in Linux). If you have some other kind of gamepad, like a Nintendo Wii, you'll have to modify autopylot_gamepad.c to reflect this. If you're using Python, make sure to get the Python development environment:

sudo apt-get install python-dev 

Logitech Joystick Setup

I set up the program so that the Logitech joystick axes work as follows:

Axis Stick Effect
0 Rock left/right Roll (sideways travel)
1 Rock forward/back Pitch (forward/backward travel)
2 Twist clockwise/anticlockwise Yaw (clockwise/anticlockwise turn)
5 Mini-joystick on top Altitude (forward=down; backward=up)

The Logitech buttons are labeled 1 - 12 on the joystick. I set up the program to work with them as


Button Effect
1 (trigger) Takeoff/Land
3 Zap (toggle front/belly camera)
4 Toggle autopilot

PS3 Controller Setup

I set up the program so that the PS3 axes work as follows:

Axis Stick Effect
0 Left-side stick left/right Roll (sideways travel)
1 Left-side stick forward/back Pitch (forward/backward travel)
2 Right-side stick left/right Yaw (clockwise/anticlockwise turn)
3 Right-side stick forward/back Altitude (forward=down; backward=up)

I set up the program to work with the PS3 buttons as follows:

Button Effect
8 (select) Exit program (IN-FLIGHT EMERGENCY CUTOFF)
9 (start) Takeoff/Land
3 (square) Zap (toggle front/belly camera)
2 (×) Toggle autopilot

These button and axis configurations can be modified by editing gamepad.c

Running the Default Program

Change to the repository directory and type make. This will build the ardrone_autopylot executable, as well as compiling the SDK (probably with a lot of warnings about type mismatches). Once you've built the program you can run it by typing ./ardrone_autopylot in the directory where you built it. The autopylot.makefile is set up to use Python, but you can modify it for Matlab or C. For Python, you should first make sure that your PYTHONPATH shell variable is set to include the current directory: either on the command line, or (better long-term solution) in your .bashrc file, put the following instruction:


The autopilot is intially off, so you are flying the AR.Drone manually. When you push the autopilot button (4 on the Logitech joystick, × on the PS3), control is transferred to the action function in Any subsequent joystick / gamepad action returns control to you, providing an emergency override. The function in currently ignores the video and navigation data input and just makes the drone turn clockwise. (I've noticed that the program can take several seconds to report non-zero navigation data from the drone.) Note that the altitude and X/Y velocities are approixmate, and that the minimum reported altitude is around 230 mm. You can modify this function to do something more interesting.

Working with Matlab

The file autopylot_agent.m contains Matlab code equivalent to the Python code in To run the Matlab version, comment-out the Python lines (36-38) in autopylot.makefile, and un-comment the Matlab lines (45-47). you should have the following in your .bashrc file:

export MATLAB=/usr/local/MATLAB/R2013a # or whatever release you've installed


You will also need the csh command, which is used by the Matlab Engine. To be sure you have this command, do sudo apt-get install csh in your Ubuntu shell.

Working with C

If you prefer to program in C, comment-out the Python lines in autopylot.makefile, un-comment the C lines (50-51), and work with the code in autopylot_c_agent.c.

Running the Ball-Tracking Example

To run the example in the video, download and this version of You will need OpenCV for Python, which you can install by following the instructions here.

Copyright and licensing information can be found in the header of each source file. Please contact me with any questions or suggestions.