Skip to content

Commit

Permalink
Merge merge_bag tools (#745)
Browse files Browse the repository at this point in the history
* meging python and c++ tool - untested

* tested

* removed commented code

* using utilities instead of function

* running python3 + fixes

* fixing dependencies issues
  • Loading branch information
marinagmoreira authored Nov 6, 2023
1 parent fafa41e commit 589d392
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import os
import subprocess

import pandas as pd


# Forward errors so we can recover failures
# even when running commands through multiprocessing
Expand Down Expand Up @@ -68,6 +66,9 @@ def create_directory(directory=None):


def load_dataframe(files):
# Importing the module only within this function
import pandas as pd

dataframes = [pd.read_csv(file) for file in files]
dataframe = pd.concat(dataframes)
return dataframe
Expand Down
46 changes: 24 additions & 22 deletions tools/bag_processing/scripts/rosbag_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import os
import re
import string
import subprocess
import sys

import rosbag
import localization_common.utilities as lu


# https://stackoverflow.com/a/4836734
Expand Down Expand Up @@ -59,29 +60,31 @@ def merge_bag(input_bag_prefix, input_bag_suffix, merged_bag, only_loc_topics=Fa
merged_bag_name = input_bag_prefix + ".merged.bag"

sorted_bag_names = natural_sort(bag_names)
merge_bags_command = (
"rosrun localization_node merge_bags "
+ " ".join(sorted_bag_names)
+ " -output_bag "
+ str(merged_bag_name)
)

topics = None
if only_loc_topics:
topics = [
"/hw/imu",
"/loc/of/features",
"/loc/ml/features",
"/loc/ar/features",
"/mgt/img_sampler/nav_cam/image_record",
"/graph_loc/state",
"/gnc/ekf",
"/sparse_mapping/pose",
"/mob/flight_mode",
"/beh/inspection/feedback",
"/beh/inspection/goal",
"/beh/inspection/result",
]
merge_bags_command += (
" -save_topics"
+ " '/hw/imu"
+ " /loc/of/features"
+ " /loc/ml/features"
+ " /loc/ar/features"
+ " /mgt/img_sampler/nav_cam/image_record"
+ " /graph_loc/state"
+ " /gnc/ekf"
+ " /sparse_mapping/pose"
+ " /mob/flight_mode"
+ " /beh/inspection/feedback"
+ " /beh/inspection/goal"
+ " /beh/inspection/result'"
)

with rosbag.Bag(merged_bag_name, "w") as merged_bag:
for sorted_bag_name in sorted_bag_names:
with rosbag.Bag(sorted_bag_name, "r") as sorted_bag:
for topic, msg, t in sorted_bag.read_messages(topics):
merged_bag.write(topic, msg, t)
lu.run_command_and_save_output(merge_bags_command)


if __name__ == "__main__":
Expand Down Expand Up @@ -136,7 +139,6 @@ def merge_bag(input_bag_prefix, input_bag_suffix, merged_bag, only_loc_topics=Fa

print(bag_names)
for bag_name in bag_names:
print(bag_name)
merge_bag(
bag_name, args.input_bag_suffix, args.merged_bag, args.only_loc_topics
)

0 comments on commit 589d392

Please sign in to comment.