29 #ifndef SWRI_ROSCPP_SUBSCRIBER_IMPL_H_ 30 #define SWRI_ROSCPP_SUBSCRIBER_IMPL_H_ 32 #include <std_msgs/Header.h> 72 if (stamp >= last_header_stamp_) {
77 if (message_count_ == 1) {
78 min_latency_ = latency;
79 max_latency_ = latency;
80 total_latency_ = latency;
82 min_latency_ = std::min(min_latency_, latency);
83 max_latency_ = std::max(max_latency_, latency);
84 double latency_weight_ = 0.1;
85 total_latency_.
fromSec(latency_weight_*latency.
toSec() + (1-latency_weight_)*total_latency_.
toSec());
89 if (message_count_ > 1) {
91 if (message_count_ == 2) {
94 total_periods_ = period;
95 }
else if (message_count_ > 2) {
96 min_period_ = std::min(min_period_, period);
97 max_period_ = std::max(max_period_, period);
98 total_periods_ += period;
105 last_receive_time_ = now;
106 last_header_stamp_ = stamp;
111 if (blocking_timeout_) {
119 if (message_count_ == 0) {
123 if (
age(now) > timeout_) {
132 unmapped_topic_(
"N/A"),
133 mapped_topic_(
"N/A"),
138 blocking_timeout_(false)
176 if (message_count_ < 1) {
178 }
else if (last_header_stamp_.
isValid()) {
189 if (message_count_ < 1) {
198 if (message_count_ < 1) {
207 if (message_count_ < 1) {
216 if (message_count_ < 2) {
225 if (message_count_ < 2) {
234 if (message_count_ < 2) {
243 if (message_count_ < 2) {
263 blocking_timeout_ = block;
296 static const bool value =
true;
299 template<
class M ,
class T>
308 const std::string &topic,
320 ROS_INFO(
"Subscribing to '%s' at '%s'.",
329 &TypedSubscriberImpl::handleMessage<M>,
336 typename boost::enable_if< ros::message_traits::HasHeader<M2>,
void>::type
340 (obj_->*callback_)(msg);
345 typename boost::disable_if< ros::message_traits::HasHeader<M2>,
void>::type
349 (obj_->*callback_)(msg);
356 boost::function<void(const boost::shared_ptr< M const> &)> callback_;
362 const std::string &topic,
373 ROS_INFO(
"Subscribing to '%s' at '%s'.",
378 callback_ = callback;
381 &BindSubscriberImpl::handleMessage<M>,
388 typename boost::enable_if< ros::message_traits::HasHeader<M2>,
void>::type
397 typename boost::disable_if< ros::message_traits::HasHeader<M2>,
void>::type
413 const std::string &topic,
423 ROS_INFO(
"Subscribing to '%s' at '%s'.",
431 &StorageSubscriberImpl::handleMessage<M>,
438 typename boost::enable_if< ros::message_traits::HasHeader<M2>,
void>::type
447 typename boost::disable_if< ros::message_traits::HasHeader<M2>,
void>::type
455 #endif // SWRI_ROSCPP_SUBSCRIBER_IMPL_H_ boost::shared_ptr< M const > * dest_
boost::enable_if< ros::message_traits::HasHeader< M2 >, void >::type handleMessage(const boost::shared_ptr< M const > &msg)
ros::Duration total_periods_
ros::Duration max_latency_
boost::disable_if< ros::message_traits::HasHeader< M2 >, void >::type handleMessage(const boost::shared_ptr< M const > &msg)
double meanFrequencyHz() const
int numPublishers() const
ros::Duration age(const ros::Time &now) const
ros::Duration minPeriod() const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
boost::disable_if< ros::message_traits::HasHeader< M2 >, void >::type handleMessage(const boost::shared_ptr< M const > &msg)
ros::Duration meanLatency() const
ros::Duration meanPeriod() const
uint32_t getNumPublishers() const
ros::Duration min_period_
boost::disable_if< ros::message_traits::HasHeader< M2 >, void >::type handleMessage(const boost::shared_ptr< M const > &msg)
virtual ~SubscriberImpl()
ros::Duration min_latency_
void processHeader(const ros::Time &stamp)
TypedSubscriberImpl(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, void(T::*fp)(const boost::shared_ptr< M const > &), T *obj, const ros::TransportHints &transport_hints)
void setTimeout(const ros::Duration &time_out)
Duration & fromSec(double t)
bool blockTimeouts(bool block)
ros::Duration minLatency() const
std::string mapped_topic_
bool timeoutEnabled() const
std::string unmapped_topic_
ros::Duration maxPeriod() const
std::string resolveName(const std::string &name, bool remap=true) const
const std::string & mappedTopic() const
bool timeoutsBlocked() const
ros::Duration timeout() const
boost::enable_if< ros::message_traits::HasHeader< M2 >, void >::type handleMessage(const boost::shared_ptr< M const > &msg)
void checkTimeout(const ros::Time &now)
boost::enable_if< ros::message_traits::HasHeader< M2 >, void >::type handleMessage(const boost::shared_ptr< M const > &msg)
BindSubscriberImpl(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const boost::function< void(const boost::shared_ptr< M const > &)> &callback, const ros::TransportHints &transport_hints)
ros::Time last_receive_time_
ros::Time last_header_stamp_
ros::Duration maxLatency() const
ros::Duration max_period_
const std::string & unmappedTopic() const
ROSTIME_DECL const Duration DURATION_MAX
StorageSubscriberImpl(ros::NodeHandle &nh, const std::string &topic, boost::shared_ptr< M const > *dest, const ros::TransportHints &transport_hints)
ros::Duration total_latency_