Skip to content

Commit

Permalink
Add diagnostics for the hardware components
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Sep 25, 2024
1 parent f23f9a4 commit 3246b8c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ class ControllerManager : public rclcpp::Node

void controller_activity_diagnostic_callback(diagnostic_updater::DiagnosticStatusWrapper & stat);

void hardware_components_diagnostic_callback(diagnostic_updater::DiagnosticStatusWrapper & stat);

/**
* @brief determine_controller_node_options - A method that retrieves the controller defined node
* options and adapts them, based on if there is a params file to be loaded or the use_sim_time
Expand Down
49 changes: 49 additions & 0 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ void ControllerManager::init_controller_manager()
diagnostics_updater_.setHardwareID("ros2_control");
diagnostics_updater_.add(
"Controllers Activity", this, &ControllerManager::controller_activity_diagnostic_callback);
diagnostics_updater_.add(
"Hardware Components Activity", this,
&ControllerManager::hardware_components_diagnostic_callback);
}

void ControllerManager::robot_description_callback(const std_msgs::msg::String & robot_description)
Expand Down Expand Up @@ -2780,6 +2783,52 @@ void ControllerManager::controller_activity_diagnostic_callback(
}
}

void ControllerManager::hardware_components_diagnostic_callback(
diagnostic_updater::DiagnosticStatusWrapper & stat)
{
bool all_active = true;
bool atleast_one_hw_active = false;
const auto hw_components_info = resource_manager_->get_components_status();
for (const auto & [component_name, component_info] : hw_components_info)
{
stat.add(component_name, component_info.state.label());
if (component_info.state.id() != lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE)
{
all_active = false;
}
else
{
atleast_one_hw_active = true;
}
}
if (!is_resource_manager_initialized())
{
stat.summary(
diagnostic_msgs::msg::DiagnosticStatus::ERROR, "Resource manager is not yet initialized!");
}
else if (hw_components_info.empty())
{
stat.summary(
diagnostic_msgs::msg::DiagnosticStatus::ERROR, "No hardware components are loaded!");
}
else
{
if (!atleast_one_hw_active)
{
stat.summary(
diagnostic_msgs::msg::DiagnosticStatus::ERROR,
"No hardware components are currently active");
}
else
{
stat.summary(
diagnostic_msgs::msg::DiagnosticStatus::OK, all_active
? "All hardware components are active"
: "Not all hardware components are active");
}
}
}

void ControllerManager::update_list_with_controller_chain(
const std::string & ctrl_name, std::vector<std::string>::iterator controller_iterator,
bool append_to_controller)
Expand Down

0 comments on commit 3246b8c

Please sign in to comment.