30 #include <rosgraph_msgs/TopicStatistics.h> 33 #include "std_msgs/Header.h" 54 const std::string& topic,
const std::string& callerid,
const SerializedMessage& m,
const uint64_t& bytes_sent,
55 const ros::Time& received_time,
bool dropped)
57 (void)connection_header;
66 if (topic ==
"/statistics" || topic ==
"/clock")
72 std::map<std::string, struct StatData>::iterator stats_it =
map_.find(callerid);
73 if (stats_it ==
map_.end())
80 map_[callerid] = stats;
84 stats =
map_[callerid];
103 if (!header.stamp.isZero())
105 stats.
age_list.push_back(received_time - header.stamp);
122 rosgraph_msgs::TopicStatistics msg;
124 msg.node_pub = callerid;
126 msg.window_start = window_start;
127 msg.window_stop = received_time;
138 for(std::list<ros::Duration>::iterator it = stats.
age_list.begin(); it != stats.
age_list.end(); it++)
141 msg.stamp_age_mean += age;
143 if (age > msg.stamp_age_max)
145 msg.stamp_age_max = age;
149 msg.stamp_age_mean *= 1.0 / stats.
age_list.size();
151 double stamp_age_variance = 0.0;
152 for(std::list<ros::Duration>::iterator it = stats.
age_list.begin(); it != stats.
age_list.end(); it++)
157 double stamp_age_stddev = sqrt(stamp_age_variance / stats.
age_list.size());
162 catch(std::runtime_error& e)
165 ROS_WARN_STREAM(
"Error updating stamp_age_stddev for topic [" << topic <<
"]" 166 <<
" from node [" << callerid <<
"]," 167 <<
" likely due to the time between the mean stamp age and this message being exceptionally large." 168 <<
" Exception was: " << e.what());
169 ROS_DEBUG_STREAM(
"Mean stamp age was: " << msg.stamp_age_mean <<
" - std_dev of: " << stamp_age_stddev);
197 msg.period_mean += period;
198 if (period > msg.period_max)
199 msg.period_max = period;
205 double period_variance = 0.0;
218 double period_stddev = sqrt(period_variance / (stats.
arrival_time_list.size() - 1));
233 pub_ = n.
advertise<rosgraph_msgs::TopicStatistics>(
"/statistics", 1);
256 map_[callerid] = stats;
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
Assign value from parameter server, with default.
void callback(const boost::shared_ptr< M_string > &connection_header, const std::string &topic, const std::string &callerid, const SerializedMessage &m, const uint64_t &bytes_sent, const ros::Time &received_time, bool dropped)
void init(const SubscriptionCallbackHelperPtr &helper)
void publish(const boost::shared_ptr< M > &message) const
Publish a message on the topic associated with this Publisher.
std::list< ros::Time > arrival_time_list
ROSCPP_DECL const std::string & getName()
Returns the name of the current node.
std::map< std::string, struct StatData > map_
roscpp's interface for creating subscribers, publishers, etc.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Advertise a topic, simple version.
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
std::list< ros::Duration > age_list
boost::shared_array< uint8_t > buf
std::string getTopic() const
Returns the topic that this Publisher will publish on.
void deserialize(Stream &stream, T &t)