Skip to content

Commit

Permalink
fix: order rosbags by starting_time instead of file name.
Browse files Browse the repository at this point in the history
Signed-off-by: temkei.kem <[email protected]>
  • Loading branch information
xtk8532704 committed Jun 10, 2024
1 parent 5a14882 commit d1ac6b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d1ac6b3

Please sign in to comment.