Thursday, December 6, 2012

Load strokelitude data from .bag file into Python

Here is a script I've been using to load the strokelitude data contained in a .bag file. It should be easy to convert it to load data from other ros topics.


import sys, os
import numpy as np
import roslib
roslib.load_manifest('rosbag')
import rosbag
def loadBag(inFileName):
"""
Script to import strokelitude bag file
usage: outDict = loadBag(inFileName)
PTW 02/04/12
"""
if inFileName[-4:] != '.bag':
inFileName = inFileName + '.bag'
bag = rosbag.Bag(inFileName)
timeSec = list()
leftWingRad = list()
rightWingRad = list()
for topic, msg, t in bag.read_messages():
if topic == '/strokelitude' or topic == 'strokelitude':
timeSec.append(msg.header.stamp.secs + msg.header.stamp.nsecs*float(1e-9))
leftWingRad.append(msg.left_wing_angle_radians)
rightWingRad.append(msg.right_wing_angle_radians)
timeSec = np.array(timeSec)
leftWingRad=np.array(leftWingRad)
rightWingRad = np.array(rightWingRad)
outDict = {'timeSec':timeSec, 'leftWingRad':leftWingRad, 'rightWingRad':rightWingRad}
return outDict
view raw loadBag.py hosted with ❤ by GitHub

No comments: