Up and flying with the AR.Drone and ROS: Getting started
In this tutorial (#1) we will:
- Install ROS, the AR.Drone driver and AR.Drone keyboard controller
- Fly the AR.Drone using the provided keyboard controller
In tutorials 2-5, we will:
- Modify the keyboard controller to work with a joystick or control pad, giving much finer control (link)
- Look more closely at the data sent back from the drone and play with the onboard tag detection (link)
- Write a controller for the drone to enable tag following
- Write a controller for the drone which allows us to control drone velocity, rather than body angle
Based on feedback I received from a video hangout with Robot Garden (cofounded by fellow Robohub author, Andra Keay), I have made a few updates to the tutorial, summarized below and highlighted throughout the tutorial in red:
- Fixed permissions problem which caused the keyboard button on the launch bar to do nothing
- Added keyboard_controller_with_tags.launch file, which enables the drone’s tag detection feature
- Updated tutorial with command-line equivalent commands, for all graphical actions
- Included a “Going Further” section at the end of the tutorial
If you are running the ARDroneUbuntu virtual machine, updating the tutorial will download the above updates and fixes.
Command-line equivalent (updating the tutorial): $ roscd ardrone_tutorials $ git pull
What is the AR.Drone?
The AR.Drone is a quadrotor that can be flown from any WiFi enabled device with an appropriate application – most commonly an iPhone or Android phone.
Unlike other quadrotors, which can be difficult to fly manually, the AR.Drone is equipped with onboard sensors and controllers that stabilize the vehicle while flying and give it the ability to hover on a spot and await the next command. Because of this onboard stabilization, the AR.Drone is becoming very popular as both a toy (it can be flown by even the most inexperienced pilots), and as a research platform for computer vision and robotic exploration (researchers can focus on their algorithms without worrying that the drone will crash).
And what is ROS?
ROS, the “Robot Operating System”, is a software framework that enables the development of robotic applications – applications that control and interact with robots. A large number of groups using the AR.Drone for research purposes, use ROS to control the drone, which is why we are focusing on it here.
What you’ll need for the tutorial
To complete this tutorial you will need:
- An AR.Drone!
- A computer or laptop with WiFi
For future tutorials, you will need:
- USB Joystick or control pad (linux compatible)
For these tutorials, we will be running the ROS software and AR.Drone controllers using the Linux operating system.
If you don’t have Linux, want to get flying quickly or don’t know what I’m talking about:
To get started, we’ll be downloading an “Xubuntu Virtual Machine”, which has been created especially for these tutorials. This virtual machine package contains everything that you need to get up and flying – fast!
Once you have Virtual Box installed, double click the ARDroneUbuntu.ova file that you downloaded. This will open it in the Virtual Box program.
A settings/import dialog should open. You should leave these settings as they are, unless you know what you’re doing.
After completing the import process, click start in the Virtual Box program to begin running ARDroneUbuntu.
Congratulations, you’re now running Xubuntu 12.04 (username: ardrone, password: ardrone)! This has been preconfigured with all the software required for this series of tutorials, so you’re now good to go!
Once the virtual machine is running, you will be brought to the desktop. At the bottom of the screen you will see the launch bar:
The launch bar contains a number of icons, which I will be referring to throughout the tutorial:
- Terminal – in this program, you run text-based programs and commands
- Text Editor - we will be using this in future tutorials to write some basic programs
- Keyboard Controller – this launches the keyboard controller
- Update Tutorials - this will update the AR.Drone driver and tutorial source code, it will also install new tutorials once they have been released.
- Quick Command Box – this is like the terminal and can be used for sending a quick command to the operating system
Great, now that you’re up and running, lets update the tutorial files. Click the Update Tutorials (#4) button in the launch bar. This will launch a terminal window in which it will download and install any required software updates. You should be connected to the internet for this step.
Command-line equivalent (updating the driver): $ roscd ardrone_autonomy $ git pull $ rosmake ardrone_autonomy
Command-line equivalent (updating the tutorial): $ roscd ardrone_tutorials $ git pull $ rosmake ardrone_tutorials
Now you’re ready to fly and can skip the next section of the tutorial.
If you have Linux (skip this section if you just downloaded the virtual machine):
I’ll assume you understand enough about linux to follow the ROS installation instructions (summarized here). I also assume you are running Ubuntu (or a deviant). If not, you should modify the apt-get commands to suit your system.
In addition to the summarized ROS installation instructions above, you will need to run:
$ sudo rosdep init $ rosdep update $ sudo apt-get install ros-fuerte-joystick-drivers $ rosdep install joy
This will install the joystick drivers which are used in a future tutorial.
Now to install the AR.Drone driver’s prerequisites:
$ sudo apt-get install daemontools libudev-dev libiw-dev
Next, we will download the AR.Drone driver (full disclosure: I am a regular contributor to the driver) and the keyboard controller used for this tutorial:
$ roscd $ pwd ~/ros_workspace $ git clone https://github.com/AutonomyLab/ardrone_autonomy.git $ git clone https://github.com/mikehamer/ardrone_tutorials.git $ ls ... ardrone_autonomy ardrone_tutorials ... $ rospack profile
And now to compile the packages:
$ roscd ardrone_auto<TAB should autocomplete> $ ./build_sdk.sh $ rosmake -a
If TAB does not autocomplete the above-indicated command, or if rosmake reports any failures, you may have a problem with your installation. If this is the case, you should check the installation guide linked above.
If you’ve completed all of the above successfully, you’re ready to move on!
We are now going to fly the drone. Flying inside can be dangerous. When flying inside, you should always use the propellor-guard and fly in the largest possible area, making sure to stay away from walls and delicate objects. Even when hovering, the drone tends to drift, so always land the drone if not being flown.
I accept no responsibility for damages or injuries that result from flying the drone.
If you have a laptop and are thus able to fly outside, check the last section of this tutorial for instructions on reconfiguring the drone.
Great, we’ve got the software, now lets have some fun!
Turn on the drone and wait until the propellors vibrate, indicating that the drone is ready.
Now connect your computer’s wireless to the AR.Drone’s network, just like you would connect to a normal wireless network. The network will be called ardrone<something>.
If your computer is also connected to a network via ethernet (or any other network adaptor), disconnect it. We only want the wireless network to be running*
* Advanced users: The drone acts as a wireless server and assigns itself (via its DHCP server) a fixed IP address of 192.168.1.1 and your wireless card an address from 192.168.1.2-255. For this reason, there can be routing issues if your ethernet card is also in the 192.168.1.0 subnet.
Running the keyboard controller
If you’re using the supplied virtual machine:
Click on the keyboard icon (#3) in the launch bar to run the keyboard controller program:
Note that a connection can take up to 10 seconds. If after 10 seconds the window still says “Disconnected”, check the wireless connection to the drone, and check that any network cables have been unplugged from the computer.
If you’re using a custom Linux installation or want to use the command line:
Open a terminal window and type the command:
roslaunch ardrone_tutorials keyboard_controller.launch
Pressing TAB at various stages throughout the command should autocomplete. If this is not the case, or if this command causes errors, check that you have setup your .bashrc file as per the ROS installation guide, and that you ran rospack profile after cloning the two git repositories.
If successful, this command will print out many startup messages, including:
Exception AttributeError: AttributeError("'_DummyThread' object has no attribute '_Thread__block'",)...
This exception is a Python bug and won’t affect the program.
You will also see a printout:
process[ardrone_driver-2]: started with pid  ===================+> 192.168.1.1
Within a few seconds, the output should progress well past this stage and begin printing configuration messages as the initialization of the AR.Drone progresses. If this is not the case, check the wireless connection to the drone, and check that any network cables have been unplugged from the computer.
Up, up and away!
If the keyboard controller launched successfully, you will now be seeing a live video stream from the drone. If this is the case, we’re ready to fly!
The controls (defined in ardrone_tutorials/src/keyboard_controller.py) are:
- E – Pitch Forward
- D – Pitch Backward
- S – Roll Left
- F – Roll Right
- W – Yaw Left
- R – Yaw Right
- Q – Increase Altitude
- A – Decrease Altitude
- Y – Takeoff
- H – Land
- SPACEBAR – EMERGENCY STOP
Note: Pressing the Spacebar will toggle the drone between an emergency state (all onboard LEDs are red), and the ready state (all onboard LEDs are green). If your drone isn’t responding to commands, make sure it is in the ready state!
With that said, I now hand the controls to you. Remember to keep a thumb on the Spacebar at all times, just in case something goes wrong.
Going Further (Added 17/12/2012)
This tutorial was fairly straight forward, the purpose being simply to get you up and running with the right software. Future tutorials will be more technical, however if you’re wanting to scratch the itch, try running some of the following commands at the terminal:
With a controller running:
$ rostopic echo /ardrone/navdata
Will print the data packets that are being sent back from the drone at 50Hz.
$ rosservice call /ardrone/togglecam
Will toggle the drone’s video stream between front and bottom cameras.
$ rxplot /ardrone/navdata/ax:ay /ardrone/navdata/vx:vy
Will plot the x and y acceleration on one plot, and the estimated x and y velocity on a second plot.
Now without a controller running (ie close the keyboard_controller window)
$ roslaunch ardrone_tutorials keyboard_controller_with_tags.launch
This runs a new launch file that enables tag detection. Now run:
$ rostopic echo /ardrone/navdata
And have a look at the various tag detection data that is returned (you have to be holding tags in front of or below the drone for this to work).
By default, this launch file configures the drone to detect Orange-Blue-Orange stickers on the front facing camera, and the A4 “Oriented Roundel” that comes with the AR.Drone 2.0 on the downward facing camera.
If your stickers are a different color, change the launch-file parameter enemy_colors to 1 for Orange-Green-Orange, 2 for Orange-Yellow-Orange and 3 for Orange-Blue-Orange.
Coming up in tutorial #2 – Joystick control
By now you may have noticed that flying with the keyboard isn’t so easy. This is largely due to the binary nature of a keypress (not pressed/pressed), which translates into 0%/100% control. Although we could implement software remedies such as input windup based on how long the key has been held, this is for the most part only a band-aid solution; what we really need is an analogue input device. Enter the Joystick (or control pad).
In the second tutorial of this series, we will be covering a little ROS theory (topics, messages and launch files), before installing a joystick, linking it up to the ROS system and then using it to fly the drone.
Source code and configuration
For those of you interested in the source code or configuration, I will briefly discuss the various options below. We will be going into much more detail in the next tutorial.
Full source code for this tutorial is available from the GitHub repository.
This file provides an abstracted interface to the AR.Drone driver and shouldn’t need to be modified
This file implements the video display window and shouldn’t need to be modified
This file brings everything together. The KeyboardController class implemented in this file extends the DroneVideoDisplay class, adding a keyboard handler for control. Key mappings are defined in this file and can be changed to suit your preferences.
This is the default configuration file, which sets the drone’s configuration and launches all required processes
This configuration file implements a more aggressive set of flight parameters for outdoor flight. If you are wanting to fly outdoors, the keyboard controller can be launched with the command:
roslaunch ardrone_tutorials keyboard_controller_outdoor.launch
For more information about configuring the AR.Drone, have a look at the AR.Drone driver’s readme.
That’s all folks
I hope you’ve had fun with this tutorial and I look forward to bringing you the next one in two weeks time!
If you have any questions, or comments about what you would like to see in the next tutorials, please send me a message or leave a comment to this post! You can see all the tutorials in here: Up and flying with the AR.Drone and ROS.
If you liked this article, you may also be interested in:
- Parrot AR.Drone app harnesses crowd power to fast-track vision learning in robotic spacecraft
- Taking your first steps in robotics with the Thymio II
- Discovering social robotics with the Aisoy1
- Classroom robotics: Motivating independent learning and discovery