Skip to content

Commit

Permalink
jsk_topic_tools: add option to set diangostic level
Browse files Browse the repository at this point in the history
jsk_topic_tools: update doc for jsk_topic_tools nodelet classes
  • Loading branch information
furushchev committed Jun 21, 2018
1 parent 8a24715 commit baaf908
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc/jsk_topic_tools/class/connection_based_nodelet.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ This base-class is being deprecated and replaced by `nodelet_topic_tools::Nodele
This class is a base-class which can start subscribing topics if published topics are subscribed by the other node.
This is abstruct class.

## Note

Each subclass of this class must call `onInitPostProcess` in the last line `onInit`.

## Parameter
- `~use_multithread_callback` (Bool, default: `true`):

Expand Down
16 changes: 15 additions & 1 deletion doc/jsk_topic_tools/class/diagnostic_nodelet.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@

This class is a subclass of [`ConnectionBasedNodelet`](connection_based_nodelet.html).
Instances of this class can publish diagnostics messages.
This is abstruct class.
This is an abstruct class.

## Note

Each subclass of this class is required to call `vital_checker_->poke()` on all callback functions so that this class can check the health of the functionality of the nodelet.

## Publishing Topic

- `~diagnostics` (`diagnostic_msgs::DiagnosticArray`):

Diagnostic messages

## Parameter
- `~vital_rate` (Double, default: `0.1`):

Rate to determine if the nodelet is in health.
If the rate that the callback functions is below this parameter, error messages are displayed on diagnostics.

- `~use_warning` (Bool, default: `False`):

If this parameter is enabled, diagnostic messages on failure is displayed on `WARN` level instead of `ERROR` level.
6 changes: 6 additions & 0 deletions jsk_topic_tools/include/jsk_topic_tools/diagnostic_nodelet.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ namespace jsk_topic_tools
*/
jsk_topic_tools::VitalChecker::Ptr vital_checker_;

/** @brief
* True if summary is displayed as 'Warnings', otherwise it is displayed as 'Errors'
*/
uint8_t diagnostic_error_level_;


private:

};
Expand Down
3 changes: 2 additions & 1 deletion jsk_topic_tools/include/jsk_topic_tools/diagnostic_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace jsk_topic_tools
void addDiagnosticErrorSummary(
const std::string& string_prefix,
jsk_topic_tools::VitalChecker::Ptr vital_checker,
diagnostic_updater::DiagnosticStatusWrapper& stat);
diagnostic_updater::DiagnosticStatusWrapper& stat,
const uint8_t error_level = diagnostic_msgs::DiagnosticStatus::ERROR);

////////////////////////////////////////////////////////
// add Boolean string to stat
Expand Down
15 changes: 14 additions & 1 deletion jsk_topic_tools/src/diagnostic_nodelet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ namespace jsk_topic_tools
&DiagnosticNodelet::updateDiagnostic,
this,
_1));

bool use_warn;
nh_->param("/diagnostic_nodelet/use_warn", use_warn, false);
if (pnh_->hasParam("use_warn")) {
pnh_->getParam("use_warn", use_warn);
}
if (use_warn)
{
diagnostic_error_level_ = diagnostic_msgs::DiagnosticStatus::ERROR;
} else {
diagnostic_error_level_ = diagnostic_msgs::DiagnosticStatus::WARN;
}

double vital_rate;
pnh_->param("vital_rate", vital_rate, 1.0);
vital_checker_.reset(
Expand All @@ -72,7 +85,7 @@ namespace jsk_topic_tools
}
else {
jsk_topic_tools::addDiagnosticErrorSummary(
name_, vital_checker_, stat);
name_, vital_checker_, stat, diagnostic_error_level_);
}
}
else {
Expand Down
5 changes: 3 additions & 2 deletions jsk_topic_tools/src/diagnostic_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ namespace jsk_topic_tools
void addDiagnosticErrorSummary(
const std::string& string_prefix,
jsk_topic_tools::VitalChecker::Ptr vital_checker,
diagnostic_updater::DiagnosticStatusWrapper& stat)
diagnostic_updater::DiagnosticStatusWrapper& stat,
const uint8_t error_level)
{
stat.summary(
diagnostic_msgs::DiagnosticStatus::ERROR,
error_level,
(boost::format("%s not running for %f sec")
% string_prefix % vital_checker->deadSec()).str());
}
Expand Down

0 comments on commit baaf908

Please sign in to comment.