Getting started with Crazyflie 2.0: Reliable use and light dev

Discussions and questions about the Crazyflie Nano Quadcopter
Post Reply
H0stname
Member
Posts: 32
Joined: Fri Feb 17, 2017 5:44 am

Getting started with Crazyflie 2.0: Reliable use and light dev

Post by H0stname » Sun May 14, 2017 8:09 pm

0. Preface:
First, my intent is not to say the current documentation is bad, or the devs haven't done enough work. There is a ton of good info on the wiki, Bitcraze Github readmes, and random places like https://www.bitcraze.io/getting-started ... velopment/ which don't appear to be part of the wiki. To make development easy on all platforms, using the Bitcraze Virtual Machine is advised, but I ran into issues using this on Windows because Virtualbox had issues with USB drivers.

If I could start over with everything I have learned in the past few months of light work on this for a class examining my own issues as well as other students, I would say for reliable use and light development of the Crazyflie 2.0, one should be running Linux naively on their machine (either alone, or with dual boot, or a persistent boot off a flash drive). This avoids issues with VM USB drivers, a source of major hassle for us. If you just want to fly it around on your computer, with Windows, using the CFClient binaries for Windows should work fine. But if you even think you want to do some dev, or have a more involved experience with this amazing, modular, open-source platform, bite the bullet and install linux, even if you have never used it before. This will attempt to get you up to speed with what I used the last month or so, and took many hours to get there. It is targeted at someone with no Linux or development experience, but wants to use their Crazyflie to its full potential, therefore lowering the barrier to entrance on this amazing platform. Some instruction is written, or pages on the wiki are linked where I would not change anything.

If you do not know what you're doing, this might feel a little spoon fed, but it is my personal belief, that having something running to play with and then learning why that worked, is more motivating than staring at a mountain, and feeling you can't play until you learn how to, and then climb it. While this is a bit more wordy than originally intended, it is actually not that complicated. Skim it, then you can type the commands exactly as shown without even reading the brief explanation and it should work (note that blindly following commands or running scripts, especially with admin privileges is bad practice). Once you've done it once, repeating the following steps takes only a few minutes, if that.

1. Concise setup intro
This assumes you have Linux installed on your machine, assumed to be a 'normal' laptop/desktop x64 processor etc not a raspberry pi (though this might work on that), or running off a persistent install (saves changes, unlike live CD) flash drive. Also assumed is that you have Git installed, which comes on most Linux distros. It is recommended that you read this on the machine you are setting up so you can copy and paste long or detailed commands.

The Crazyflie PC Client is entirely written in Python, which is great as it is easy to read and learn quickly. Python relies heavily on built-in and openly developed 3rd party libraries to run. To install/use the Crazyflie PC client (referred to as CFClient or CFC) on Linux, you will need to download the CFClient and install its dependencies (external Python libraries) inside a virtual environment, so that these do not interfere with other dependencies and make it hard to find the source of a bug. I have started doing this for almost everything as the compartmentalization is so nice.

You will also need to set udev permissions by adding a couple lines to a text file, or creating it if it doesn't exist.

2. Download the CFClient using Git
Open terminal and type these commands. The default current working directory is your home folder. Make a directory for Github stuff, with a good, organized structure for your projects.

Code: Select all

mkdir Github
Change Directory into it

Code: Select all

cd Github
Make a Bitcraze folder

Code: Select all

mkdir bitcraze
CD into it

Code: Select all

cd bitcraze
Your working directory is now inside this folder. See this by using the command 'pwd' in your terminal window if you'd like.

Download the CFClient by cloning the repository with Git

Code: Select all

git clone https://github.com/bitcraze/crazyflie-clients-python.git
This will make a directory in your current folder called crazyflie-clients-python and download the contents of the repo into it.

You could stop here, downloading the latest version will probably work with the dependencies described next, but just to be sure, reset the local files to the version this was designed for by changing into the cloned repository's folder:

Code: Select all

cd crazyflie-clients-python
(hit tab after typing 'crazy' and Linux should complete the rest)

and telling git to reset these local files to a past version, identified by the long SHA-1 hash at the end

Code: Select all

git reset --hard b1045f561863fdd60999543dcfa50080fa3ff26d
Make note of this directory you are in, as you will come back to it later. You can close the terminal window if desired.


3. Install Minconda
Use your web browser to download Miniconda here:
https://conda.io/miniconda.html

In a new terminal window, change directory to your 'Downloads'

Code: Select all

cd Downloads
Your working directory is now in your downloads in your home directory, aka ~/Downloads

Change permissions using chmod to allow the Miniconda setup execute

Code: Select all

sudo chmod +x Miniconda3-latest-Linux-x86_64.sh
Note: This is one of the few times prefixing a command with 'sudo' is ok. Running things as sudo is dangerous and should not be done unless absolutely necessary.

Run the installer:

Code: Select all

./Miniconda3-latest-Linux-x86_64.sh
.. follow the directions


4. Make a conda virtual environment and install dependencies for CFClient
This should be complicated, but using conda and the configuration file shown the next post, this is done in one line!

First, create the configuration file by pasting the following text verbatim into your favorite text editor (GEdit, nano, emacs, .. or vim :D ) and saving as crazyflie.yml. You can save it anywhere as long as you know where it is. The default location is probably your home directory. This file is a human-readable instruction file to tell conda what to install in your virtual environment.

Code: Select all

name: crazyflie
channels:
- defaults
dependencies:
- dbus=1.10.10=0
- expat=2.1.0=0
- fontconfig=2.12.1=3
- freetype=2.5.5=2
- glib=2.50.2=1
- gst-plugins-base=1.8.0=0
- gstreamer=1.8.0=0
- icu=54.1=0
- jpeg=9b=0
- libffi=3.2.1=1
- libgcc=5.2.0=0
- libiconv=1.14=0
- libpng=1.6.27=0
- libxcb=1.12=1
- libxml2=2.9.4=0
- openssl=1.0.2k=1
- pcre=8.39=1
- pip=9.0.1=py36_1
- pyqt=5.6.0=py36_2
- python=3.6.1=0
- qt=5.6.2=3
- readline=6.2=2
- setuptools=27.2.0=py36_0
- sip=4.18=py36_0
- sqlite=3.13.0=0
- tk=8.5.18=0
- wheel=0.29.0=py36_0
- xz=5.2.2=1
- zlib=1.2.8=3
- pip:
  - appdirs==1.4.0
  - "--editable=git+https://github.com/bitcraze/crazyflie-clients-python.git@b1045f561863fdd60999543dcfa50080fa3ff26d#egg=cfclient"
  - cflib==0.1.2
  - numpy==1.12.1
  - pyqtgraph==0.10.0
  - pyusb==1.0.0
  - pyzmq==16.0.2
prefix: /home/H0stname/miniconda3/envs/crazyflie
Now, tell conda to use this file to A) create a virtual environment, and B) install all dependencies including a version of cflib that worked for me and should always work because this file installs specific versions.

Code: Select all

conda env create -f crazyflie.yml

5. Set udev permissions as per the github readme for cflib
https://github.com/bitcraze/crazyflie-l ... ermissions

You'll make some text files and paste rules in them. It's pretty straightforward, but be sure you type the filenames correctly else it won't work and the USB device not being detected/used properly is illusive.


6. Run the CFClient!
cd back to the directory you cloned the CFClient repo to

Code: Select all

cd ~/Github/bitcraze/crazyflie-clients-python
If new to Linux, note that this is the same as the following absolute directory syntax instead of relative (with respect to your home directory)

Code: Select all

cd /home/yourUsername/Github/bitcraze/crazyflie-clients-python
Now to access those dependencies installed earlier, the virtual environment must be active. Activate by using

Code: Select all

source activate crazyflie
which can be done in any directory by the way.

With the venv active, run the CFClient and get flying and developing!

Code: Select all

python bin/cfclient
When you are done or want to work on a different project outside of your crazyflie virtual environment, simply type

Code: Select all

source deactivate
Note that you will also need to connect a controller to use as an input device. This is beyond the scope of this little post, but any recent version of Ubuntu (I used 16.04 LTS) should support it out of the box as long as it doesn't use proprietary protocols people haven't figured out yet like the Xbox One controller. I used a $20 controller from Meijer, a PowerA 106102-FR.

7. Discussions
What was done:
You used Git to pull/clone/download the latest version of the CFClient repository, reset the local files back to the version that this guide was made for denoted by that SHA-1 hash, created a conda virtual environment with static dependency versions included by using a file (also containing information linked to that version), activated this virtual environment, and ran the Crazyflie Client inside here. No hunting for specific dependencies or experiencing conflicts with other things installed on your computer because you used Miniconda, which contains nothing but Conda and Python, and all specific dependencies were described by a file.

8. Conclusions
Hope this was of some use, and that over time you learn where these instructions come from.. the importance of Git and version control, how that environment yml file pulls a specific version, more familiarity with Linux, speeding up your workflow with aliases and modifying your environment (both python and Linux itself) to better suit your liking etc. Also what hardware you have to play with and why the Crazyflie costs so much :D. Note that since you are cloning a specific version of things, it may contain bugs, and devs generally don't like users to use old version since they updated them for a reason. But this version (or commit in Github speak) worked for me, and was stable enough to get going quickly. Maybe this could be modified to contain yml files for major updates, to download and create virtual environments for these major updates in a quick and containable manner.

When you want to use or try the latest version, simply create a new virtual environment with a different name (an empty one, not from a file.. read google creating virtual environments with conda), and follow the setup instructions found on the crazyflie Wiki https://wiki.bitcraze.io/doc:crazyflie:indexor Github repo readmes to install necessary dependencies. You should just have to pull/clone the latest CFClient and run the setup, maybe also needing to install pyqt, easier with conda than apt. You can deactivate this new test virtual environment and active your old crazyflie one if something goes wrong. Or delete them all and simply follow the above procedure to recreate environment 'crazyflie' from a file.

Hopefully you will have learned more by then, and appreciate this very quick (<15 mins) setup for a specific version that can be replicated by lvl 1 noob by simply typing these commands verbatim. Then this lvl 1 noob will find it easier to lvl up in the future by having something to go back to and see the progress in action! Have fun out there, and feel free to post suggestions. Maybe I didn't do this as efficiently as I could have or something like that.
Last edited by H0stname on Sun May 14, 2017 8:40 pm, edited 7 times in total.

tobias
Bitcraze
Posts: 1583
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Getting started with Crazyflie 2.0: Reliable use and light dev

Post by tobias » Mon May 15, 2017 9:38 am

Awesome guide and great feedback! I highly think this should go into some section on the wiki, the question is which. What about under development - getting started section?

bjorn
Bitcraze
Posts: 12
Joined: Mon Nov 02, 2015 10:16 am

Re: Getting started with Crazyflie 2.0: Reliable use and light dev

Post by bjorn » Fri Jun 30, 2017 9:00 am

Hi @H0stname Would you be interested in helping us out and adding your guide to the wiki?

Post Reply