Why is Python rosbag crashing? [closed]

asked 2016-01-24 12:15:22 -0500

VictorLamoine gravatar image

updated 2017-02-02 04:19:49 -0500

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 <module>
    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()
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by VictorLamoine
close date 2016-02-16 11:35:04.740544

Comments

So it's no longer crashing for you, or you're no longer interested in solving this?

gvdhoorn gravatar image gvdhoorn  ( 2017-02-02 07:06:46 -0500 )edit

I've tested and the script works fine on Ubuntu 16.04, ROS Kinetic, Python 2.7.12. I don't remember closing this!

VictorLamoine gravatar image VictorLamoine  ( 2017-02-03 02:25:56 -0500 )edit