topic_status.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include <limits>
12 #include <memory>
13 #include <string>
14 #include <type_traits>
15 
18 #include <ros/message_event.h>
19 #include <ros/message_traits.h>
20 
24 
25 namespace cras
26 {
27 
33 template <typename Message, typename = ::std::enable_if_t<::ros::message_traits::IsMessage<Message>::value>>
35 {
36 public:
43  template <typename M = Message, ::std::enable_if_t<!::ros::message_traits::HasHeader<M>::value, bool> = true>
44  TopicStatus(const ::std::string& name, const ::cras::TopicStatusParam<Message>& params) :
46  {
47  this->freqTask = ::std::make_unique<::diagnostic_updater::FrequencyStatus>(this->origParams);
48  this->addTask(this->freqTask.get());
49  }
50 
60  template <typename M = Message, ::std::enable_if_t<!::ros::message_traits::HasHeader<M>::value, bool> = true>
61  explicit TopicStatus(const ::std::string& name,
62  const double minRate = 0.0, const double maxRate = ::std::numeric_limits<double>::infinity(),
63  const double rateTolerance = 0.1, const int rateWindowSize = 5) :
64  TopicStatus(name, ::cras::TopicStatusParam<Message>(minRate, maxRate, rateTolerance, rateWindowSize))
65  {
66  }
67 
74  template <typename M = Message, ::std::enable_if_t<::ros::message_traits::HasHeader<M>::value, bool> = true>
75  TopicStatus(const ::std::string& name, const ::cras::TopicStatusParam<Message>& params) :
77  {
78  this->freqTask = ::std::make_unique<::diagnostic_updater::FrequencyStatus>(this->origParams);
79  this->stampTask = ::std::make_unique<::diagnostic_updater::SlowTimeStampStatus>(this->origParams);
80 
81  this->addTask(this->freqTask.get());
82  this->addTask(this->stampTask.get());
83  }
84 
96  template <typename M = Message, ::std::enable_if_t<::ros::message_traits::HasHeader<M>::value, bool> = true>
97  explicit TopicStatus(const ::std::string& name,
98  const double minRate = 0.0, const double maxRate = ::std::numeric_limits<double>::infinity(),
99  const double rateTolerance = 0.1, const int rateWindowSize = 5,
100  const double minDelay = -1.0, const double maxDelay = 5.0) :
101  TopicStatus(name, ::cras::TopicStatusParam<Message>(
102  minRate, maxRate, rateTolerance, rateWindowSize, minDelay, maxDelay))
103  {
104  }
105 
111  TopicStatus(const ::std::string& name, const ::cras::SimpleTopicStatusParam<Message>& params) :
112  TopicStatus(name, ::cras::TopicStatusParam<Message>(params))
113  {
114  }
115 
116  ~TopicStatus() override
117  {
118  }
119 
124  virtual void tick(const ::ros::Time& stamp)
125  {
126  this->freqTask->tick();
127  if (this->stampTask != nullptr)
128  this->stampTask->tick(stamp);
129  }
130 
135  virtual void tick(const Message& message)
136  {
137  this->freqTask->tick();
138  if (this->stampTask != nullptr && ::ros::message_traits::HasHeader<::cras::BaseMessage<Message>>::value)
139  this->stampTask->tick(*::ros::message_traits::TimeStamp<::cras::BaseMessage<Message>>::pointer(message));
140  }
141 
146  virtual void tick(const typename Message::Ptr& message)
147  {
148  this->tick(*message);
149  }
150 
155  virtual void tick(const typename Message::ConstPtr& message)
156  {
157  this->tick(*message);
158  }
159 
164  virtual void tick(const ::ros::MessageEvent<Message>& event)
165  {
166  this->tick(*event.getConstMessage());
167  }
168 
176  {
177  return ::cras::safeRate(this->origParams.getExpectedRate());
178  }
179 
185  {
186  return ::cras::safeRate(*this->origParams.min_freq_);
187  }
188 
194  {
195  return ::cras::safeRate(*this->origParams.max_freq_);
196  }
197 
202  double getRateTolerance() const
203  {
204  return this->origParams.tolerance_;
205  }
206 
211  int getRateWindowSize() const
212  {
213  return this->origParams.window_size_;
214  }
215 
221  template <typename M = Message, typename = ::std::enable_if_t<::ros::message_traits::HasHeader<M>::value>>
223  {
224  return ::ros::Duration(this->origParams.min_acceptable_);
225  }
226 
232  template <typename M = Message, typename = ::std::enable_if_t<::ros::message_traits::HasHeader<M>::value>>
234  {
235  return ::ros::Duration(this->origParams.max_acceptable_);
236  }
237 
238 protected:
240  ::std::unique_ptr<::diagnostic_updater::FrequencyStatus> freqTask;
241 
243  ::std::unique_ptr<::diagnostic_updater::SlowTimeStampStatus> stampTask;
244 
247 };
248 
249 template <typename Message>
250 using TopicStatusPtr = ::std::shared_ptr<::cras::TopicStatus<Message>>;
251 
252 }
ros::message_traits::TimeStamp
diagnostic_updater::CompositeDiagnosticTask::addTask
void addTask(DiagnosticTask *t)
message_utils.hpp
Utilities for working with ROS message files.
cras
Definition: any.hpp:15
cras::TopicStatus::freqTask
::std::unique_ptr<::diagnostic_updater::FrequencyStatus > freqTask
The frequency-checking diagnostic task. This will always be non-null.
Definition: topic_status.hpp:240
cras::TopicStatus::getMaxDelay
::ros::Duration getMaxDelay() const
Max acceptable delay (in s). It can be negative if timestamps in future are expected.
Definition: topic_status.hpp:233
cras::TopicStatus::TopicStatus
TopicStatus(const ::std::string &name, const double minRate=0.0, const double maxRate=::std::numeric_limits< double >::infinity(), const double rateTolerance=0.1, const int rateWindowSize=5)
Create the diagnostic task for a header-less message (checking frequency only).
Definition: topic_status.hpp:61
ros::message_traits::HasHeader
cras::TopicStatus::TopicStatus
TopicStatus(const ::std::string &name, const ::cras::TopicStatusParam< Message > &params)
Create the diagnostic task for a header-less message (checking frequency only).
Definition: topic_status.hpp:44
cras::TopicStatus::stampTask
::std::unique_ptr<::diagnostic_updater::SlowTimeStampStatus > stampTask
The delay-checking diagnostic task. It will be non-null only for messages with header.
Definition: topic_status.hpp:243
cras::TopicStatus::getMaxRate
::ros::Rate getMaxRate() const
Maximum allowed frequency.
Definition: topic_status.hpp:193
cras::TopicStatus
Diagnostic task for topic frequency and timestamp delay (combining FrequencyStatus and TimeStampStatu...
Definition: topic_status.hpp:34
cras::TopicStatus::getMinDelay
::ros::Duration getMinDelay() const
Min acceptable delay (in s). It can be negative if timestamps in future are expected.
Definition: topic_status.hpp:222
diagnostic_updater.h
cras::TopicStatus::getRateWindowSize
int getRateWindowSize() const
Number of updates during which the frequency is computed.
Definition: topic_status.hpp:211
message_traits.h
cras::TopicStatus::tick
virtual void tick(const ::ros::Time &stamp)
Record that a message has arrived now with the given timestamp.
Definition: topic_status.hpp:124
cras::TopicStatus::tick
virtual void tick(const Message &message)
Record that a message has arrived.
Definition: topic_status.hpp:135
diagnostic_updater
cras::TopicStatus::origParams
::cras::TopicStatusParam< Message > origParams
The parameters via which this task has been configured.
Definition: topic_status.hpp:246
cras::TopicStatus::getExpectedRate
::ros::Rate getExpectedRate() const
Get the expected/average rate. If min and max are the same, their value will be returned....
Definition: topic_status.hpp:175
cras::TopicStatus::tick
virtual void tick(const ::ros::MessageEvent< Message > &event)
Record that a message has arrived.
Definition: topic_status.hpp:164
cras::TopicStatus::getMinRate
::ros::Rate getMinRate() const
Minimum allowed frequency.
Definition: topic_status.hpp:184
cras::TopicStatus::TopicStatus
TopicStatus(const ::std::string &name, const ::cras::SimpleTopicStatusParam< Message > &params)
Create the diagnostic task checking frequency of messages and timestamp delay (if the message has hea...
Definition: topic_status.hpp:111
diagnostic_updater::CompositeDiagnosticTask
cras::safeRate
::ros::Rate safeRate(double frequency)
Return a rate representing the given frequency. If the frequency is zero or too small,...
cras::TopicStatus::tick
virtual void tick(const typename Message::ConstPtr &message)
Record that a message has arrived.
Definition: topic_status.hpp:155
update_functions.h
cras::TopicStatusParam
::std::conditional_t<::ros::message_traits::HasHeader< Message >::value, ::cras::TopicStatusParamWithHeader, ::cras::FrequencyStatusParam > TopicStatusParam
Helper struct for automatic choosing of the correct topic status parameter object based on whether th...
Definition: topic_status_param.hpp:280
time_utils.hpp
Utilities for working with time.
cras::TopicStatus::TopicStatus
TopicStatus(const ::std::string &name, const double minRate=0.0, const double maxRate=::std::numeric_limits< double >::infinity(), const double rateTolerance=0.1, const int rateWindowSize=5, const double minDelay=-1.0, const double maxDelay=5.0)
Create the diagnostic task for a message with header (checking frequency and timestamp delay).
Definition: topic_status.hpp:97
diagnostic_updater::CompositeDiagnosticTask::CompositeDiagnosticTask
CompositeDiagnosticTask(const std::string name)
ros::Rate
cras::TopicStatus::tick
virtual void tick(const typename Message::Ptr &message)
Record that a message has arrived.
Definition: topic_status.hpp:146
cras::TopicStatus::~TopicStatus
~TopicStatus() override
Definition: topic_status.hpp:116
cras::TopicStatus::getRateTolerance
double getRateTolerance() const
Tolerance of frequency.
Definition: topic_status.hpp:202
cras::TopicStatusPtr
::std::shared_ptr<::cras::TopicStatus< Message > > TopicStatusPtr
Definition: topic_status.hpp:250
topic_status_param.hpp
Definitions of parameters for a TopicStatus diagnostic task.
ros::Duration
message_event.h
cras::BaseMessage
typename ::ros::ParameterAdapter< M >::Message BaseMessage
Return the base message type of M (i.e. removes MessageEvent, const, &, shared_ptr etc....
Definition: message_utils.hpp:19


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04