You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, when I try to use rosbag to read the messages, I get the error:
Traceback (most recent call last):
File "IMU_pose.py", line 70, in <module>
main(args["input_bag"], args["topic"], args["output"])
File "IMU_pose.py", line 40, in main
for topic, msg, timestamp in tqdm(input_bag.read_messages(topics=topic_specified)):
File "/home/uma/.local/lib/python3.8/site-packages/tqdm/std.py", line 1193, in __iter__
for obj in iterable:
File "/opt/ros/noetic/lib/python3/dist-packages/rosbag/bag.py", line 2700, in read_messages
yield self.seek_and_read_message_data_record((entry.chunk_pos, entry.offset), raw, return_connection_header)
File "/opt/ros/noetic/lib/python3/dist-packages/rosbag/bag.py", line 2824, in seek_and_read_message_data_record
self.bag._file.seek(chunk_header.data_pos)
AttributeError: 'NoneType' object has no attribute 'seek'
This error occurs when trying to read the message with field.header.seq = 32737, but when I inspect the bag, this message is valid:
@EricWiener
It's not rosbag's problem.It's a logic bug.
Why do you generate a file for every message
After yield, you call input_bag.close(). I think you should put close() outside the for loop.
# ============ Loop through ROS bag ===========
for topic, msg, timestamp in tqdm(input_bag.read_messages(topics=topic_specified)):
print(msg.header.seq)
json_str = json_message_converter.convert_ros_message_to_json(msg)
# Save
# Why do you generate a file for every message
file_name = str(timestamp)
file_path = os.path.join(output_directory, file_name + ".json")
with open(file_path, "w") as outfile:
json.dump(json_str, outfile)
# After yield, you call input_bag.close(). I think you should put close() outside the for loop
input_bag.close()
I made a little change
# ============ Loop through ROS bag ===========
for topic, msg, timestamp in tqdm(input_bag.read_messages(topics=topic_specified)):
print(msg.header.seq)
json_str = json_message_converter.convert_ros_message_to_json(msg)
# Save
# Why do you generate a file for every message
file_name = str(timestamp)
file_path = os.path.join(output_directory, file_name + ".json")
with open(file_path, "w") as outfile:
json.dump(json_str, outfile)
# After yield, you call input_bag.close(). I think you should put close() outside the for loop
input_bag.close()
Hi,
I'm trying to loop through all the messages in a bag and save them to JSON. The bag appears to be correctly formatted because I can do both:
and get valid results.
However, when I try to use
rosbag
to read the messages, I get the error:This error occurs when trying to read the message with field.header.seq = 32737, but when I inspect the bag, this message is valid:
I am attaching both the script I am using as well as the ROS bag file. Additionally, I am use ROS Noetic, Python 3.8.5, and rosbag==1.15.9.
Thank you!
code_imu_bag.zip
The text was updated successfully, but these errors were encountered: