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
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 ROS.
Please note that I am only supporting this project on 64-bit Ubuntu 16.04. I do not have the resources to support other OSs.
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, to 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
Depending on what other libraries you already have installed, you may also need to do the following:
sudo apt-get install libsdl2-dev
sudo apt-get install libgtk2.0-dev
Logitech Joystick Setup
I set up the program so that the Logitech joystick axes work as follows:
|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
|2||IN-FLIGHT EMERGENCY CUTOFF|
|3||Zap (toggle front/belly camera)|
PS3 Controller Setup
I set up the program so that the PS3 axes work as follows:
|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:
|8 (select)||Exit program (IN-FLIGHT EMERGENCY CUTOFF)|
|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.
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 autopylot_agent.py. Any subsequent joystick / gamepad action returns control to you, providing an emergency override. The function in autopylot_agent.py 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 ROS
Working with Matlab
The file autopylot_agent.m contains Matlab code equivalent to the Python code in autopylot_agent.py. 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 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MATLAB/bin/glnxa64
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
Copyright and licensing information can be found in the header of each source file. Please contact me with any questions or suggestions.