Crazyflie and Networking Related Procedures


Crazyflie setup process

Overview:

NIMBUS Lab operates the crazflie 2.0 using the work of Whoenig and his associates from USC ACT Lab. Their documentation can be found at http://crazyswarm.readthedocs.io/en/latest/index.html. However, there are some wholes in this documentation. The purpose of this document is to walk the Crazyflie operator through the setup of the Crazyflie system, from downloading a virtual machine to navigating the holes in the USC Crazyflie documentation.

  • If you are working in room 218 you will probably want to skip to page 7 of this document to “Actually Operating the Crazyflies.” If not, you will probably want to start with “System Reqirements

  • If you want Internet on the desktop in room 218 look under “Possible Problems

  • The current distributed controller is a python script under:

    ~/crazyswarm/ros_ws/src/crazyswarm/scripts/Distributed_Controller.py

     

  • Crazyflie PID controller is in Crazyflie firmware under

        “crazyflie-firmware/src/modules/src/

  1.          Instruction for compiling and flashing this firmware can be found at “https://github.com/USC-ACTLab/crazyflie-firmware

Assumptions:

  • Host computer has Windows 7 as native OS

  • Host computer uses has VMware® Workstation 12 Pro

    • Version 12.1.0 build-3272444

  • Host computer uses Vicon

    • A Vicon network adapter is already present on the host machine under path “Control Panel\Network and Internet\Network Connections”

Possible Problems:

If you are working in room 218 it is likely that the USB Wi-Fi receiver on the HRI desktop will be too slow to download packages or load a website at a reasonable rate. If this is the case, you may want to bridge the Wi-Fi from your laptop to the desktop.

Setting Up Bridge Between Windows 10 Laptop to Ubuntu 16.04 VM

Setting Up Bridge on Windows 10 side:

  1. On your Windows 10 Laptop right click on the Wi-Fi icon on the bottom right hand corner of your screen

    1. You may need to click on the upward carrot on the bottom right hand corner of your screen to get to the Wi-Fi icon.

  2. After right clicking select “Open Network and Internet Settings”

  3. Select “Wi-Fi” from the menu on the right hand side of the “Settings” window

  4. Scroll down to “Related settings” and select “Change adapter options

  5. Plug one end of an Ethernet cable into your laptop and the other end into the Windows 7 desktop which is hosting Ubuntu 16.04

    1. If you do not have an Ethernet port on your computer you will probably need to use an Ethernet to USB adapter to connect to your laptop.

    2. You probably have a choice whether you want to use another USB adapter to connect to the desktop or if you want to connect the Ethernet cable directly to the back of the desktop – the second half of these instructions only apply if you choose to use the adapter. If you choose to connect directly with the Ethernet you will have to do more work with the network adapter on the Desktop, and this documentation will not walk you through that.

  6. You should see a new connection pop up in the “Network Connections” window when you have plugged the Ethernet cable into both computers.

  7. Highlight your current Wi-Fi connection and the new Ethernet connection together

    1. The Wi-Fi connection should say “unl.edu” or the name of whatever Wi-Fi you are connected to.

    2. The Ethernet should say “Unidentified Network”

  8. Right click on the highlighted networks and select “Bridge Connections

  9. In theory you should now be bridging Wi-Fi to the Windows 7 computer, but normally I find you still have one more process to go through

  10. Unplug the Ethernet cable

    1. The Ethernet connection and bridged connection should disappear

  11. Right click on the Wi-Fi connection and select “Remove from Bridge

  12. Right click on the Wi-Fi connection again and select “Add to Bridge

  13. Now if you plug the Ethernet cable back into your laptop you should be bridging Wi-Fi to the desktop

  14. You should now have access to Internet on the Windows 7 host desktop

Setting Up Bridge on Ubuntu Side:

These instructions only apply if you are using a USB adapter to connect to the Windows 7 host.

  1. When you plug the USB adapter into the Windows 7 host you should notice a new USB icon show up on the bottom right hand side of your virtual machine. Click on this icon and make sure the USB is connected to your VM.

    1. If the USB is connected to your computer then when you right click on the icon you will have the option “Disconnect (Connect to Host)”

    2. If the USB is not connected to your computer you will have the option “Connect (Disconnect from Host)”. Select this option.

  2. Now in the top right hand of your VM click on the network icon. This will either look like the Wi-Fi icon or it will be two parallel arrows side by side.

  3. Select “Edit Connections

  4. Select “Add

  5. Make sure the drop-down menu says “Ethernet” and then select “Create

  6. Under “Device” in the resulting window select the device you just plugged in to your computer

    1. The device you just plugged in should be the only one that does not share a MAC address with one of the network adapters for your VM. To determine the MAC addresses of your VMs network adapters:

      1. In the upper right hand corner of your screen select “VM

      2. Select “Settings

      3. Select a network adapter from the menu on the left hand side of the window

      4. On the right hand side of the window select Advanced

      5. Note the MAC address at the bottom of the resulting window

      6. Repeat this process for each network adapters

  7. Once you have selected the correct device select “Save

  8. You should now be able to access the Internet from your virtual machine!

System requirements:

  • Ubuntu 16.04

  • ROS kinetic

Downloading Ubuntu 16.04 to VMware Workstation:

  1. Go to releases.ubuntu.com/16.04/ in your web browser.

  2. Select the 64-bit PC (AMD64) desktop image link on the website. An .iso file should begin downloading

  3. Make sure to note the file path of the .iso file

  4. Once the file has downloaded (which may take a while) open VMware and select the “Home” tab in the upper left hand corner.

  5. Now select the “Create a New Machine” option from the options in the middle of your screen.

  6. Follow the “New Virtual Machine Wizard” that pops up.

  7. On the second screen of the wizard select “Browse” and choose the .iso file you just downloaded.

    1. Tip: when you choose a user name and password for this virtual machine, unless you expect to store anything confidential, make the username and password as short as possible. You will need to use your password a lot so you do not want it to be long and you do not want to forget it – make it the same thing as your username.

  8. As you follow the wizard, when it asks you how many processor you want to give your virtual machine, select as many as is reasonable for your computer.

    1. If you are unsure what this number is Jean Paul or AJ might be good people to talk to.

    2. For the computer in room 218 select 8 processors.

  9. For selecting the optimum amount for RAM or memory talking to AJ or Jean Paul may be necessary.

    1. You will need 1.4 GB of ROM at a minimum to download everything necessary for flying the Crazyflie

    2. The desktop VM in room 218 has 16 GB allocated to the “CrazyflieDesktop” VM

    3. The desktop VM in room 218 also has 16 GB of RAM

  10. Once the wizard is finished you should be good to go.

  11. Go to “Home” again and select “Open a Virtual Machine”.

  12. Somewhere on your computer there should be a file with the name you gave your VM. Open that file and select the document of type .vmx. This should open your new VM.

Connecting Ubuntu 16.04 VMware Workstation to Vicon Network Adapter:

In order for your virtual machine to receive Vicon data it needs to join Vicon’s network. Vicon has a network adapter on the Windows 7 host. This is where the Vicon application sends all of the telemetry data it collects from objects in the room. You need to make a network adapter on your virtual machine in order to receive this information from Vicon. Finally, these two network adapters need a way to talk to one another in order that the VM can receive Vicon data from the host computer. This final piece is called a bridge. The network adapter on the Windows 7 end should already be set up on the host computer. However, you will need to set up the bridge and the Ubuntu network adapter yourself. The following steps describe how this is done.

