Home

Awesome

CRAZYFLIE ROS DRIVER WITH GUI

CrazyflieROS Node Details below.

This assumes my latest custom firmware flashed.

Please note this document might be outdated. For discussions and questions on using the kinect part, please ask here.

Update: Branch joyManager was merged into master, no more mix-ups :)

Update: Sixaxis/sixpair instructions updated to (workaround for a bug introduced by the later kernels)

Update: Relative barometric pressure for above ground level estimation. Details

Update: MSc Thesis is now online: Visual Inertial Control of a Nano-Quadroto With Video: Video on Youtube

Introduction

This package / document was created to help some friends get working with the crazyflie, ROS and the mocap system here at TUM. Still very much a work in progress. The goal is to obtain a general overview of the flie, get a development environment set up for changing the firmware and implementing client side code.

I assume you are familiar with ROS and are running a recent version of Ubuntu. This was tested on 12.04 and ROS Fuerte to Hydro. You will need a joystick to fly the flie with - the code in this package was written to fly the flie with PS3 Sixaxis controller.

Also, some permissions might be messed up (thanks Mr NTFS partition..) so you might need to chmod +x a few files (the *.cfg files probably).

Important Links

A quick list of useful links

Crazyflie Concepts

One has to distinguish between:

Hardware

Sensors

Communication

First steps

Lets download all the code and prereqs we need. I probably missed a couple, so please let me know (either via githib or the crazyflie forums)

Requirements and source code

Required packages

You will need the following, os run: sudo apt-get install python2.7 python-usb python-pygame python-qt4 beep terminator ipython ros-$ROS_DISTRO-joystick-drivers

To compile the firmware you will need GNU Tools for ARM Embedded Processors

sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi
Source Code

I recommend you use git to obtain the latest source code:

You will need 3 sets of source code. Put them in your working ros directory.

Permissions

To use the crazyradio you will need to set some udev rules. For conveniance, just run sudo sh udev.sh from the crazyflieROS directory.

Some of the files in this repo should be executable, but are not (thanks to my crappy NTFS permission). Especially some of the the files in crazyflieROS/cfg, crazyflieROS/bin and crazyflieROS/src/crazyflieROS/driver.py will need chmod +x path/file (Update: most of this should be fixed now, let me know if it is not)

Optional

To use the optional beeping functionality of my crazyflie driver you will need to enable the terminal bell: sudo modprobe pcspkr

I guess you can use any IDE, but I will use the following in this guide:

Running stock Crazyflie client

The crazyflie client is a GUI fully in python that exposes all aspects of the flie. You can use it to flash the flie with new firmware, remote control it, observe sensor data, set parameters. Run bin/cfclient from the crazyflie-clients-python directory.

Flashing the flie with (potentially custom) firmware using the stock client.

Lets flash the flie with latest stock firmware. For now, instead of compiling it, we will download the latest bin directly from here. Extract it, we need the .bin file.

Unplug the flie if it is plugged in. Insert the dongle into a usb2 port (usb3 might work with the most recent radio firmware). Note at this point the flie does not need a battery or motors, just the PCB will suffice.

Run bin/cfclient from the crazyflie-clients-python directory. Then follow the Bootloader instructions and use the bin file you just downloaded. Using the instructions and links on that page you should now be able to connect and fly the flie.

Developing for the flie

Compile / modify firmware

Start up eclipse and

This should open a new project with the crazyflie firmware. Press ctrl+b to build it. This should result in a short summary of ram/rom usage and if all goes well produce a cflie.bin file you can flash the flie with using the procedure above.

Client side code

Start up pycharm, File | Open, chose the crazyflieROS directory.

TODO

Communication Protocol

Some important concepts based on how the communication with the flie works are important befor you can start anything. The flie has its own custom communication protocol called the Crazy RealTime Protocol (CRTP). Has the notion of packets, ports, etc. Luckily a higher level python library implemented, so we dont need to deal with the details Details can be found Here

Parameters

Use this when you wish to set/get a variable on the crazyflie with low frequency. Eg turning an led on/off, setting PID values, etc. Getting and setting is initiated from the computer. Update: here is an example.

TODO: Examples of how to add logging to the firmware and read it from the client side code

Logging

High throughput reading of variables on the crazyflie. One requests them, and the crazyflie sends them at a given frequency. Useful for continuously reading sensor data Maxes out at 100hz What can be logged is specified in the firmware. Logs are then requested from the client and the flie starts pushing the data back Update: here is an example.

TODO: Examples of how to add parameters to the firmware and set/read them from the client side code

