bag_player.cpp
Go to the documentation of this file.
1 #include "rosbag/bag_player.h"
2 
3 #define foreach BOOST_FOREACH
4 
5 namespace rosbag
6 {
7 
8 BagPlayer::BagPlayer(const std::string &fname) {
11  View v(bag);
13  bag_end_ = v.getEndTime();
15  playback_speed_ = 1.0;
16 }
17 
19  bag.close();
20 }
21 
23  return last_message_time_;
24 }
25 
26 void BagPlayer::set_start(const ros::Time &start) {
27  bag_start_ = start;
28 }
29 
30 void BagPlayer::set_end(const ros::Time &end) {
31  bag_end_ = end;
32 }
33 
34 void BagPlayer::set_playback_speed(double scale) {
35  if (scale > 0.0)
36  playback_speed_ = scale;
37 }
38 
40  return play_start_ + (msg_time - bag_start_) * (1 / playback_speed_);
41 }
42 
44 
45  std::vector<std::string> topics;
46  std::pair<std::string, BagCallback *> cb;
47  foreach(cb, cbs_)
48  topics.push_back(cb.first);
49 
50  View view(bag, TopicQuery(topics), bag_start_, bag_end_);
52 
53  foreach(MessageInstance const m, view)
54  {
55  if (cbs_.find(m.getTopic()) == cbs_.end())
56  continue;
57 
59 
60  last_message_time_ = m.getTime(); /* this is the recorded time */
61  cbs_[m.getTopic()]->call(m);
62  }
63 }
64 
65 void BagPlayer::unregister_callback(const std::string &topic) {
66  delete cbs_[topic];
67  cbs_.erase(topic);
68 }
69 
70 }
71 
std::map< std::string, BagCallback * > cbs_
Definition: bag_player.h:119
ros::Time real_time(const ros::Time &msg_time)
Definition: bag_player.cpp:39
void open(std::string const &filename, uint32_t mode=bagmode::Read)
Open a bag file.
Definition: bag.cpp:106
static bool sleepUntil(const Time &end)
void set_playback_speed(double scale)
Definition: bag_player.cpp:34
void set_start(const ros::Time &start)
Definition: bag_player.cpp:26
void unregister_callback(const std::string &topic)
Definition: bag_player.cpp:65
ros::Time get_time()
Definition: bag_player.cpp:22
ros::Time play_start_
Definition: bag_player.h:124
void close()
Close the bag file.
Definition: bag.cpp:166
ros::Time bag_start_
Definition: bag_player.h:120
ros::Time const & getTime() const
virtual ~BagPlayer()
Definition: bag_player.cpp:18
ros::Time last_message_time_
Definition: bag_player.h:122
ros::Time getBeginTime()
Definition: view.cpp:187
A class pointing into a bag file.
void set_end(const ros::Time &end)
Definition: bag_player.cpp:30
static void init()
BagPlayer(const std::string &filename)
Definition: bag_player.cpp:8
double playback_speed_
Definition: bag_player.h:123
ros::Time bag_end_
Definition: bag_player.h:121
ros::Time getEndTime()
Definition: view.cpp:202
Definition: bag.h:78
std::string const & getTopic() const
static Time now()


rosbag_storage
Author(s):
autogenerated on Sun Feb 3 2019 03:29:47