53 ROS_ERROR(
"GenericAnalyzer was not given parameter \"path\". Namepspace: %s",
59 if (n.
getParam(
"find_and_remove_prefix", find_remove))
61 vector<string> output;
68 if (n.
getParam(
"remove_prefix", removes))
72 if (n.
getParam(
"startswith", startswith))
80 if (n.
getParam(
"contains", contains))
84 if (n.
getParam(
"expected", expected))
87 for (
unsigned int i = 0; i < expected_.size(); ++i)
90 addItem(expected_[i], item);
97 vector<string> regex_strs;
100 for (
unsigned int i = 0; i < regex_strs.size(); ++i)
104 boost::regex re(regex_strs[i]);
105 regex_.push_back(re);
107 catch (boost::regex_error& e)
109 ROS_ERROR(
"Attempted to make regex from %s. Caught exception, ignoring value. Exception: %s",
110 regex_strs[i].c_str(), e.what());
115 if (startswith_.size() == 0 &&
name_.size() == 0 &&
116 contains_.size() == 0 && expected_.size() == 0 && regex_.size() == 0)
118 ROS_ERROR(
"GenericAnalyzer was not initialized with any way of checking diagnostics. Name: %s, namespace: %s", nice_name.c_str(), n.
getNamespace().c_str());
123 for(
size_t i=0; i<chaff_.size(); i++) {
128 int num_items_expected;
130 n.
param(
"timeout", timeout, 5.0);
131 n.
param(
"num_items", num_items_expected, -1);
132 n.
param(
"discard_stale", discard_stale,
false);
135 if (base_path ==
"/")
138 my_path = base_path +
"/" + nice_name;
140 if (my_path.find(
"/") != 0)
141 my_path =
"/" + my_path;
144 timeout, num_items_expected, discard_stale);
153 for (
unsigned int i = 0; i < regex_.size(); ++i)
155 if (boost::regex_match(name.c_str(), what, regex_[i]))
159 for (
unsigned int i = 0; i < expected_.size(); ++i)
161 if (name == expected_[i])
165 for (
unsigned int i = 0; i <
name_.size(); ++i)
167 if (name ==
name_[i])
171 for (
unsigned int i = 0; i < startswith_.size(); ++i)
173 if (name.find(startswith_[i]) == 0)
177 for (
unsigned int i = 0; i < contains_.size(); ++i)
179 if (name.find(contains_[i]) != string::npos)
191 vector<string> expected_names_missing;
192 bool has_name =
false;
194 for (
unsigned int i = 0; i < expected_.size(); ++i)
197 for (
unsigned int j = 0; j < processed.size(); ++j)
199 size_t last_slash = processed[j]->name.rfind(
"/");
200 string nice_name = processed[j]->name.substr(last_slash + 1);
201 if (nice_name == expected_[i] || nice_name ==
getOutputName(expected_[i]))
208 for (
unsigned int k = 0; k < chaff_.size(); ++k)
219 expected_names_missing.push_back(expected_[i]);
223 bool all_stale =
true;
224 for (
unsigned int j = 0; j < processed.size(); ++j)
226 if (processed[j]->level != 3)
231 for (
unsigned int i = 0; i < expected_names_missing.size(); ++i)
234 processed.push_back(item->toStatusMsg(path_,
true));
237 for (
unsigned int j = 0; j < processed.size(); ++j)
240 for (
unsigned int i = 0; i < chaff_.size(); ++i)
244 if (expected_names_missing.size() > 0 && processed[j]->name == path_)
248 processed[j]->level = 2;
249 processed[j]->message =
"Error";
253 processed[j]->level = 3;
254 processed[j]->message =
"All Stale";
258 for (
unsigned int k = 0; k < expected_names_missing.size(); ++k)
260 diagnostic_msgs::KeyValue kv;
261 kv.key = expected_names_missing[k];
262 kv.value =
"Missing";
263 processed[j]->values.push_back(kv);
PLUGINLIB_EXPORT_CLASS(diagnostic_aggregator::GenericAnalyzer, diagnostic_aggregator::Analyzer) GenericAnalyzer
virtual std::vector< boost::shared_ptr< diagnostic_msgs::DiagnosticStatus > > report()
Reports current state, returns vector of formatted status messages.
GenericAnalyzer is most basic diagnostic Analyzer.
virtual ~GenericAnalyzer()
virtual std::vector< boost::shared_ptr< diagnostic_msgs::DiagnosticStatus > > report()
Reports current state, returns vector of formatted status messages.
std::string removeLeadingNameChaff(const std::string &input_name, const std::string &chaff)
Removes redundant prefixes from status name.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
virtual bool match(const std::string name)
Returns true if item matches any of the given criteria.
bool getParam(const std::string &key, std::string &s) const
bool init(const std::string base_path, const ros::NodeHandle &n)
Initializes GenericAnalyzer from namespace. Returns true if s.
bool init(const std::string path, const ros::NodeHandle &n)=0
Analyzer is initialized with base path and namespace.
bool getParamVals(XmlRpc::XmlRpcValue param, std::vector< std::string > &output)
Returns list of strings from a parameter.
Base class of all Analyzers. Loaded by aggregator.
const std::string & getNamespace() const
GenericAnalyzer()
Default constructor loaded by pluginlib.
Helper class to hold, store DiagnosticStatus messages.
std::string getOutputName(const std::string item_name)
Replace "/" with "" in output name, to avoid confusing robot monitor.