AR Drone : Tutorial

AR.Drone Instructions

Note 1: This is a draft article. This is being kept on my blog as a future reference guide. You can go through it and get the joy of flying a quadrotor autonomously in no time. Thanks to Jurgen Strum from TUM university for the wonderful tutorial which makes this possible.

Note 2: These instructions apply to Ubuntu 12.04 and ROS Fuerte. It would be great if somebody could create a second page with instructions for Ubuntu and ROS Hydro.

Installation

We assume that you have Ubuntu 12.04 LTS installed on your computer. If you use normally a different operating system and you don’t have a free partition on your hard drive, you can also install Ubuntu onto a (bootable) USB stick. In this case, you need at least 4 GB of additional storage on the stick.

Furthermore, we need to install ROS (the Robot Operating System) and various ROS packages (ardrone driver, joystick, Python example). In the following, we guide you through all steps required to set up your system accordingly.

Install ROS

This section comprises the core steps of installing ROS Fuerte on Ubuntu 12.04 as described here:

  • First, add the respective keys and repositories:

$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list'

$ wget http://packages.ros.org/ros.key -O - | sudo apt-key add -

$ sudo apt-get update

  • Now install ROS and some useful packages:

$ sudo apt-get install ros-fuerte-desktop-full ros-fuerte-joystick-drivers python-rosinstall python-rosdep liblapack-dev libblas-dev daemontools libudev-dev libiw-dev

  • Create your ROS workspace folder

$ mkdir ~/workshop

  • Add ROS commands and your workspace folder to your .bashrc: Open it in your favorite text-editor (e.g. using gedit ~/.bashrc), and append the following two lines at the end:

$ source /opt/ros/fuerte/setup.bash

$ export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/workshop

  • Check your installation by opening a new console window and starting

$ roscore

  • Everything is fine when you see the line "started core service [/rosout]". You can then stop roscore by hitting CTRL-C.

Install and compile ROS packages

  • Download the source code into your ROS workspace.

$ cd ~/workshop

$ GIT_SSL_NO_VERIFY=1 git clone https://github.com/AutonomyLab/ardrone_autonomy.git -b fuerte

$ GIT_SSL_NO_VERIFY=1 git clone https://github.com/tum-vision/autonavx_ardrone.git

  • Compile the packages. Note that the compilation process requires internet access and takes around 10-20 minutes.

$ roscd ardrone_autonomy

$ ./build_sdk.sh

$ rosmake ardrone_autonomy ardrone_joystick

Manual Flight

In this section, we set up the AR.Drone, perform a manual flight with a Sony Playstation 3 joystick, and record a bag file (logfile). For this task you need a Parrot AR.Drone, a PS3 joystick and some space to fly around.

  • Connect the AR.Drone battery.
  • Connect to the AR.Drone WLAN.
  • Start the ROS master and the AR.Drone driver (each in a separate terminal window).

$ roscore

$ rosrun ardrone_autonomy ardrone_driver

This command will print out some information on the connection etc. After 70 lines or so, the output should come to a rest. If everything works, the result should look as follows.

If you see error messages (bad packets etc), then your firmware might not be compatible with the AR.Drone driver on your computer. In this case, either try to upgrade to a newer firmware or upgrade the ardrone driver (whatever is newer).

  • Open a new terminal window and see whether you get navdata messages from the quadrotor:

$ rostopic echo /ardrone/navdata

The result should look as follows. This message contains the telemetry data from the quadrotor. In this lecture, we are primarily interested in the readings from the IMU and visual odometry sensor. The current orientation of the AR.drone is given in roll-pitch-yaw angles (rotX, rotY, rotZ). The height is provided in altd. The horizontal speed can be read out from vx and vy. Note that some fields (like altd) only provide values while the quadrotor is actually flying. Press CTRL-C to stop when you are happy.

  • Now start rviz, a 2D and 3D visualization tool for all kinds of sensor messages.

$ rosrun rviz rviz

  • Add an Image display to RVIZ and change the Image Topic to /ardrone/image_raw. You should see the live camera stream from the quadrotor’s frontal camera.
  • Plug in the joystick, and start the joystick driver as follows:

$ rosrun joy joy_node

On some computers, it’s necesary to add the parameter _dev:=/dev/input/jsX, where X is the number of the joystick device. Inspect the topic /joy to verify that the joystick works as follows (open a new terminal window):

$ rostopic echo /joy

Press CTRL-C when you are satisfied. The output should look as follows.

  • Note: You might have to press the P (PlayStation) button in the middle once on the joystick to activate it.
  • The ardrone_joystick node we provided translates the raw joystick messages to the correct control commands sent to the quadrotor. Start it as follows:

$ rosrun ardrone_joystick ardrone_teleop

This node translates the joystick messages (/joy) to velocity command messages that the AR.drone understands (/cmd_vel). To check whether these messages are actually generated, open a new console and run:

$ rostopic echo /cmd_vel

Move the sticks of the joystick. The result should look as follows.

  • The axes and buttons are assigned as follows:
    • The R1 button toggles the emergency state of the robot. Pressing R1 while flying will stop the rotors immediately. If the LED beneath the rotors are red (for example, after a crash), press R1 to reset the quadrotor.
    • The L1 button starts the motors of the quadrotor. It also works as a deadman switch so that the robot will land if you release it during flight. The quadrotor will ascend to one meter above ground and tries to hold this position.
    • The left stick can be used to control the roll and pitch angle of the quadrotor. Keep in mind that these velocities are given in the local frame of the quadrotor!
    • The right stick controls the yaw-rate and the altitude.
    • The select button can be used to switch between the two cameras. This can also be done by executing rosservice call /ardrone/togglecam.
    • The triangle button can be used to switch off the on-board position stabilization: Per default, the quadrotor hovers (i.e. stabilizes its horizontal position by keeping vx and vy at zero) when you do not touch the left control stick. It even actively decelerates when letting go of the left control stick.
    • Pressing and holding the triangle button will switch this off, i.e. give you direct control over roll and pitch at all times – note how this leads to rapid drift in horizontal position.
  • First Flight: You are all set up to fly the quadrotor! Fly a short round through the lab to practice your flying skills. You can try to take a group picture of yourself while flying! Tip: If the quadrotor does not take-off vertically but immediately shoots away, you need to calibrate the IMU. This is done by placing the quadrocopter on a horizontal surface, and calling rosservice call /ardrone/flattrim.

Autonomous Flight

  • We provide several (minimalistic) Python examples in the folder ardrone_python:

$ roscd ardrone_python/src

  • Example 1: Odometry. This script just prints some data from the navdata message sent by the quadrotor. It also works when the robot is not flying – just move the quadrotor by hand and see how the values change. As an exercise, add the code from week 2 (odometry) in the callback to compute the position of the quadrotor in world (global) coordinates. Note that the height sensor does not work when the quadrotor is not flying. Use the joystick to navigate the robot around and inspect the values.

$ ./example1_odometry.py

$ ./example2_takeoff_and_land.py

  • Example 3: Simple trajectory. This script publishes /cmd_vel messages. The quadrotor takes off, flies forward for 2 seconds, turns for 2 seconds, and flies forward for another 2 seconds, and lands again. Note that you have to kill the ardrone_teleop node before you run this script – otherwise, the joystick (which also sends /cmd_vel messages) will override the motion commands from this script.

$ ./example3_trajectory.py

  • Example 4: Everything combined. This script contains both a subscriber for the /ardrone/navdata message as well as a publisher. The script sends a takeoff command and then repeatedly sends the quadrotor forward and backward for 2 seconds. To stop the quadrotor, either start the joystick node (and press and release the L1 button), or catch the quadrotor in the air and turn it by 90 degrees (to trigger the emergency stop).

$ ./example4_combined.py