Friday, 21 July 2017

Controlling a Crazyflie

This is a note on getting set up to work on a Crazyflie 2.0.

After unpacking, testing and assembling the drone, you need to get some software to talk to it.

You can get an Android or iPhone client. I got the Android version for my Moto G5. It has a slight technical problem: on startup, the two joystick-equivalent pads are often not displayed. I have to select the preferences icon and then go back. It has a practical problem, too, in that there's no tactile feedback, so it's quite hard to know where your thumbs are while looking at the drone!

On the Mac, you have the option of installing in a virtual machine or from source.

The Mac instructions recommend using Homebrew. I already (reluctantly) have MacPorts (to support the latest Monotone, needed for Emacs ada-mode), and don't want another package manager, with the risk of conflicts.

Reading between the lines of the Homebrew and Windows instructions, the first thing was to install Python 3 from (this leaves the macOS standard version 2.7 as the default; you need to say python3 explicitly).

Now, it's best to create a virtual environment to install all the Crazyflie-related packages, to keep them away from either of the system-wide packages. The environment also has the advantage of making the appropriate version of Python the default.

mkdir ~/crazyflie
cd ~/crazyflie
python3 -m venv cf

which creates the virtual environment cf. To "activate" it,

source cf/bin/activate

To save typing you can replace the source with a period,

. cf/bin/activate

Your command prompt changes from, for example,
lockheed:crazyflie simon$
(cf) lockheed:crazyflie simon$

The command to leave the virtual environment is deactivate. but don't do it yet!

The Bitcraze software is on Github. To start with, you'll need to clone crazyflie-lib-python and crazyflie-clients-python.

Install crazyflie-lib-python:

cd crazyflie-lib-python
pip install -r requirements.txt

Download SDL2-2.0.5.dmg (or later), open the disk image, and copy SDL2.Framework to ~/Library/Frameworks/ (you may have to create the Frameworks folder).

Install crazyflie-clients-python:

cd crazyflie-clients-python
pip install -e .

That installs a lot of packages, but for some reason, PyQT5 isn't installed, so do so:

pip install pyqt5

You need a copy of libusb. You could download and build it from Sourceforge (you'll need pkg-config as well), or you could download and install this stlink package.

Now, connect your game controller (I have the cheapest one I could find, from Argos) and your CrazyRadio (I forgot to say that you'll need this, unless you fancy driving the drone with a USB cable attached) and run:


You'll probably want to configure your Input device: I have Normal ticked, then Device > USB GAME PAD > Input map > PS3_Mode_1.

Select Scan; you're looking for radio://0/80/2M. Select that, then Connect; and off you go!

No comments:

Post a Comment