Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef CARTOGRAPHER_ROS_CARTOGRAPHER_ROS_PLAYABLE_BAG_H
00018 #define CARTOGRAPHER_ROS_CARTOGRAPHER_ROS_PLAYABLE_BAG_H
00019 #include <cartographer_ros_msgs/BagfileProgress.h>
00020 #include <ros/node_handle.h>
00021
00022 #include <functional>
00023 #include <queue>
00024
00025 #include "rosbag/bag.h"
00026 #include "rosbag/view.h"
00027 #include "tf2_ros/buffer.h"
00028
00029 namespace cartographer_ros {
00030
00031 class PlayableBag {
00032 public:
00033
00034
00035 using FilteringEarlyMessageHandler =
00036 std::function<bool (
00037 const rosbag::MessageInstance&)>;
00038
00039 PlayableBag(const std::string& bag_filename, int bag_id, ros::Time start_time,
00040 ros::Time end_time, ros::Duration buffer_delay,
00041 FilteringEarlyMessageHandler filtering_early_message_handler);
00042
00043 ros::Time PeekMessageTime() const;
00044 rosbag::MessageInstance GetNextMessage(
00045 cartographer_ros_msgs::BagfileProgress* progress);
00046 bool IsMessageAvailable() const;
00047 std::tuple<ros::Time, ros::Time> GetBeginEndTime() const;
00048
00049 int bag_id() const;
00050 std::set<std::string> topics() const { return topics_; }
00051 double duration_in_seconds() const { return duration_in_seconds_; }
00052 bool finished() const { return finished_; }
00053
00054 private:
00055 void AdvanceOneMessage();
00056 void AdvanceUntilMessageAvailable();
00057
00058 std::unique_ptr<rosbag::Bag> bag_;
00059 std::unique_ptr<rosbag::View> view_;
00060 rosbag::View::const_iterator view_iterator_;
00061 bool finished_;
00062 const int bag_id_;
00063 const std::string bag_filename_;
00064 const double duration_in_seconds_;
00065 int message_counter_;
00066 std::deque<rosbag::MessageInstance> buffered_messages_;
00067 const ::ros::Duration buffer_delay_;
00068 FilteringEarlyMessageHandler filtering_early_message_handler_;
00069 std::set<std::string> topics_;
00070 };
00071
00072 class PlayableBagMultiplexer {
00073 public:
00074 PlayableBagMultiplexer();
00075 void AddPlayableBag(PlayableBag playable_bag);
00076
00077
00078
00079
00080 std::tuple<rosbag::MessageInstance, int ,
00081 bool >
00082 GetNextMessage();
00083
00084 bool IsMessageAvailable() const;
00085 ros::Time PeekMessageTime() const;
00086
00087 std::set<std::string> topics() const { return topics_; }
00088
00089 private:
00090 struct BagMessageItem {
00091 ros::Time message_timestamp;
00092 int bag_index;
00093 struct TimestampIsGreater {
00094 bool operator()(const BagMessageItem& l, const BagMessageItem& r) {
00095 return l.message_timestamp > r.message_timestamp;
00096 }
00097 };
00098 };
00099
00100 ros::NodeHandle pnh_;
00101
00102 ros::Publisher bag_progress_pub_;
00103
00104 std::map<int, ros::Time> bag_progress_time_map_;
00105
00106 double progress_pub_interval_;
00107
00108 std::vector<PlayableBag> playable_bags_;
00109 std::priority_queue<BagMessageItem, std::vector<BagMessageItem>,
00110 BagMessageItem::TimestampIsGreater>
00111 next_message_queue_;
00112 std::set<std::string> topics_;
00113 };
00114
00115 }
00116
00117 #endif // CARTOGRAPHER_ROS_CARTOGRAPHER_ROS_PLAYABLE_BAG_H