Studio 8

Controlling the Parrot AR 2.0 with Software Drone

1. Straight Interfacing with ROS

Connect to drone by wifi. Open a terminal, and run:

roscore

Then open a new tab in terminal (ctrl-shift-t), and run:

rosrun ardrone_autonomy ardrone_driver

Then open another terminal tab (ctrl-shift-t again), and run:

rostopic echo /ardrone/navdata

You can see an explanation of navdata here:

https://github.com/AutonomyLab/ardrone_autonomy#legacy-navigation-data

Now we going to tell the drone to take off and land. Open a new terminal window (ctrl-n), so you can type commands and keep an eye on the navdata.

Takeoff:

rostopic pub /ardrone/takeoff std_msgs/Empty

Land:

rostopic pub /ardrone/land std_msgs/Empty

Awesome. Close all your terminal windows and move to the next part.

2. Keyboard Tutorial

Open a terminal window and type the command:

roslaunch ardrone_tutorials keyboard_controller.launch

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

Remember to keep a thumb on the Spacebar at all times, just in case something goes wrong.

While playing with the drone, in a new terminal window (or tab):

rostopic echo /ardrone/navdata

Guess what this does:

rosservice call /ardrone/togglecam

Now, let's have some visualization fun. Open a new terminal and run:

rosrun rqt_graph rqt_graph

or if that gives you an error, issue this command and try again:

sudo apt-get install ros-groovy-rqt

These are all the different parts ROS "topics" that are running and their relationships with each other. Topics are info feeds that you can read and write to, with various effects. Navdata is a topic. They're a crucial part of understanding ROS. So, learn more:

http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics

Have some fun. Then, close your terminals and move on to the next step.

3. Tag Detection

Open terminal, run:

roslaunch ardrone_tutorials keyboard_controller_with_tags.launch

We've seen this before. But something is different! Grab a tag from the battery box, and hold it in front of the drone. It should display a marker over the tag.

Now, in a new terminal, run:

rostopic echo /ardrone/navdata

There's a new section for tags. More information can be found here:

https://github.com/AutonomyLab/ardrone_autonomy#tag-detection

This harkens back to the AR.Drone's original purpose as an augmented reality games toy. You should browse the AR.Drone SDK to see how lame ideas sometime lead to great products. Tag detection adds a whole new level of interactive potential, though.

Anyway, close your terminals and move to the next step.

4. Light Hacking

Some background: what we're running so far is ROS with two packages, ardrone_autonomy (the important one) and ardrone_tutorials. We're going to dig around ardrone_tutorials and make it do something new!

Open ~/ros_workspace/ardrone_tutorials/src/keyboard_controller.py. Most easily done by:

gedit ~/ros_workspace/ardrone_tutorials/src/keyboard_controller.py

We've found the keymapping file! Under "class KeyMapping(object):" you'll see a list of keymaps - let's add our own. Put in:

Custom = QtCore.Qt.Key.Key_Z

Line it up with the others correctly - python's big on that. Ask for help!

Now go down to "def keyPressEvent(self, event):" (not to be confused with "def keyReleaseEvent(self,event):") and you'll see an IF loop. We're going to put ours in here. Under "elif key == KeyMapping.Land: <linebreak> controller.SendLand()" put in:

elif key == KeyMapping.Custom

controller.SendCustom()

Now go down to #Setup the application function

add under display = keyboardController()

pub = rospy.Publisher('/ardrone/setflightanimation',"1 0")

Now save and let's try it out. Run:

roslaunch ardrone_tutorials keyboard_controller.launch

Hit Z and see what happens! These are predefined flight animations. More info is available here:

https://github.com/AutonomyLab/ardrone_autonomy#flight-animations-new

Experiment with flight animations (except flips - save those for when you're outside). You can see a list by running:

gedit ~/ros_workspace/ardrone_autonomy/srv/FlightAnim.srv

You can learn and explore more here:

http://robohub.org/up-and-flying-with-the-ar-drone-and-ros-handling-feedback/