Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add publish_values parameter #418

Open
wants to merge 8 commits into
base: ros2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ class Aggregator
*/
bool critical_;

/*!
*\brief If true, the aggregator will publish "values" for each DiagnosticStatus
*/
bool publish_values_;

/*!
*\brief Store the last top level value to publish the critical error only once.
*/
Expand Down
1 change: 1 addition & 0 deletions diagnostic_aggregator/mainpage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Reads the following parameters from the parameter server
- \b "~base_path" : \b double [optional] Prepended to all analyzed output
- \b "~analyzers" : \b {} Configuration for loading analyzers
- \b "~critical" : \b bool [optional] React immediately to a degradation in diagnostic state
- \b "~publish_values: \b bool [optional] Publish the "values" for each diagnostic status. Default: "true"

\subsection analyzer_loader analyzer_loader

Expand Down
12 changes: 12 additions & 0 deletions diagnostic_aggregator/src/aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Aggregator::Aggregator()
clock_(n_->get_clock()),
base_path_(""),
critical_(false),
publish_values_(true),
last_top_level_state_(DiagnosticStatus::STALE)
{
RCLCPP_DEBUG(logger_, "constructor");
Expand Down Expand Up @@ -123,6 +124,8 @@ void Aggregator::initAnalyzers()
history_depth_ = param.second.as_int();
} else if (param.first.compare("critical") == 0) {
critical_ = param.second.as_bool();
} else if (param.first.compare("publish_values") == 0) {
publish_values_ = param.second.as_bool();
}
}
RCLCPP_DEBUG(logger_, "Aggregator publication rate configured to: %f", pub_rate_);
Expand All @@ -131,6 +134,8 @@ void Aggregator::initAnalyzers()
logger_, "Aggregator other_as_errors configured to: %s", (other_as_errors ? "true" : "false"));
RCLCPP_DEBUG(
logger_, "Aggregator critical publisher configured to: %s", (critical_ ? "true" : "false"));
RCLCPP_DEBUG(
logger_, "Aggregator publish_values configured to: %s", (publish_values_ ? "true" : "false"));

{ // lock the mutex while analyzer_group_ and other_analyzer_ are being updated
std::lock_guard<std::mutex> lock(mutex_);
Expand Down Expand Up @@ -244,6 +249,13 @@ void Aggregator::publishData()
}
}

// If "publish_values" is false, clear all values
if (!publish_values_) {
for (auto & status : diag_array.status) {
status.values.clear();
}
}

diag_array.header.stamp = clock_->now();
agg_pub_->publish(diag_array);

Expand Down
Loading