Tuesday, July 28, 2015

Installation notes for Kinefly

Today I'm going to set up a computer to track average wing stroke envelopes of flies. This is useful because asymmetries in wing stroke amplitude indicate attempted turns by tethered flies, so measuring them gives us a quantitative metric of flight behavior. I'm going to be installing Steve Safarik's Kinefly, which is a ROS-based replacement for Andrew Straw's Strokelitude, both of which were developed in the Dickinson Lab. (Strokelitude is rapidly becoming obsolete.) Here is a screenshot of what Kinefly looks like:
Screenshot of wing amplitude tracking using Kinefly

I'll mostly follow Steve's instructions here, but make notes of any differences. To start off with, I installed 64-bit Ubuntu 14.04 LTS on a new hard drive.

Departing from Steve's instructions, I'll first install ROS Indigo, which is a newer version of ROS and will hopefully be supported for longer. I'll follow the directions here.

I'll be using a firewire (IEEE1394) camera in my rig, not a gigE (Ethernet) camera, so I'll skip the Camera Aravis installation (lines 29-35 of Steve's installation instructions). I also skipped lines 50-53. Instead I installed the ROS drivers for 1394 cameras:

cd catkin/src/
git clone https://github.com/ros-drivers/camera1394.git
cd ~/catkin

Now I'm going to download and install coriander to test that the camera is working:

sudo apt-get install coriander
Then I plugged the camera into the computer and ran
Under the Services tab, click Display and you should see a live image from the camera.

In line 90, I copied the 'polarization' rig instead of 'thadsrig' because that rig used a 1394 camera:
cp -R polarization yourrigname

We are almost done! Now just three lines of code that need to be changed because ROS indigo uses opencv2 instead of an earlier version (I think):

gedit ~/src.git/Kinefly/nodes/kinefly.py
and edit line 240 to be:
rosimg = self.cvbridge.cv2_to_imgmsg(imgInitial, 'passthrough') # used to be img = np.uint8(cv.GetMat(self.cvbridge.imgmsg_to_cv(rosimg, 'passthrough')))
line 619 to be
img = np.array(self.cvbridge.imgmsg_to_cv2(rosimg, 'passthrough')) # used to be img = np.uint8(cv.GetMat(self.cvbridge.imgmsg_to_cv(rosimg, 'passthrough')))
and line 769 to be
rosimgOutput = self.cvbridge.cv2_to_imgmsg(imgOutput, 'passthrough') # used to be rosimgOutput = self.cvbridge.cv_to_imgmsg(cv.fromarray(imgOutput), 'passthrough')

If you want to test Kinefly without the LED panels attached, you can edit the _main.launch file: 
gedit ~/src.git/Kinefly/launch/yourrigname/_main.launch 
Comment out the following three lines:
<include file= "$(find Kinefly)/launch/$(env RIG)/params_ledpanels.launch" ns="kinefly" />
<node name="ledpanels" pkg="ledpanels" type="ledpanels.py" />
<node name="flystate2ledpanels" pkg="Kinefly" type="flystate2ledpanels.py" ns="kinefly"  />
by inserting   <!-- before each and --> after each. Now test Kinefly by running this command:
roslaunch Kinefly main.launch
Don't forget to click the 'exit' button to close Kinefly--the red x doesn't work!