Commander

Primitive but fast way to throw values at the crazyflie. Only used for sending it command data, eg roll, pitch yaw Recommened to use at 100hz. Send a command at least once every 2 seconds to keep the flie alive.

TODO: Show the function that reads the variables in the firmware and the client side code that sends them

Using ROS

Setting up bluetooth PS3 Controller using PS3 Joy

__Update: One the kernel updates broke the default PS3 driver (sixpair). Please see these instruction to fix it (tested with 12.04).

Once one has done the above, run

sixad --start 

This exposes your joystick under ls /dev/input/js*. To test it, you can use jstest-gtk: jstest-gtk or jstest /dev/input/js*

Next you will need to start a ros node to read the joystick data and send it over the ros network. Here Ive made a launch file that launches 3 nodes: one that exposes the controller to ROS; one that reads it and exposes crazyflie controls, and a gui to set some settings. Launch with

roslaunch crazyflieROS joy.launch js:=0

where you will need to replace X with your joystick nr. Now you can visualise the outputs of the nodes:

<a name="details"></a> CrazyflieROS GUI Application

This is a ros node wrapped in QT gui. For now some of the functionality is still in separate python nodes (especially joy_manager_pid.py), but all should eventually fuse into this one.

Feautres

Screenshots

Here are some screenshots. Note some are outdated as they do not show CPU usage.

Logging Logging

Params Params

Attitude Indicator Attitude Indicator

Kinect Kinect

Input input

Settings Settings

Starting the node

Run is just like any ros node: rosrun crazyflieROS driver.py

Show optional input arguments: rosrun crazyflieROS driver.py --help

Motion Capture System

##Video example

TODO: Overview, way poin control, wand control, pid.launch

Setting it up Qualisys

Read Realtime data with ROS

Qualisys ROS Node

Defining ridig bodies

PID Node

Controls
Options

Required TF transforms

Kinect Tracking and Control

One can also use the kinect to track the 3d position of the flie. However, one must use the on board attitude to estiamte the yaw. As yaw drifts one must manually align it to the camera optical axis. The gui has an option to "set north" in the current direction the flie is facing. More on this later.

Prerequisites

Make sure you have the latest custom client code.

Make sure you have the latest custom firmware flashed.

Install the freenect ROS stack using the instructions from here - this will install all the drivers, etc you need to use the kinect.

Highly Recommended: Add some paper to the flie to make it have a larger cross section and improve tracking paper

#####Get the PS3 controller running Start the sixaxis driver: sixad --start, and follow the instructions

Then start the joystick controller with PID functionality:

#####Launch the crazyflie driver:

At this point it makes sense to fly the flie around and make sure it is balanced. To adjust the trim, you can use the d-pad. To set it to the current joystick position, press and release R1. To reset, press square. If all is working, continue.

#####You will also need the following transformations

#####You will need to start the kinect driver

#####You can use RVIZ to verify everything:

#####Now start the tracking.

<a name="multiBaro"></a>Using a second flie for barometric pressure reference

Connecting to multiple crazyflies with the same dongle is not supported yet (although there is an experimental branch I have not tested), but using two radios works with recent updates, despite being a little buggy.

Two connect to two flies, attach two dongles, then run

rosrun crazyflieROS driver.py #defaults to --radio=0
rosrun crazyflieROS driver.py #defaults to --radio=1

This should launch two nodes, one which advertises topics over /cf0/... and the other over /cf1/...

Turn both flies on (make sure they use different channels), and scan using each client. Then connect each client to a different flie (using the dropdown). Sometimes scanning is a little buggy, somehow the order matters. Some sort of bug in the radio driver, supporting multiple radios is experimental.

Make sure you are logging the baro.asl data with both clients (@ 100hz). Then put the flies on the ground, and in both clients go to settings, click Check Sea Level, click Set Level. The, for the flie you wish to fly with, check advanced barometer, and press "connect". This now listens to the data from the other flie and uses it as a baseline. So if someone opens a window or so, both flies will notice the pressure change, but the flying flie wont care, as the relative pressure difference between them stays the same.

Adding a camera

##First person video #####Forum discussion

Camera

vo

Hardware

Cam directly
VLC/ROS viewing
Cam with tx/rx
Cam with tx/rx powered from the flie

Noise

Before

After


Changing Code

Remember

Todo

Notes

Q Control + Track K Track

rosrucrazyflieROS printW2K.py rosrun tf static_transform_publisher 0 0 0 0.121965 0.126995 -0.691227 0.700858 /cf0 /cf_kinect 10