Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "jsk_topic_tools/diagnostic_nodelet.h"
00037 #include <sstream>
00038 namespace jsk_topic_tools
00039 {
00040 DiagnosticNodelet::DiagnosticNodelet(const std::string& name):
00041 name_(name)
00042 {
00043
00044 }
00045
00046 void DiagnosticNodelet::onInit()
00047 {
00048 ConnectionBasedNodelet::onInit();
00049 diagnostic_updater_.reset(
00050 new TimeredDiagnosticUpdater(*pnh_, ros::Duration(1.0)));
00051 diagnostic_updater_->setHardwareID(getName());
00052 diagnostic_updater_->add(
00053 getName() + "::" + name_,
00054 boost::bind(
00055 &DiagnosticNodelet::updateDiagnostic,
00056 this,
00057 _1));
00058 double vital_rate;
00059 pnh_->param("vital_rate", vital_rate, 1.0);
00060 vital_checker_.reset(
00061 new jsk_topic_tools::VitalChecker(1 / vital_rate));
00062 diagnostic_updater_->start();
00063 }
00064
00065 void DiagnosticNodelet::updateDiagnostic(
00066 diagnostic_updater::DiagnosticStatusWrapper &stat)
00067 {
00068 if (connection_status_ == SUBSCRIBED) {
00069 if (vital_checker_->isAlive()) {
00070 stat.summary(diagnostic_msgs::DiagnosticStatus::OK,
00071 getName() + " running");
00072 }
00073 else {
00074 jsk_topic_tools::addDiagnosticErrorSummary(
00075 name_, vital_checker_, stat);
00076 }
00077 }
00078 else {
00079 stat.summary(diagnostic_msgs::DiagnosticStatus::OK,
00080 getName() + " is not subscribed");
00081 }
00082 std::stringstream topic_names;
00083 for (size_t i = 0; i < publishers_.size(); i++) {
00084 if (i == publishers_.size() - 1) {
00085 topic_names << publishers_[i].getTopic();
00086 }
00087 else {
00088 topic_names << publishers_[i].getTopic() << ", ";
00089 }
00090 }
00091 stat.add("watched topics", topic_names.str());
00092 for (size_t i = 0; i < publishers_.size(); i++) {
00093 stat.add(publishers_[i].getTopic(),
00094 (boost::format("%d subscribers") %
00095 publishers_[i].getNumSubscribers()).str());
00096 }
00097 }
00098 }