Setting Up Ubuntu Network Adapter for Vicon

  1. Open your Ubuntu 16.04 workstation

  2. In the top left corner of your screen select “VM

  3. At the bottom of the drop-down menu select “settings

  4. Toward the bottom left of this window select “Add

    1. At this point you will probably need the administrative password to the Windows 7 host.

      1. The administrative password for the computer in room 218 is ‘Avery365bduncan’

      2. You may want to copy this password to you clipboard so that you can paste it instead of typing it as it is pretty long.

  5. Select “Network Adapter” from the list of options to the left of the window and click “next”.

  6. Select “Custom” and then choose an unused VMnet.

    1. You can tell whether or not a VMnet is used by looking at the “Device” menu under the “Hardware” tab of the “Virtual Machine Settings” window. If a VMnet is used it will be in parentheses after the name of one of the listed network adapters.

  7. Select “Finish”

Setting Up Bridge Between the Vicon Network Adapter and the Ubuntu Network Adapter

  1. Open your Ubuntu 16.04 workstation

  2. On the top left hand corner of your screen select “Edit

  3. Toward the bottom of the drop-down menu select “Virtual Network Editor

  4. Select “Change Settings” at the bottom right side of the window

    1. At this point you will probably need the administrative password to the Windows 7 host.

      1. Follow “a)” of step 4 of “Setting Up Ubuntu Network Adapter for Vicon”

  5. Select “Add Network” to the bottom right of the first list in the window.

  6. Now, using the drop-down menu in the “Add a Virtual Network” window choose the same VMnet you chose in step 6 of “Setting Up Ubuntu Network Adapter for Vicon”

  7. Select “OK

  8. Under the VMnet Information heading select “Bridged

  9. Now you have to use the drop-down menu after “Bridged to” order to select which Ethernet connection you want to connect to. In order to do this you will need to see which Ethernet connection the Vicon Network adapter is communicating with.

    1. Click on the Windows icon in the bottom left hand corner of your screen and type “Network and Sharing Center” in the search bar and hit ‘Enter

    2. In the top left hand side of the window that pops up select “Change adapter settings

    3. You should now see a list of all of the network adapters on the Windows 7 host machine. Hopefully one of these adapters is named “Vicon_LAN” or something similar which includes the name “Vicon”

      1. If not talk to AJ (thank you AJ)

    4. Underneath the network adapter you should see the network name and the name of the Ethernet connection that the adapter is using to communicate

    5. Note the connection that Vicon is using and then return to the “Virtual Network Editor” window and select the correct connection from the “Bridged to” drop-down menu.

  10. Click “Apply

  11. Click “OK

Accessing the Vicon Network from Inside the Ubuntu Virtual Machine

In order to use the network you just set up between Vicon and your Ubuntu VM you will have make a network connection from the inside of your Ubuntu VM. First you have to add the IP address of your Vicon network adapter to the “hosts” document on your VM. Then you will make a network connection which will allow you to use access Vicon data from your VM.

  1. Open a terminal in you Ubuntu VM (ctrl+alt+t)

  2. type: ‘cd ../..

  3. type: ‘sudo gedit etc/hosts

  4. In the top of the document paste type: “[Vicon Network Adapter IP Address] vicon”

    1. In order to determine the Vicon network IP address first follow steps 9 a) – c) of “Setting Up Bridge Between the Vicon Network Adapter and the Ubuntu Network Adapter”

    2. Double click on the Vicon network adapter

    3. Select “Details

    4. Use the IPv4 address in the “hosts” document

  5. Select save and close the “hosts” document

  6. In the top right corner of your screen click on the network icon in your Ubuntu VM

    1. The icon will either be the Wi-Fi icon or two parallel arrows pointing in opposite directions

  7. At the bottom of the drop-down menu select “Edit Connections

  8. Now select “Add

  9. Choose “Ethernet” from the drop-down menu and the select “Create

  10. In this window there should be a “Device” heading with a drop-down menu which will show you all of the available Ethernet or ens connections

    1. To determine which connection to use click VM in the top right corner of your screen

    2. Select “Settings” at the bottom of the resulting drop-down menu.

    3. Click on the network adapter that is connected to Vicon

    4. Toward the bottom right hand side of the window select “Advanced”

    5. In the resulting window note the MAC address used by the network adapter

    6. Return to the connection editing window and select the Ethernet or ens connection with the same MAC address as the network adapter

  11. Make sure “MTU” is set to “automatic” and Wake on LAN to Default

  12. Go to the “IPv4 Settings

    1. Change the drop-down menu under “Method” to “Manual”

    2. Click “Add under the Addresses heading.

    3. Under the “Address” header make a new IP address for you computer. Check the doc entitled “Network Connections in Room 218” on the NIMBUS website to make sure you are not using an address that has already been used

      1. The first three sections of your address must match the first three sections of the Vicon network adapter address. (probably 192.168.1.[your ID])

    4. Under the “Netmask” header use 255.255.255.0. When you come back and look later the netmask may say 24. This is OK. Apparently 24 is the abbreviation for 255.255.255.0.

    5. The Gateway is the same as the IP address of the Vicon network adapter.

  13. Go to “IPv6 Settings

    1. Make sure that “Method” is set to “Link-Local-Only”

  14. Select “Save

  15. You Should now be able to access Vicon data on your Ubuntu 16.04 VM

