Skip to content

Commit

Permalink
feat(diagnostic_graph_aggregator): report the highest error level
Browse files Browse the repository at this point in the history
Signed-off-by: Takagi, Isamu <[email protected]>
  • Loading branch information
isamu-takagi committed Apr 11, 2024
1 parent 748e12b commit 8caa935
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

0 comments on commit 8caa935

Please sign in to comment.