CrazyflieHacking

Categories: Perching MultiModal

This page is a tutorial for Crazyflie Hacking! Also included are basic instructions for operating the Crazyflie

Connecting and Flying the Crazyflie

Barebones beginner's guide

  • Log onto one of the computers that has the Bitcraze Virtual Machine installed. As of 7/23, the lonesome computer in the back corner is the only one successfully running the VM. The Dell laptop has been difficult to set up, but should be good to go soon.
  • Open "Oracle VM VirtualBox" and run the Bitcraze VM 0.5
  • To connect the CF (Crazyflie), plug the crazyradio dongle into the USB port. Also connect the red PS3 controller via USB.
    • You'll have to pass the crazyradio and PS3 controller into the VM by right clicking on the little USB icon in the bottom right corner of the VM (3rd icon from the left) and selecting the relevant options. They should have check marks next to them now.
  • Open the CF client ("Crazyflie PC client latest")
  • Hit connect and wait for the scanner to pick up the CF. Hit connect.
  • Go to Input Device (tab) -> Devices and make sure that the USB controller is found.
  • Go to Input Device -> Mappings and select your preferred mapping mode. My fav is PS3_Mode_2. The thumbsticks will control everything you need to fly. Play with the controller before turning the CF on to get used to the controls.
  • Turn the CF on by pushing the tiny on-off button on the side of the PCB. Make sure the CF is level when you turn it on, as it calibrates its orientation immediately. When it's done the props will spin (don't be afraid!).
    • If you're having trouble connecting, the CF probably needs to be charged. Plug into the micro USB on the bottom side to charge. You know you're charged when the green light stops blinking
  • You're good to go! Note that the piece of tape on one of the arms indicates the forward direction.
    • As you start flying, it may be useful to turn the Max Yaw angle/rate to 0. Place the CF in the same orientation as you are standing so you don't have to do any vector mapping in your head!

Intermediate Tips

  • If you're using PS3_Mode_2, the X button will activate altitude hold mode. It's ok, but not perfect
  • If you get into a precarious position, pressing the O button will inactivate the motors. Try not to press this if you're really high in the air...

Logging Variables

-Downloading data from the Crazyflie

Plotting Data

  • Connect the CF, open the CF client, and navigate to View -> Tabs -> Log TOC -> click on Log TOC tab to view a list of the available variables that you can log.
  • Go to View -> Tabs -> Plotter -> click on the Plotter Tab
  • Go to Settings -> Logging Configurations -> add your desired variables (can be a group or individual vars). Set your logging period in the bottom left. Set the configuration name to something useful (like the name of the plot you are about to generate). SAVE!
  • In the plotter tab, click the scrolly option bar thing and select the variable you just set up.
  • See cool data

Adding Logging Variables

- for example, adding temperature logging in degrees Fahrenheit

  • Open Eclipse
  • In Package Explore navigate to crazyflie-firmware -> modules -> src -> stabilizer.c
  • Declare a global variable -> static DATA_TYPE NAME, where type is a float, int, boolean, etc. For the Fahrenheit temp calculation, I'd write static float temp_f
  • Find the method called "static void stabilizerAltHoldUpdate(void)" and insert your variable into the code.
    • For example if I wanted to add the calculations to get the temperature in Fahrenheit, I'd write temp_f = temperature * 1.8 + 32;
  • Go to the bottom of the script. Create log group by writing:
    • LOG_GROUP_START(Group name you want)
    • LOG_ADD(LOG_DATA_TYPE, name you want in the plotting GUI, &variable name)
    • LOG_GROUP_END
    • example:
    • LOG_GROUP_START(Temperature)
    • LOG_ADD(LOG_FLOAT, degrees_f, &temp_f)
    • LOG_ADD(LOG)FLOAT, degrees_c, &temperature)
    • LOG_GROUP_END
  • Go to bottom left corner in Eclipse named "Make Target"
    • open crazyflie-firmware -> Make radio-bootloader build (pretty quick) -> Flash via radio, reboot CF (takes longer)

Parameters

-setting variables in the Crazyflie

Viewing Available Parameters

  • Open the CF client -> Tabs -> Parameters
    • Available info is (Name, Type, Access, Value)
      • RO means read only, RW is read/write

Creating New Params

  • Open Eclipse and go to Package Explore, navigate to crazyflie-firmware -> modules -> src -> stabilizer.c (same place as where you add variables)
    • Example code will be a parameter to turn the motors on and off
  • Declare global variable (static DATA_TYPE NAME)
    • For params, you always (I think) will use a boolean as the data type
    • Ex: static bool enable_motors = true;
  • Create param group
    • PARAM_GROUP_START(group name)
    • PARAM_ADD(PARAM_TYPE, name you want in the CF client, &variable reference)
    • PARAM_GROUP_STOP(group name)
    • Example
    • PARAM_GROUP_START(mc) <- short for motor control
    • PARAM_ADD(PARAM_UINT8, enable, enable_motors)
    • PARAM_GROUP_END(mc)
  • Go to the loop where the control occurs (for the example this is stabilizerTask where it says if actuatorThrust > 0) and insert your param
    • Ex: if actuatorThrust > 0 && enable_motors
  • Make radio-bootloader build
  • Flash via radio, reboot CF immediately
  • Reconnect CF in client

Using the GUI

Creating CF client tabs

  • Open Python in the Bitcraze VM using PyCharm
    • Navigate to lib -> cfclients -> ui -> tabs
    • Open ExampleTab.py . Copy and paste into new .py file and save with your desire tab name.
    • Ctrl-f all instances of "example" and rename them to the name of your tab
  • Open Qt 4 Designer
    • Create a new widget (.ui file) and drag n drop fun buttons and other things to you ui
    • Name each ui item in the top right item inspector
      • Name them starting with an underscore
      • Example: _temp_f
    • Save using the same name as your .py file to the same folder as the other tab files

Connecting the UI to a Logged Variable

  • Return to Eclipse and go to "connected" function
  • configure your variable using YOURVAR_conf = LogConfig("name", sample rate in ms)
    • Also add the variable by calling YOURVAR_conf.add_variable("name")
    • Ex: temp_conf.add_variable("temp.F")
  • Add this variable to the API by calling self._helper.cf.log.add_config(YOURVAR_conf)
    • Also include
    • if YOURVAR_conf.valid: //checks to see if the var exists
    • YOURVAR_conf.data_received_cb.add_callback(self._log_data_signal.emit) //add call-back and connect to a signal
    • YOURVAR_conf.start() //executes the command
  • Go to _log_data_received method
    • Create the text for the UI using the received data
      • self.(name of UI part you made).setText("{0:.2f}YOURLABEL".format(data["Name of variable you added"])))
      • Ex: self._temp_f.setText("{0:.2f}degrees F".format(data["temp.F"])))
      • {0:.2f} <- this is a python command that makes a numerical string w/ 2 decimal points
  • Go to bin -> cfclient -> run

Adding a Parameter to the UI

Page last modified on January 18, 2016, at 10:50 AM