Ask Your Question

cannot convert imu messages from bagfile to csv file

asked 2013-12-10 09:13:05 -0500

Dereck gravatar image

updated 2013-12-10 09:15:58 -0500

I'm trying to convert this bagfile to csv:

With this command:

rostopic echo -b imu.bag -p /android/imu

I get this error:

Traceback (most recent call last):
  File "/opt/ros/hydro/bin/rostopic", line 35, in <module>
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rostopic/", line 1666, in rostopicmain
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rostopic/", line 1026, in _rostopic_cmd_echo
    _rostopic_echo(topic, callback_echo, bag_file=options.bag)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rostopic/", line 671, in _rostopic_echo
    _rostopic_echo_bag(callback_echo, bag_file)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rostopic/", line 649, in _rostopic_echo_bag
    for t, msg, timestamp in b.read_messages():
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rosbag/", line 2062, in read_messages
    yield self.seek_and_read_message_data_record((entry.chunk_pos, entry.offset), raw)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rosbag/", line 2198, in seek_and_read_message_data_record
    msg_type = _get_message_type(connection_info)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/rosbag/", line 1309, in _get_message_type
    message_type = genpy.dynamic.generate_dynamic(info.datatype, info.msg_def)[info.datatype]
  File "/opt/ros/hydro/lib/python2.7/dist-packages/genpy/", line 151, in generate_dynamic
    for l in msg_generator(msg_context, spec, search_path):
  File "/opt/ros/hydro/lib/python2.7/dist-packages/genpy/", line 733, in msg_generator
    genmsg.msg_loader.load_depends(msg_context, spec, search_path)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/genmsg/", line 344, in load_depends
    return load_msg_depends(msg_context, spec, msg_search_path)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/genmsg/", line 313, in load_msg_depends
    depspec = load_msg_by_type(msg_context, resolved_type, search_path)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/genmsg/", line 119, in load_msg_by_type
    file_path = get_msg_file(package_name, base_type, search_path)
  File "/opt/ros/hydro/lib/python2.7/dist-packages/genmsg/", line 78, in get_msg_file
    % (base_type, package, search_path))
Cannot locate message [Header]: unknown package [std_msgs] on search path [{}]
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-12-15 10:32:59 -0500

Dereck gravatar image

The rosjava implementation used in the android sensors app is broken and is not properly embedding the message definitions in the message stream. rosbag then doesn't know how what a std_msgs message type is inside the bagfile. UGH!

My work around was to play the messages with 'rosbag play /android/imu' and then echo the messages to a text file with 'rostopic echo /android/imu > imu.txt'. rostopic doesn't use the message type information located withing the topic stream, but rather uses the compiled libraries, so this works.

Then I convert the text file to a csv file with this ugly shinanigans:


cp $1 a

tr -d "[a-z:_/ ,]" < a > b
sed 's/' b > a
tr  -s "\n" "," < a > b
sed 's/,---,/#/g' b > a
tr  "#" "\n" < a > b
sed 's/^,//g' b > a

cp a $2
rm a b

Save it as a script and run it with './script.bash imu.txt imu.csv' to convert imu.txt to a csv file.

edit flag offensive delete link more


I ran into this problem enough times to write a primitive script that attempts to embed the msg defs after the fact (by using some ugle rosbag internals). See rosbag_fixer.

Note: it uses the defs from the machine it's run on, so won't work always.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-13 09:02:01 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-12-10 09:13:05 -0500

Seen: 1,746 times

Last updated: Dec 15 '13