Skip to content

Instantly share code, notes, and snippets.

@madelinegannon
Last active January 19, 2024 05:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save madelinegannon/ba38a89c210d011a3ae224651b8a1aee to your computer and use it in GitHub Desktop.
Save madelinegannon/ba38a89c210d011a3ae224651b8a1aee to your computer and use it in GitHub Desktop.
Setting up Crazyflie 2.1

Notes on getting started with interactive control of the Crazyflie 2.1 drone.

Contents

  1. Basic Setup
  2. LPS Setup
  3. Autonomous Flight

Setting up a Crazyflie 2.1

This tutorial walks through how to set up and fly a Crazyflie 2.1 drone with a PC and PS4 Controller.

Requirements

Getting Started

  1. Install the Crazyflie Client on your PC
  1. Unpack, Test, Assemble, Update, and Configure your Crazyflie.
  1. Connect the Crazyflie to the Crazyflie Client.
  • Plug in the Crazyradio PA.
  • Connect your PS4 to the PC.
  • Open the Crazyflie Client; in terminal run:
$ cfclient
  1. Read the Crazyflie Client User Guide. A few things to note:
  • In the client, make sure all the trim variables are set to 0 to start.
  • Turn on the Crazyflie drone by pressing the ON/OFF button near the top right of the body.
  • In the Crazyflie Client, press the Scan button to set the Crazyradio PA as the client's interface.
    • If the drone connected to the Crazyradio PA, it should be blinking red (about once every second).
  • Connect the PS4 to the Client by going to the dropdown menu Input Device, and selecting Device > PS4 Controller.
  • Connect the Crazyflie to the PC by hitting the Connect Button.
    • If the drone connected to the PC, you should be getting live IMU readings in the Crazyflie Client.
  1. Start Flying. Once the input device is connect, here's how to see what button does what:

But in general, there's not a lot of info / explainers for how to fly with a joystick.

  • This has the best explanation, but the details are only for when flying with LPS.
  • Depending on your configuration, here are a few tidbits:
    • Press the O button once to start motors.
      • YOU HAVE TO PRESS AND HOLD THE O BUTTON TO DISABLE THE MOTORS.
    • RIGHT joystick UP/DN is thrust(+/-) <-- Z(+/-)
    • RIGHT joystick LEFT/RIGHT is yaw(+/-) <-- Rz(+/-)
    • LEFT joystick UP/DN is X(+/-) <-- maybe Rx(+/-)?
    • LEFT joystick LEFT/RIGHT is Y(+/-) <-- maybe Ry(+/-)?
  1. Stop Flying.
  • You can press-and-hold the O button to disable the drone motors.
  • Once the drone has landed, press the Disconnect Button in the Crazyflie Client to end communication.
  • Now you can turn off the Crazyflie drone by pressing the ON/OFF button (you don't need to long press).

Adding LPS

This tutorial walks through how to set up Bitcraze's Loco Positioning System (LPS) to work with the Crazyflie drone. The LPS provides absolute positioning (in the 10cm range).

Additional Requirements

  • (8) LPS Nodes
  • (1 per drone) LPS Deck
  • (8) 3D Printed Stands for the Nodes
  • (8) Power Supplies for the Nodes
    • Can be any 5V-12V, 150mAmp power supply (25' micro USB cables work)

Getting Started

  1. Configure, Install, and Calibrate the 8 LPS Nodes.
  • LPS Tools Notes:
    • LPS Wiki: https://wiki.bitcraze.io/doc:lps:index
    • To run the LPS Tools GUI from terminal: python3 -m lpstools
    • You really have to press-and-hold the DFU button as you plug in the board to bootload new firmware
  • Installation Notes:
    • Print 1 stand per anchor
    • "The anchor antenna should be placed 15cm from any wall, ceiling or metal object to avoid interfering reflections."
    • Each of the nodes needs to be powered — I found that long (25') micro USB cables work well.
      • USB cables over 15' are POWER ONLY ... no data.

Flying with LPS

  1. Connect, Configure LPS, Configure Gamepad, Fly Manually
  • Flying Notes:
    • You can preview and set the Gamepad buttons using the Input device > Configure device mapping tab. Hit the Configure button, and then load a preset to see what buttons do what.
    • After a crash, look at the Loco Positioning Tab: the LPS is often very, very wrong (meters off), and flying using the Assisted Control button will send the drone way off. Turn off the drone and reconnect to try to correct the calibration error.
    • The drone's battery is too low to reliably fly at around 3.7V. Swap the battery to avoid a crash.

Here are a few good examples from crazyflie-lib-python to run for basic autonomous flying:

example/positioning/intialPosition.py
example/autonomousSequence.py
example/autonomous_sequence_high_level.py

Autonomous Flight

Begin by reading the docs on the Crazyflie Python API

Understanding Logging & ToCs

It took me a while to understand how use the Crazyflie API to access all the information and parameters you can visualize cfclient:

  • Here's my original question on the Bitcraze Forum: Streaming multiple crazyflie positions from LPS over UDP
  • You can add asynchronous callbacks onto certain variables using the Logging and Parameter frameworks.
    • Use Logging when you want continuous updates.
    • Use Parameters for rare updates (like on start up or shut down).

More Info

It also wasn't immediately obvious what all the parameters were, and how to see the Logging or Parameter ToCs:

  • You can see them by opening the cfclient Parameter and Logging tabs, and connecting a Bitcraze.
  • These are cleared once you disconnect.

Finally, once I could see them, it wasn't clear what each variable did:

  • There's currently no good documentation for this from Bitcaze, so contact support or ask the forum.
  • The position estimate from the LPS is stored in kalman.stateX, kalman.stateY, kalman.stateZ

Here are a few good examples from crazyflie-lib-python that helped me understand logging with the crazyflie:

example/basicLogging.py
example/autonomousSequence.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment