Controlling the CrazyFlie

I love the CrazyFlie. It is a small quadcopter which you can fly in your home. The reason I bought it is that it is an open source project. Hardware, firmware and software: all open source. Kudo’s for the guys at Bitcraze!

 

When I saw it I immediately bought it and eagerly awaited its arrival. Looking at the software requirements I was in for a profound shock: all in Python. Not that I have any grudge against Python. I simply didn’t know the language. Well, that meant another project: learning Python. As I noticed that the documentation at Bitcraze was for developers well versed in Python I had to build my knowledge from the ground up. To help you avoid the many mistakes I made I documented the steps I made here. This documentation is for windows but I found the attempts of a implementing the cfclient on OSX quite helpful.

A – Learning Python

I had to start learning Python.  That was a pleasant surprise. A simple but powerful language, lots of documentation, libraries and forums. I used the following resources till now:

B. Installing Python

On linux and osx it is standard, not so on windows. Additionally the developers at Bitcraze request to install some extra libraries: Qt, Pygame and PyUsb.

  • You can find here what is needed to install Python and the required libraries. Best is to install 32bit versions of everything to avoid potential problems.
  • Python 2.7 should be installed. There are two forks of Python: 2.x and 3.x. The developers opted for 2.x so should you. When installing do not install in the C:\Program Files (x86) as I did. This will cause problems when you try to install libraries later on. Just take the directory suggested by the Python installer.
    When all is well you should find a Python27 entry in the start menu. Open it and click IDLE, the Python shell should come up
  • Sometimes you’ll need to run Python from the command prompt. Check whether the Python directory (the one in which you installed Python: let’s suppose C:\Python27) is in the PATH environment variable. Click Start | Control Panel | System | Advanced system settings (left panel) | Environment variables... | and check for PATH in the system settings. Double click it and check whether C:\Python27 is listed in the edit box. If not enter “C:\Python27;” (or whatever your Python directory is, include semi-colon) at the begining of the edit box. Do a lot of Ok’s. Open the command prompt, enter python -V and python should return its version number
  • Next install PyQt4, the Python user interface based on Qt. Choose the 32bit version for Python 2.7. The installation was succesful when you open IDLE and entering import PyQt4 returns without an error message
  • Same applies to Pygame. Enter import pygame to test whether the installation was succesful
  • Download PyUsb and libusb. Unpack both in the <your Python directory>\Lib\site-packages directory. This directory is the directory in which to install additional packages and already in the search path for modules to be imported by import statements.
    Open a terminal windows, CD to the <your Python directory>\Lib\site-packages\pyusb directory and type

    > python setup.py install

    This installs the pyusb into a newly created usb directory. Enter import usb to test whether pyusb installed succesfully

You might wonder which directories Python searches for its import directive. An article of Dan Fairs explains this quite well.

C. Using version control

The developers at Bitcraze have opted for Bitbucket as a repository and Mercurial for versioning.

  • Goto Bitbucket and create an account
  • Download Mercurial. When I downloaded the version of Selenic I had trouble to quickly download the source files. I noticed that Bitbucket had a tortoise shell and installed that one after uninstalling the Selenic version. Follow their instructions to set it all up
  • Create a directory on your disk where to install the crazyflie client. I’ll assume D:\crazyflie from now on
  • Go to the Bitcraze/PC client page on Bitbucket and look for the source link in the upper right corner. Select and copy it
  • Right click at your desktop and select Hg Workbench. Click File | clone repository. For source paste the copy you made in the bullet before and as destination choose D:\crazyflie (or whatever directory you choose). After some moments all is ready. You have made your clone of the cfclient of the Crazyflie

D. Run and modify the Crazyflie PC client

Supposing all your previous steps went ok you now have the cfclient software at your disposal. This is where I am now. When(ever) I understand what’s going on here I’ll report on how getting this up and running. See this part of the Wiki which I am studying now and which should give plenty of hints on how to proceed. I am stuck at an error message that the pluginhelper is not recognized. Whenever I solve this, this story continues.

 

 

 

About Arnold

I compose music and love to write software so I write software to compose music. Somewhere in that proces I got attracted to robots. Probably this all makes few sense but it is fun.

Category(s): Robots, Software

Leave a Reply