Downloading ROS Kinetic onto Ubuntu 16.04:

ROS Kinetic can be downloaded by following the steps at wiki.ros.org/kinetic/Installation/Ubuntu. In step 1.4 enter the command for “Desktop-Full Install” into your terminal and then move on to step 1.5.

Patching Wholes in Crazyflie Documentation:

Communicating with Crazyradio

The Crazyflie documentors from USC ACT Lab mentioned in the introduction (http://crazyswarm.readthedocs.io/en/latest/index.html) seems to make the assumption that you have kept up with their previous work. Therefore they do not include the instructions for setting up your operating system to work with the Crazyradio. Before attempting to communicate with the Crazyflie via Crazyradio follow all of the instructions in section 3.1 and the first block of commands in section 3.2 of previous Crazyflie documentation act.usc.edu/publications/Hoenig_Springer_ROS2017.pdf. Note that the first block of commands in section 3.2 should say “python3-pyqt5” (not “python3-pyqt4”)

Troubles with Build

If the “./buildSumOnly.sh” command does not work do not worry. Keep following the instructions. The “python figure8_canned.py –sim will not work either. This is ok, keep moving.

Before running the “./build.sh” command you will need to use another command the documentation forgot to included. Run this command in the directory ~/crazyswarm:

‘git submodule update –init –recursive’

USC ACT Lab made the crazyswarm workspace out of a number of different trees. The initial git clone command does not grab all of the trees. Therefore we use the command above.

Now you can run the “./build.sh” command, but this also must be done in the parent “crazyswarm” directory.

Flashing New Firmware to Crazyradio

You will need to use the full file path as described in under the next heading.

Flashing New Firmware to Crazyflies

We have only used Option 2 Under “Crazyflie Preparation” in NIMBUS Lab. So if you decide to use Option 1, best of luck. Option 2 works well, but the filename needs to have the complete file path to the file you want to flash to the Crazyflie. In room 218, the file path for the nrf51 target is “/home/cf/crazyswarm/prebuilt/cf2_nrf.binand the file path for the stm32 target is “/home/cf/crazyswarm/prebuilt/cf2.bin”.

Problems with Tool Scan

The instructions say that the command “rosrun crazyflie_tools scan” will report the firmware version of the crazyflie. This may have been true when they first made the tool, but now reporting the firmware has been made into an option. The correct command to use is “rosrun crazyflie_tools scan -v”. The v stands for verbose.

Also, in order to locate a Crazyflie, the scan tool needs to know what address to search. If the tool is not finding a Crazyflie even though you know it is on, go to “~/crazyswarm/ros_ws/src/crazyflie_ros/crazyflie_tools/src/scan.cpp”. On line 12 make sure the address matches that of your Crazyflie (If you’re not sure what the address is, look under the heading Understanding Meaning of “id” Crazyflie.yaml files” two sections down).

Problems with yaml library

The first time you launch “hover_swarm.launch” it may be that you get an error complaining about yaml libraries. I am pretty sure the fix is download the correct yaml library:

‘pip install yaml3’

However I am not certain and have been unable to test to make sure that this is correct. Whether or not this is the exact right command I am certain that the problem has to do with missinig the correct yaml library. Use Google to look up problems with yaml libraries and how to download them.

Understanding Meaning of “id” Crazyflie.yaml files

“id” in the files “allCrazflies.yaml” and “crazyflieTypes.yaml” must be the same as the end of the corresponding Crazyflie’s address. For example, if my Crazyflie has the address “0xE7E7E7E701” then its id would be “01”. If its address is “0xE7E7E7E712”, then the “id” is 12.

Actually Operating the Crazyflies

  • Everything that follows assumes you are using “motionCapture” system (If you do not know what I am referring to, read under “Select Motion Capture System” in http://crazyswarm.readthedocs.io/en/latest/usage.html). The “libobjecttracker” works as well, but this requires that every Crazyflie shares the same marker configuration and that each Crazyflie starts from a home position each time you start the Crazyflie server (“hover_swarm.launch”)

  • When making a Crazyflie object in Vicon it is absolutely vital that you make the object centered in Vicon’s coordinate system and facing forward in the positive x direction.

  • In order to successfully kill “chooser.py”, after you hit ctrl+c you will need to pass your curser over the GUI.

Steps to getting Crazyflies in the air:

  1. Make sure the Crazyflies you plan to fly are selected by “chooser.py”.

  2. Make sure all of the Crazyflies are on and that they have been turned off and on since the last time they were connected to the Crazyflie server (the crazflie server is launched when you launch “hover_swarm.launch”).

  3. Make sure the Crazyradio has been unplugged and re-plugged before launching “hover_swarm.launch” (not exactly sure why you have to do this, it may have something to do with the fact that we are using a virtual machine – either way, this step is vital).

  4. launch “hover_swarm.launch” by typing “roslaunch crazyswarm hover_swarm.launch” in the consul.

  5. Now you can make the Crazyflies hover with the Xbox controller by plugging the Xbox USB dongle into the computer and then pressing the start button on the Xbox controller.

  6. Make the Crazyflies land by pressing the back button on the Xbox controller.

  7. You can write a python script to control the Crazyflies using the library discussed on the Python API section of the USC ACT Lab crazyswarm documentation.

  8. In order to run the python scripts make sure you have saved the script in “~/crazyswarm/ros_ws/src/crazyswarm/scripts”.

  9. Go to the library where you have saved the script and enter “python [name of script].py”.

  10. In order to kill a python script you may need to enter ctrl+z instead of ctrl+c.

  11. When you kill a python script the Crazyflies will stop and hover where they are. You will need to land them with the Xbox controller by pressing back.

  12. You can also stop anything the crazyflies are doing by pressing “X” on the Xbox controller. The Crazyflies will just fall out of the air.

Trouble Shooting

  • If you get a timeout error when launching “hover_swarm.launch” try check these six things

    1. Make sure that the VM is connected to the Vicon network (click on the network icon in the top right of your screen and make sure “Vicon” is connected”.

    2. Make sure Vicon is not paused.

    3. Make sure as many Crazyflies are on as selected in “chooser.py”.

    4. Make sure the all the Crazyflies have a blinking red light. If any one only has a solid blue light you will need to turn it off and turn it back on.

    5. Make sure you have removed and replaced the Crazyradio from the USB port since the last time you killed “hover_swarm.launch”.

    6. If you are still getting a timeout error, remove the Crazyradio, kill “hover_swarm.launch”, restart every Crazyflie, replace the radio, and relaunch “hover_swarm.launch”.

Leave a Comment