Closed EricWiener closed 3 years ago
@EricWiener It's not rosbag's problem.It's a logic bug.
# ============ 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()
And then there were more than 3000 files.
@jinmenglei thanks so much! So sorry for not seeing that issue. I really appreciate your help
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