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(diagnostic_graph_aggregator): report the highest error level #1248

Merged
merged 1 commit into from
Apr 12, 2024
Merged
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
5 changes: 5 additions & 0 deletions system/diagnostic_graph_aggregator/src/common/graph/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ DiagnosticGraph Graph::report(const rclcpp::Time & stamp)
}
message.nodes.push_back(temp);
}

for (const auto & [name, diag] : diags_) {
diag->reported();
}

return message;
}

Expand Down
13 changes: 13 additions & 0 deletions system/diagnostic_graph_aggregator/src/common/graph/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ BaseUnit::NodeData BaseUnit::report() const

void DiagUnit::init(const UnitConfig::SharedPtr & config, const NodeDict &)
{
is_reported_ = true;
name_ = config->data.take_text("diag");
timeout_ = config->data.take<double>("timeout", 1.0);
}
Expand All @@ -87,9 +88,21 @@ void DiagUnit::update(const rclcpp::Time & stamp)

void DiagUnit::callback(const rclcpp::Time & stamp, const DiagnosticStatus & status)
{
// Do not overwrite if high error level has not been reported yet.
if (diagnostics_ && !is_reported_) {
if (status.level < diagnostics_->second.level) {
return;
}
}
is_reported_ = false;
diagnostics_ = std::make_pair(stamp, status);
}

void DiagUnit::reported()
{
is_reported_ = true;
}

AndUnit::AndUnit(const std::string & path, bool short_circuit) : BaseUnit(path)
{
short_circuit_ = short_circuit;
Expand Down
2 changes: 2 additions & 0 deletions system/diagnostic_graph_aggregator/src/common/graph/units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ class DiagUnit : public BaseUnit

std::string name() const { return name_; }
void callback(const rclcpp::Time & stamp, const DiagnosticStatus & status);
void reported();

private:
bool is_reported_;
double timeout_;
std::optional<std::pair<rclcpp::Time, DiagnosticStatus>> diagnostics_;
std::string name_;
Expand Down
Loading