topic_status_monitor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <ros/ros.h>
23 #include <boost/thread/mutex.hpp>
24 #include <cmath>
25 
26 
28 {
29 public:
31  {
32  ros::NodeHandle nh;
33  double hz, hzerror;
34  int window_size;
35  ros::param::get("~hz", hz);
36  ros::param::get("~hzerror", hzerror);
37  ros::param::param<int>("~window_size", window_size, std::ceil(hz));
38 
39  min_freq_ = hz-hzerror;
40  max_freq_ = hz+hzerror;
41 
42  diagnostic_updater::FrequencyStatusParam freq_param(&min_freq_, &max_freq_, 0.0, window_size); //min_freq, max_freq, tolerance (default: 0.1), window_size (default: 5)
43  diagnostic_updater::TimeStampStatusParam stamp_param(-1, 1); //min_acceptable (default: -1), max_acceptable (default: 5)
44 
45  topic_diagnostic_task_.reset(new diagnostic_updater::TopicDiagnostic(topic_name, diagnostic_updater, freq_param, stamp_param));
46 
48  }
49 
51  {
53  }
54 
58 };
59 
60 
62 {
63 public:
65  {
66  ros::NodeHandle nh;
67  ros::param::get("~topics", topics_);
68  ros::param::get("~diagnostics_name", hardware_id_);
69  diagnostic_updater_.setHardwareID(hardware_id_);
70 
71  for(size_t i=0; i<topics_.size(); i++)
72  {
73  tasks_.push_back(new GenericTopicDiagnostic (topics_[i], diagnostic_updater_));
74  }
75 
76  diagnostic_timer_ = nh.createTimer(ros::Duration(1.0), &TopicStatusMonitor::updateDiagnostics, this);
77  diagnostic_timer_.start();
78  }
79 
81  {}
82 
83 
85  {
86  diagnostic_updater_.update();
87  }
88 
89 private:
90  std::string hardware_id_;
91  std::vector<std::string> topics_;
93 
94  std::vector< GenericTopicDiagnostic* > tasks_;
96 };
97 
98 
99 
100 int main(int argc, char **argv)
101 {
102  ros::init(argc, argv, "topic_status_monitor");
103  TopicStatusMonitor tsm;
104 
105  ros::spin();
106 
107  return 0;
108 }
boost::shared_ptr< diagnostic_updater::TopicDiagnostic > topic_diagnostic_task_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void start()
GenericTopicDiagnostic(std::string &topic_name, diagnostic_updater::Updater &diagnostic_updater)
diagnostic_updater::Updater diagnostic_updater_
void topicCallback(const topic_tools::ShapeShifter::ConstPtr &msg)
ROSCPP_DECL void spin(Spinner &spinner)
int main(int argc, char **argv)
void updateDiagnostics(const ros::TimerEvent &event)
ROSCPP_DECL bool get(const std::string &key, std::string &s)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
std::vector< GenericTopicDiagnostic * > tasks_
static Time now()
std::vector< std::string > topics_


cob_monitoring
Author(s): Florian Weisshardt , Felix Messmer
autogenerated on Wed Apr 7 2021 03:03:11