Categories
Procedures *

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”.

Categories
Educational Material * Procedures *

Spawn getty over serial: systemd

The switch to systemd from init has been wonderful in the world of *nix. Here’s how you could quickly get a getty running on a serial ttyUSB device in the old system:

  • Create a ttyUSB0.conf file inside /etc/init/ and fill it with start on stopped and RUNLEVEL information, followed by an exec statement, that reads something like: /sbin/getty -L 9600 ttyUSB0 vt102. (see addendum)
  • Tell init to pick it up, by adding to /etc/rc.local the line sudo start ttyUSB0.

(Warning: this is the way I do it, which naturally means there’s something ugly about it!).

Here’s how you’d do this through systemd:

  • Modify the system-file in /lib/systemd/system/serial-getty@.service to change the baud-rate to what you need (technically you shouldn’t do this, but we need to get moving quick).
    The line: ExecStart:-/sbin/agetty 9600 %I $TERM instead of --keep-baud. This will tell it to use a specific baudrate as opposed to scanning through a list.
  • The systemctl daemon needs to know that you meddled with the file (which you shouldn’t have, you know.. but we did anyway, spilt milk). Do:
    sudo systemctl daemon-reload
  • Fun part: just enable this setup once, and systemd will remember over reboots:
    sudo systemctl enable serial-getty@ttyUSB0Of course you can disable, start or stop this. Apparently it is not smart enough to ignore you when you start it twice. The way it enables is by creating a symlink from /etc/systemd/system/getty.target.wants/serial-getty@ttyUSB0.service to /lib/systemd/system/serial-getty@.service, in case the command doesn’t work (note that the latter is the file you edited previously). Feel free to explain this to me after reading more on this RHEL KB. :)

Addendum:

My old setup (using init) had this inside the ttyUSB0.conf file:
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
exec /sbin/getty -L 9600 ttyUSB0 vt102


Ooh, how do you know if you’re using systemd or init? If you’re system is up, then PID 1 should tell you :)
(ps -p1).

Categories
Educational Material * Procedures *

Beginning C++ GUI Development in ROS

Disclaimer:  Part 1 – This tutorial is designed to get you started with developing a GUI for your ROS project using C++ and Qt.  If you’d like to use Python, you should check out the official ROS tutorial here.  Also, the assumption is that you have a basic understanding of creating/building a ROS application in C++ (to include editing the CMakeLists.txt and package.xml files) and know how pull a package from the Nimbus SVN.

Part 2 – This is not the only way to develop a Qt GUI in ROS.  It is a very iterative approach that should help you understand how ROS uses rqt plugins, at least at a basic level. Also, it allows you to make sure that you’ve got working code at certain points before moving on to the next phase of development.

Part 3 – This is not a tutorial on the ins and outs of Qt Creator, but it should at least get you to the point where you can get the IDE up and running.

Part 4 – The below has been tested with both Ubuntu 14/ROS Indigo and Ubuntu 16/ROS Kinetic.

==============================

There are two ways to configure your project.  You can use the “manual” method, or you can use the “automatic” method provided by way of the create_gui.py script included in the ros_gui_template project located in the Nimbus SVN.  Both methods are described below.

 

Manual Method
============

Step 1: Get the ros_gui_template package from the Nimbus SVN.  It’s located in  var/www/svn/UAV/ros-workspaces/ros_gui_template.  You can check it out directly into whatever project you’re working on, or you can put it in it’s own ROS workspace for later use.  Remember, the files in the ros_gui_template project must be somewhere under the src directory of your catkin workspace – either directly or within a subdirectory.

Step 2: Put the ros_gui_template folder in the src folder of whatever package you want to add a gui to.  For instance, you could put it inside of ~/nimbus_asctec/src/nimbus_asctec/

Step 3: Now go back to ~/nimbus_asctec (or whatever your root catkin workspace is) and run catkin_make.  If you’ve already built you project once, then you’ll probably just see it build the ros_gui_template.  Once that’s done, you should be able to run the following:
roslaunch ros_gui_template ros_gui_template.launch

You should eventually see the following:

If you do, then success!  Now the fun begins.

Step 4: Obviously, you want your code in there with your file names and so on.  That means you’ll need to make some changes to the files in your project.  Basically, you’re going to replace any instances of “ros_gui_template” and “RosGuiTemplate” with your own project name.  For tutorial purposes, we’ll use “your_project” and “YourProject.”

Start with the folder that you just placed inside you project.  Rename it to “your_project.”  Now go into the base directory of “your_project” (where you see CMakeLists.txt, package.xml, plugin.xml, and so on) and make the the following changes to the following files:

CMakeLists.txt
===============
-Find and replace all instances of “ros_gui_template” with “your_project”

package.xml
===========
-Find and replace all instances of “ros_gui_template” with “your_project”
-Change the other tags as/if required.  Remember, ROS stuff will probably
change here as your project progresses.

plugin.xml
==========
-Change path=”lib/libros_gui_template” to path=”lib/libyour_project”
-Change class name=”ros_gui_template/RosGuiTemplate” to class name=”your_project/YourProject”
-Change type=”ros_gui_template::RosGuiTemplate” to type=”your_project::YourProject”
-Change the other stuff as/if needed

Rename ros_gui_template.launch to whatever-you-want.launch

whatever-you-want.launch
=======================
-Find and replace all instances of “ros_gui_template” with “your_project”

In the include folder, rename “ros_gui_template.h” to “your_project.h”

your_project.h
==============
-Change the #ifndef and #define lines as you see fit
-Find and replace all instances of “ros_gui_template” with “your_project”
-Find and replace all instances of “RosGuiTemplate” with “YourProject”

In the src folder, rename “ros_gui_template.cpp” to “your_project.cpp”

your_project.cpp
================
-Find and replace all instances of “ros_gui_template” with “your_project”
-Find and replace all instances of “RosGuiTemplate” with “YourProject”

In the resource folder, rename “ros_gui_template.ui” to “your_project.ui”

your_project.ui
===============
-Find and replace all instances of “RosGuiTemplate” with “YourProject”

In the scripts folder, rename “ros_gui_template.py” to “your_project.py”
(make sure this file stays executable)

your_project.py
===============
-Find and replace all instances of “ros_gui_template” with “your_project”

Step 5: ROS has a tendency to cache certain things, and sometimes this can pose a problem, especially after you change file/folder names within a project.  In order to ensure you’ll be able to run your new GUI, you’ll have to clear your rqt_gui cache with the following command: rm ~/.config/ros.org/rqt_gui.ini

Step 6: Now go back to the root of your workspace and run catkin_make.  Hopefully, everything will build and you’ll be able to test your project with
roslaunch your_project whatever-you-want.launch

At this point you should see the exact same window as before.

Step 7: After you get that working, you’ll be ready to use Qt Creator to get in there and edit your UI and whatever else you need to do.  If you don’t have Qt Creator, you can get it with sudo apt-get install qtcreator Remember, you need to source your devel/setup.bash and THEN launch qtcreator from that same command line!  From there, you open a project and choose the CMakeLists.txt file in your_project’s directory (where package.xml is and so on).  You will be then asked to configure your project by picking a default build directory.  You can safely accept the default presented as you will not be using Qt Creator to build your project – see the warning below.

WARNING

***************************************

Qt Creator is an excellent IDE that you can use to edit your ROS C++ code as well as graphically create/edit your user interface; HOWEVER, it uses the QMake utility to build and manage its projects.  QMake does not play well with ROS and catkin_make.  Therefore, DO NOT USE Qt Creator’s “build” button on your project.  ALWAYS use catkin_make from the command line!

***************************************

Step 8: If you’re not a Qt expert, there are plenty of awesome tutorials on youtube that will take you through the basics of creating buttons, assigning functions to those buttons and so on.  It’s a fairly simply process, but it’s not quite as easy as Visual Studio development.  VoidRealms has an excellent set of 107 videos on YouTube that can help you gain some understanding of Qt and Qt programming.  Be advised, it’s only about Qt and C++ – you’ll have to bring your own understanding of ROS to bear as needed.

Automatic Method
===============

Step 1: Get the ros_gui_template package from the Nimbus SVN.  It’s located in  var/www/svn/UAV/ros-workspaces/ros_gui_template.  You can check it out directly into whatever project you’re working on, or you can put it in it’s own ROS workspace for later use.  Remember, the files in the ros_gui_template project must be somewhere under the src directory of your catkin workspace – either directly or within a subdirectory.

Step 2: Navigate to the directory where you placed the ros_gui_template files.  You should see CMakeLists.txt, package.xml, create_gui.py, and others.

Step 3: Run the create_gui.py script with two arguments.  The first argument is the name of your package, and the second is the name of the class that defines your gui.  Typically, these are an underscored version and a CamelCased version of the same word as specified in the ROS C++ Style Guide.  See the below example.

./create_gui.py your_project YourProject

You’ll see some output as the script goes through all the files that were downloaded with the ros_gui_template and makes all the needed changes as described in the “manual” section of this tutorial.

The final thing the script does is to remove the SVN info from the downloaded files so that you won’t inadvertently change the repository master.

Step 4: Now go back to the root of your workspace and run catkin_make.  Hopefully, everything will build and you’ll be able to test your project with
roslaunch your_project your_project.launch

At this point you should see a gui that looks like the one shown in Step 3 of the “manual” section of this tutorial.

Step 5: After you get that working, you’ll be ready to use Qt Creator to get in there and edit your UI and whatever else you need to do.  If you don’t have Qt Creator, you can get it with sudo apt-get install qtcreator Remember, you need to source your devel/setup.bash and THEN launch qtcreator from that same command line!  From there, you open a project and choose the CMakeLists.txt file in your_project’s directory (where package.xml is and so on).  You will be then asked to configure your project by picking a default build directory.  You can safely accept the default presented as you will not be using Qt Creator to build your project – see the warning below.

WARNING

***************************************

Qt Creator is an excellent IDE that you can use to edit your ROS C++ code as well as graphically create/edit your user interface; HOWEVER, it uses the QMake utility to build and manage its projects.  QMake does not play well with ROS and catkin_make.  Therefore, DO NOT USE Qt Creator’s “build” button on your project.  ALWAYS use catkin_make from the command line!

***************************************

Step 6: If you’re not a Qt expert, there are plenty of awesome tutorials on youtube that will take you through the basics of creating buttons, assigning functions to those buttons and so on.  It’s a fairly simply process, but it’s not quite as easy as Visual Studio development.  VoidRealms has an excellent set of 107 videos on YouTube that can help you gain some understanding of Qt and Qt programming.  Be advised, it’s only about Qt and C++ – you’ll have to bring your own understanding of ROS to bear as needed.

If you have comments or questions, don’t hesitate to let me know.

–Adam

Categories
Equipment * Misc * Procedures * Projects * Uncategorized

Using rosbag_pandas to Analyze rosbag Files with Python

ROS offers great tools to record execution traces using the rosbag command line tool. However, after the data is recorded, quickly extracting the data to perform analysis and produce graphics may be an issue to those unfamiliar with the process.  ROS provides a Python and C++ API to read and write data from the bags (http://wiki.ros.org/rosbag/Code%20API), but the data returned by the examples in the API are not in a format that is easy to quickly analyze.

Often when working in the Nimbus lab, we want to quickly view a graph of data from a bag.  We also run more complex analysis on files that require timestamped information from multiple topics.  This analysis is done in Python, Matlab, and a myriad of other languages and tools.  This makes getting the data from the bag file extremely important.   Pandas (http://pandas.pydata.org/) is  a wonderful Python library that provides data structures and tools for data,  processing, preparation, and analysis. Also since pandas has methods  to plot and export its data structures, getting the bag information into pandas will make plotting and exporting trivial.  Rosbag_pandas (https://github.com/aktaylor08/RosbagPandas) is  a python package that allows users to import data recorded from a rosbag into a pandas Dataframe that is indexed by the time the message was recorded.

Installation

To use rosbag_pandas you must first install numpy, pandas, and of course ROS.  After the dependencies are installed you can install rosbag_pandas on your system using your favorite method(e.g. pip install rosbag_pandas, easy_install, or running the setup.py script).  After installing the package, three tools will be available: rosbag_pandas, bag_to_csv.py, and bag_graph.py.

 

bag2csv.py

 

Bag to csv is a python script that can be used to extract data from a bag file and place it in a .csv file.   The script has a number of parameters that can be used to change what is included in the file.    The include and exclude arguments can be used to only store data from certain topics.  By default all topics are included and no topics are excluded.  The program will select the topics by first identifying all of the include topics and then removing the excluded topics from the set.  These arguments can be regular expressions or a list of topic name strings.  The script can also fill missing values using the –fill flag.  This will forward and backward fill data points so that there is no missing values in the any row in the csv file.   Finally, by default the script ignores the header fields in a message. This behavior can be turned off by passing the  –include-header flag to the script.

bag_graph.py

 

bag_graph.py is a tool that allows the quick graphing of fields on a ros topic.  It has two required arguments “-b –bag” and “-s –series.”  The bag is the bag file to use and the series argument is the data fields in the bag to graph.   As a quick example if we want a graph of the height of a UAV we can issue the command: `bag_graph.py -b bag.bag -s /a/subject_pose/translation/z` and get the following result.

graph1

Additionally, the script can handle graphing more than one topic and field at a time.  The image below was creating by running the script with the arguments:  `bag_graph.py -b bag.bag -s /a/subject_pose/translation/z /a/subject_pose/translation.x`

double
The graphs of multiple series can also be placed on a single axis by including the `-c` flag:  `bag_graph.py -b bag.bag -s /a/subject_pose/translation/z  /a/subject_pose/translation.x -c`

combined

 

Getting a Dataframe

The final usage of the package using it to get a pandas Dataframe object populated with data from the  bag file.  This is done by importing rosbag_pandas and calling the method bag_to_dataframe.  This method takes as arguments the file and topics to include and exclude in the returned Dataframe. In the frame, there is a column for each field in the messages on the topics parsed from the bag. Each time a message is received in the bag file,  a row is added to the dataframe that contains values for that topic, but NaN values for the rest of the columns.  This opens the data in a bag file up to all of the tools that are available in pandas and other python libraries. For example rosbag_pandas lets us print the min, and max values on each of the topic’s fields with 4 lines of code:

import rosbag_pandas

df = rosbag_pandas.bag_to_dataframe(‘bag.bag’)

for c in df.columns:

print c, df[c].min(),  df[c].max()

This barely scratches the surface of what can be done with a Dataframe full of data from ROS. Hopefully it gives you an idea of what can be done and how to install and use this simple package.