topic_manager.cpp
Go to the documentation of this file.
1 // Contains the topic configuration & status
2 // Author: Max Schwarz <max.schwarz@uni-bonn.de>
3 
4 #include "topic_manager.h"
5 
6 #include <ros/node_handle.h>
7 #include <rosfmt/rosfmt.h>
8 
9 #include <ros/names.h>
10 
11 namespace rosbag_fancy
12 {
13 
14 constexpr float STAT_TIME = 0.5;
15 
17 
19 {
20  ros::NodeHandle nh;
22  boost::bind(&TopicManager::updateStatistics, this)
23  );
24 }
25 
26 void TopicManager::addTopic(const std::string& topic, float rateLimit, int flags)
27 {
28  std::string resolvedName = ros::names::resolve(topic);
29 
30  auto it = std::find_if(m_topics.begin(), m_topics.end(), [&](Topic& t){
31  return t.name == resolvedName;
32  });
33 
34  if(it != m_topics.end())
35  {
37  "You tried to record topic '{}' twice. I'll ignore that (and use the first rate limit given, if applicable)",
38  resolvedName
39  );
40  return;
41  }
42 
43  m_topics.emplace_back(resolvedName, m_topics.size(), rateLimit, flags);
44 }
45 
47 {
48  for(auto& topic : m_topics)
49  {
50  topic.messageRate = topic.messagesInStatsPeriod / STAT_TIME;
51  topic.messagesInStatsPeriod = 0;
52 
53  topic.bandwidth = topic.bytesInStatsPeriod / STAT_TIME;
54  topic.bytesInStatsPeriod = 0;
55  }
56 }
57 
58 }
std::vector< Topic > m_topics
static const ros::WallTime T0
Definition: topic_manager.h:68
SteadyTimer createSteadyTimer(WallDuration period, void(T::*callback)(const SteadyTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
ros::SteadyTimer m_timer
ROSCPP_DECL std::string resolve(const std::string &name, bool remap=true)
void addTopic(const std::string &topic, float rateLimit=0.0f, int flags=0)
constexpr float STAT_TIME
static WallTime now()
#define ROSFMT_WARN(...)


rosbag_fancy
Author(s):
autogenerated on Fri Dec 9 2022 04:00:10