From ff2fcfe178c6f43ab45552abc9caaf79b06df56f Mon Sep 17 00:00:00 2001 From: "temkei.kem" <1041084556@qq.com> Date: Fri, 7 Jun 2024 18:16:28 +0900 Subject: [PATCH] fix: order rosbags by starting_time instead of file name. --- .../perception_replayer/perception_replayer_common.py | 8 ++++---- .../scripts/perception_replayer/utils.py | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/planning/planning_debug_tools/scripts/perception_replayer/perception_replayer_common.py b/planning/planning_debug_tools/scripts/perception_replayer/perception_replayer_common.py index 5f83b9502..2cf54a4f1 100644 --- a/planning/planning_debug_tools/scripts/perception_replayer/perception_replayer_common.py +++ b/planning/planning_debug_tools/scripts/perception_replayer/perception_replayer_common.py @@ -32,7 +32,7 @@ from rosbag2_py import StorageFilter from rosidl_runtime_py.utilities import get_message from sensor_msgs.msg import PointCloud2 -from utils import open_reader +from utils import open_reader,get_starting_time class PerceptionReplayerCommon(Node): @@ -82,9 +82,9 @@ def __init__(self, args, name): # load rosbag print("Stared loading rosbag") if os.path.isdir(args.bag): - for bag_file in sorted(os.listdir(args.bag)): - if bag_file.endswith(self.args.rosbag_format): - self.load_rosbag(args.bag + "/" + bag_file) + bags = [ os.path.join(args.bag, base_name) for base_name in os.listdir(args.bag) if base_name.endswith(args.rosbag_format) ] + for bag_file in sorted(bags, key=get_starting_time): + self.load_rosbag(bag_file) else: self.load_rosbag(args.bag) print("Ended loading rosbag") diff --git a/planning/planning_debug_tools/scripts/perception_replayer/utils.py b/planning/planning_debug_tools/scripts/perception_replayer/utils.py index 5ded8d2ea..48cc79e8f 100644 --- a/planning/planning_debug_tools/scripts/perception_replayer/utils.py +++ b/planning/planning_debug_tools/scripts/perception_replayer/utils.py @@ -25,6 +25,9 @@ from tf_transformations import euler_from_quaternion from tf_transformations import quaternion_from_euler +def get_starting_time(uri: str): + info = rosbag2_py.Info().read_metadata(uri, "sqlite3") + return info.starting_time def get_rosbag_options(path, serialization_format="cdr"): storage_options = rosbag2_py.StorageOptions(uri=path, storage_id="sqlite3")