Skip to content

Commit

Permalink
feat(diagnostic_graph_utils): publish error graph instead of the term…
Browse files Browse the repository at this point in the history
…inal log

Signed-off-by: Takayuki Murooka <[email protected]>
  • Loading branch information
takayuki5168 committed Nov 21, 2024
1 parent 6c20d58 commit 584594f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions system/diagnostic_graph_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<depend>diagnostic_msgs</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>tier4_debug_msgs</depend>
<depend>tier4_system_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
14 changes: 10 additions & 4 deletions system/diagnostic_graph_utils/src/node/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ LoggingNode::LoggingNode(const rclcpp::NodeOptions & options) : Node("logging",
sub_graph_.register_create_callback(std::bind(&LoggingNode::on_create, this, _1));
sub_graph_.subscribe(*this, 1);

pub_error_graph_ =
create_publisher<tier4_debug_msgs::msg::StringStamped>("~/debug/error_graph", rclcpp::QoS(1));

const auto period = rclcpp::Rate(declare_parameter<double>("show_rate")).period();
timer_ = rclcpp::create_timer(this, get_clock(), period, [this]() { on_timer(); });
}
Expand All @@ -52,12 +55,15 @@ void LoggingNode::on_create(DiagGraph::ConstSharedPtr graph)

void LoggingNode::on_timer()
{
static const auto message = "The target mode is not available for the following reasons:";
if (root_unit_ && root_unit_->level() != DiagUnit::DiagnosticStatus::OK) {
dump_text_.str("");
dump_text_.clear(std::stringstream::goodbit);
dump_unit(root_unit_, 0, " ");
RCLCPP_WARN_STREAM(get_logger(), message << std::endl << dump_text_.str());
dump_unit(root_unit_, 0, " ");

tier4_debug_msgs::msg::StringStamped message;
message.stamp = now();
message.data = dump_text_.str();
pub_error_graph_->publish(message);
}
}

Expand Down Expand Up @@ -85,7 +91,7 @@ void LoggingNode::dump_unit(DiagUnit * unit, int depth, const std::string & inde

dump_text_ << indent << "- " + path << " " << text_level(unit->level()) << std::endl;
for (const auto & child : unit->children()) {
dump_unit(child.unit, depth + 1, indent + " ");
dump_unit(child.unit, depth + 1, indent + " ");
}
}

Expand Down
3 changes: 3 additions & 0 deletions system/diagnostic_graph_utils/src/node/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include <rclcpp/rclcpp.hpp>

#include "tier4_debug_msgs/msg/string_stamped.hpp"

#include <sstream>
#include <string>

Expand All @@ -35,6 +37,7 @@ class LoggingNode : public rclcpp::Node
void on_timer();
void dump_unit(DiagUnit * unit, int depth, const std::string & indent);
DiagGraphSubscription sub_graph_;
rclcpp::Publisher<tier4_debug_msgs::msg::StringStamped>::SharedPtr pub_error_graph_;
rclcpp::TimerBase::SharedPtr timer_;

DiagUnit * root_unit_;
Expand Down

0 comments on commit 584594f

Please sign in to comment.