diff --git a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp index 53bf64b90d..e1ffb2a3ef 100644 --- a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp +++ b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp @@ -76,6 +76,10 @@ class ROSBAG2_CPP_PUBLIC SequentialReader void reset_filter() override; + /** + * seek(t) will cause subsequent reads to return messages that satisfy + * timestamp >= time t. + */ void seek(const rcutils_time_point_value_t & timestamp) override; /** diff --git a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp index c29a518c62..ba70aa40e2 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp @@ -150,14 +150,15 @@ bool SequentialReader::has_next() throw std::runtime_error("Bag is not open. Call open() before reading."); } +// Note: if files in the bag are not time +// normalized, it's possible to read messages that have a timestamp +// before the timestamp of the last read upon a file roll-over. std::shared_ptr SequentialReader::read_next() { if (storage_) { // performs rollover if necessary if (has_next()) { auto message = storage_->read_next(); - // update seek time - seek_time_ = message->time_stamp; return converter_ ? converter_->convert(message) : message; } throw std::runtime_error("Bag is at end. No next message.");