Robotics StackExchange | Archived questions

Why is Python rosbag crashing?

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()

Asked by VictorLamoine on 2016-01-24 13:15:22 UTC

Comments

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

Asked by gvdhoorn on 2017-02-02 08:06:46 UTC

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

Asked by VictorLamoine on 2017-02-03 03:25:56 UTC

Answers