Crazyflie hardware basics

The Crazyflie

crazyflie.jpg

The Crazyflie is a small Unmanned Aerial Vehicle (UAV) produced by the company Bitcraze. This page will get you acquainted with the Crazyflie and some of the custom tools.

This page is structured in the following way:

  1. Assembling your Crazyflie - the Crazyflie comes in pieces and you need to put it together 
  2. Flashing the Crazyflie Firmware - How to flash from your computer via radio
  3. The Crazyflie Client - A GUI for communicating with the UAV. How to log signals.
  4. Modifying the Firmware - How to modify the UAV code

Warning: Be aware that the UAV might possibly be able to hurt you (or people in your surrounding, or pets, or stuff) if you are extremely unlucky, for instance if you get a rotor in your eye. So use some caution.

NOTE: We will assume that you have a system installed with all the necessary tools. See Boot camp for more information.

NOTE: We assume that you are using a Linux system.

1. Assembling your Crazyflie (without camera)

You will need an assembled Crazyflie. The parts you should have been given connected to this are

  • 1 Crazyflie 2.0 box
  • 1 micro USB cable
  • 1 USB radio dongle
  • 1 flow deck

The instructions for this are available on this page. (you only need to do the  "Testing" and "Assembling" steps. The rest will be explained below.  

The Flow deck should be mounted under the drone. Make sure to turn it in the right direction (the forward marker cross should be in the same direction).

 

2. The Crazyflie Client (cfclient)

You start the program by typing "cfclient" in a terminal. It comes with the crazyflie-clients-python Links to an external site. package. 

Charge your Crazyflie by plugging it into the computer via the micro USB cable.

Plug in the USB radio dongle and make sure that it is found by your computer (e.g. by looking at the output from the command dmesg in a Linux terminal).

The cfclient GUI serves many purposes, and can be used to (i) fly the Crazyflie using a joystick controller, (ii) log data, (iii) plotting, (iv) setting parameters and (v) simpler debugging of the real-time implementation through the console.

 cfclient.png

Once the GUI has been opened, power on your Crazyflie, plug in the USB radio dongle and press SCAN in the GUI. Your Crazyflie should then be found in the "Select an interface menu", as a textstring such as "radio://0/80/250K". Pressing CONNECT should now establish a connection to your Crazyflie.

Note that if the Crazyflie is too close to the radio dongle in the computer, you might find oddly many Crazyflies due to radio disturbances. It suffices to move the UAV a couple of decimeters away, and do a new scan, to avoid this problem.

Note: you should do this far enough from other uninitialised Crazyflies as it will otherwise be hard to tell them apart.

When a connection has been established (this might take some seconds), open the "Connect->Configure 2.0" to open the Crazyflie 2.0 config window. Here you can change the channel of the radio, allowing multiple Crazyflies to be worked on in the same space. You should use the channel assigned to your group on this page. Then press "Write" for your changes to take effect. It is a good idea to change the radio bandwidth to 2 MBit/s. Press Write and then Exit. Restart your Crazyflie for the changes to take effect (i.e. power off and on, do not start in bootloader mode).

When you power on the Crazyfie it will run the motors in quick succession, showing that it is ready to take off. During this process, it is important that it lies still on a flat surface so that the IMU can be calibrated.

 

 

Understanding LEDs

  • Power on and all is good: The blue LEDs (2 and 3) are fully lit and the front right LED (1) is blinking red twice every second.
  • Power on and all is good but sensors are not yet calibrated: The blue LEDs (2 and 3) are fully lit and the front right LED (1) is blinking red with 2 seconds interval. Put the Crazyflie 2.0 on a level surface and keep it absolutely still to calibrate.
  • Radio connected: The front left LED (4) is flickering in red and/or green.
  • Battery low: The front right LED (1) is fully lit in red. It’s time to land and re-charge the battery.
  • Charging: The back left blue LED (3) is blinking while the right back blue LED (4) is lit.
  • Boot loader mode: The blue LEDs (2 and 3) at the back are blinking approximately once every second.
  • Self test fail: The right front LED (1) is repeatedly blinking five short red pulses with a longer pause between groups.

 

3. Exploring the Crazyflie Client

Connect again to the Crazyflie using the GUI (Scan and Connect). Under the menu item "View->Tabs" you will find a set of useful tabs which can be added to the GUI. Add the following

  • Console -Messages from the Crazyflie can be printed here using the consolePrintf() function in the C-implementation. Useful for debugging.
  • Parameters - An interface for changing defined parameters in the C-code over the radio link, list all available parameters. The parameters are defined in the C-code using the * ADD_PARAM *macros [6].
  • Log Blocks - This allows you to define custom log blocks defined in the C-code using the LOG_GROUP macros [7].
  • Log TOC - This shows the currently available attributes which may be logged.
  • Plotter - Plots any defined log block in real-time.

 LoggingTabs.png

(note: you should also check the Plotter alternative)

Spend some minutes exploring the new Tabs.

To get acquainted with the functionality offered by the GUI, investigate that the gyroscope works by rotating the Crazyflie and logging some data. To log data, simply open the Log Blocks Tab and check the "Write to file" boxes for the data you want to log. For example, check the Stabilizer logging with Period 20ms, log for a while, and then uncheck the box again. To view the log, go to Settings -> open config folder and go to the logdata directory (notice the path to the logdata for later use, for instance in moving results into Matlab for further analysis).

Open the plotter and use the menu bar, located inside the Plotter window and below all the Tabs, to choose  the "Stabilizer" log-block, see figure below where the  menu bar is shown on top.

 

GUIrot.png

This plots the rotational estimate in terms of the roll, pitch and yaw angles in the stabilizer Log Block (Facts for the interested expert: ZYX intrinsic Euler angles are used. The angles are estimated online using a simple non-linear estimator, called a Mahony filter, a non-linear complementary filter).

 Additional information on how to configure the client can be found here [6].

 

4. Uploading new firmware

Sometimes you will want to make changes to the firmware of the crazyflie, i.e. change the program running on the micro controller on the Crazyflie. 

Goto the folder with the crazyflie firmware

Open a terminal and execute the following (the last command will take a while)

cd ~/crazyflie-software/crazyflie-firmware
git remote set-url origin https://github.com/KTH-CAS-UAV/crazyflie-firmware.git Links to an external site.
git fetch
git checkout -B altset -t origin/altset
make clean
make

to compile the binaries from scratch.

Flash the firmware with 

make CLOAD_CMDS="-w radio://0/109/2M/E7E7E7E7E7" cload

where you should replace 109 with the ID of your drone. Your Crazyflie should start flashing assuming the Crazyflie successfully enter bootloader mode. You can edit the Makefile on line 21 and make it look like 

CLOAD_CMDS ?= -w radio://0/109/2M/E7E7E7E7E7

again assuming that your drone's id is 109. This way you can flash with only "make cload".

When the Crazyflie has been flashed, it will light up, run the motors in quick succession, showing that it is ready to take off. 

A red light blinking at 1 Hz is the sign of life - the heartbeat - if it instead glows a steady red and flatlines the battery is discharged. If red lights flash in another (ternary) sequence, the system has hard faulted - check the console for additional details and reflash the UAV with the clean firmware.

 

4.1 The General Structure

The motors are controlled using a so called pulse-width modulated (PWM) duty cycle. For some background on PWM signals you can watch this video

Duty cycle, frequency and pulse width--an explanation Links to an external site.Duty cycle, frequency and pulse width--an explanation

The firmware is written in C and implemented in FreeRTOS with several external dependencies. The structure is rather complex at a first glance, but in the part we will only edit a single file in order to enable manual motor control.

 

5. Basic dynamics

The motors of the crazyflie are numbered as indicated in the image below. It is encouraged to play around with the motors a bit to see how they affect the drone dynamically. To change a motor signal manually, go to the tab "Parameters" tab in the cfclient, scroll down to powerModeSet, where you can set the motor signals. M1 to M4 corresponds to motorID 0 to 3. If you look carefully on the Crazyflie, the M1-M4 axes are marked with white text as shown in the figure below.

cf2_props.png

 

In addition to generating a lift force, a motor will also generate a toque around the vertical axis. Explore how.

By the UAV construction, where two rotors spin clockwise and two counter-clockwise, one can decouple the total generated torque (impacting yaw rate) and total generated thrust (impacting elevation change). The quad-rotor construction actually allows independent control of the pitch, yaw and roll, as well as the UAV elevation, by combining M1-M4 cleverly (can you describe how?).

The images below show the relation between PWM duty cycles and rotor speed respectively and the thrust. We can see from the first graph that the relation between PWM signal and thrust is almost linear. See e.g., [9] for additional details relating to blade element theory. The results shown below where generated in static conditions. Experience has shown the simple model described here seems good enough also when the drones moves through the air. 

TvR.png

PvR.png

One important aspect to pay attention to is the ground effect which means the the way the drone behaves close to ground can be quite different from the way further up in the air. The same holds when flying close to, for example, walls when it can be sucked towards the wall.