Skip to content

[Example 17] RRBot with Hardware Component that publishes diagnostics #840

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

soham2560
Copy link

@soham2560 soham2560 commented Jun 28, 2025

General

This is an example to document the usage of the Executor passed from Controller Manager through the recently added Struct based on_init() methods. Made possible by ros-controls/ros2_control#2323

as a further update that will be added in ros-controls/ros2_control#2348, this will also show how to use the default node added by the framework

This allows the user to add nodes of their own to the CMs executor and publish as necessary

@soham2560 soham2560 marked this pull request as ready for review June 30, 2025 02:52
Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the nice demo.
diagnostics usually refers to ros/diagnostics. Should we include this here instead of simple rclcpp publishers, or rename the demo to something else?

@soham2560
Copy link
Author

ooh, I think since this is not particularly about diagnostics maybe it would be better to rename. would status messages worl?

@christophfroehlich
Copy link
Contributor

I like diagnostics and use it from my hardware components, so maybe this would be also good to use here? we have it already in the CM, this is no new dependency then.

@soham2560
Copy link
Author

makes sense, I will use diagnostive for one of the publishers then, does that make sense? or both?

Comment on lines 130 to 154
// Get Default Node added to executor
if (get_node())
{
default_status_publisher_ =
get_node()->create_publisher<diagnostic_msgs::msg::DiagnosticArray>("/diagnostics", 10);
auto default_timer_callback = [this]() -> void
{
if (default_status_publisher_)
{
auto diagnostic_msg = std::make_unique<diagnostic_msgs::msg::DiagnosticArray>();
diagnostic_msg->header.stamp = get_node()->now();
diagnostic_msg->status.resize(1);

// Populate the status
diagnostic_msg->status[0].level = diagnostic_msgs::msg::DiagnosticStatus::OK;
diagnostic_msg->status[0].name = this->get_name();
diagnostic_msg->status[0].message = "Hardware is OK";

// Publish the message
default_status_publisher_->publish(std::move(diagnostic_msg));
}
};
using namespace std::chrono_literals;
default_status_timer_ = get_node()->create_wall_timer(2.5s, default_timer_callback);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, we could use the diagnostic_updater class, which handles the timer creation etc itself?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not aware of that, simplifies things a whole lot :). refer 3740cf9 and 5e1e02f

Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now there is a third option, using a custom publisher with the default node? As you were describing it before? No need to implement that, but maybe mention it here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if ac36157 works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants