I'm trying to read a ROS bag file to convert it's values.
I'm using the rosbag Python API.
I don't understand why the reading crashes at the end:
-0.262920607691 0.447809595374 -0.39638550589 -3.14159265357 0.726601225435 -2.87867204592
-0.265034838048 0.436386356356 -0.412905936714 -3.14159265357 0.721504033644 -2.87655781556
Traceback (most recent call last):
File "rosbag_read_write.py", line 20, in
for topic, msg, t in bag.read_messages(topics=['/joint_states']):
File "/opt/ros/indigo/lib/python2.7/dist-packages/rosbag/bag.py", line 2329, in read_messages
yield self.seek_and_read_message_data_record((entry.chunk_pos, entry.offset), raw)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rosbag/bag.py", line 2459, in seek_and_read_message_data_record
raise ROSBagFormatException('Expecting OP_MSG_DATA, got %d' % op)
rosbag.bag.ROSBagFormatException: Expecting OP_MSG_DATA, got 6
Here is my script:
import sys
import rosbag
from ttk import *
from Tkinter import Tk
from tkFileDialog import askopenfilename
from tkFileDialog import asksaveasfile
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename(filetypes = ( ("ROS bag", "*.bag"),("All files", "*.*") ) )
print(filename)
bag = rosbag.Bag(filename)
topics = bag.get_type_and_topic_info()[1].keys()
types = []
for i in range(0,len(bag.get_type_and_topic_info()[1].values())):
types.append(bag.get_type_and_topic_info()[1].values()[i][0])
print types
for topic, msg, t in bag.read_messages(topics=['/joint_states']):
print msg.position[0], msg.position[1], msg.position[2], msg.position[3], msg.position[4], msg.position[5]
bag.close()
The bag file is [available here]( https://mega.nz/#!lEVjnAKZ!MBRLR6l32m4t6HUgUinUD9u2yfdh9X0hn3pNog8u1SY).
↧