Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduces ram usage by individual processing #4

Merged
merged 1 commit into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ros2bag_convert/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .ros2bag_convert import read_bag,save_csv_file
import sys
from .ros2bag_convert import read_bag
import sys, os

argvs = sys.argv
argc = len(argvs)
Expand All @@ -11,10 +11,7 @@ def main():
print('Usage: #ros2bag-convert xxx.db3')
quit()
file_url = argvs[1]
data = read_bag.read_from_all_topics(file_url,True)
for i in range(len(data)):
topic_name,topic_type = data[i][0],data[i][1]
save_csv_file.save_csv_file(data[i][2:],file_url[:file_url.rfind("/")]+""+topic_name+".csv")
read_bag.read_write_from_all_topics(file_url,True)

if __name__ == '__main__':
main()
Expand Down
8 changes: 7 additions & 1 deletion ros2bag_convert/ros2bag_convert/message_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,14 @@ def _convert_from_ros_type(field_type, field_value):
field_value = list(field_value)
elif _is_field_type_an_array(field_type):
field_value = _convert_from_ros_array(field_type, field_value)
elif field_type == np.ndarray or type(field_value) == np.ndarray:
print("Unsupported type: ", field_type)
return None
else:
field_value = convert_ros_message_to_dictionary(field_value)
try:
field_value = convert_ros_message_to_dictionary(field_value)
except:
print("field_type: ", field_type)

return field_value

Expand Down
31 changes: 30 additions & 1 deletion ros2bag_convert/ros2bag_convert/read_bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from rclpy.serialization import deserialize_message
# import sys
# sys.path.append("/home/ros2/rosbag2_csv/rosbag2/")
from . import message_converter
from . import message_converter, save_csv_file
import json
import os

def connect(sqlite_file):
""" Make connection to an SQLite database file. """
Expand Down Expand Up @@ -214,3 +215,31 @@ def read_from_all_topics(bag_file, print_out=False):
close(connection)

return data

def read_write_from_all_topics(bag_file, print_out=False):
""" Returns all timestamps and messages from all topics.
"""
# Connect to the database
connection, cursor = connect(bag_file)

# Get all topics names and types
topic_names = get_all_topics_names(cursor, print_out=False)
print(topic_names)
topic_types = get_all_msgs_types(cursor, print_out=False)

# Get all messages types
topic_types = get_all_msgs_types(cursor, print_out=False)

# Get all timestamps and messages for each topic
for i in range(len(topic_names)):
timestamps, messages = read_from_topic(bag_file, topic_names[i], print_out)
topic_name,topic_type = topic_names[i],topic_types[i]
tmp = topic_name.split("/")
path, topic_name = "/".join(tmp[:-1]),tmp[-1]
path = bag_file[:bag_file.rfind("/")]+""+path
os.makedirs(path, exist_ok=True)
save_csv_file.save_csv_file([timestamps, messages],path + "/" + topic_name+".csv")

# Close connection to the database
close(connection)