Skip to content

Commit 8a33671

Browse files
committed
Fix missed initialization
1 parent 6cb3fc3 commit 8a33671

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

controller_manager/include/controller_manager/controller_manager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class ControllerManager : public rclcpp::Node
9696

9797
void init_resource_manager(const std::string & robot_description);
9898

99+
void set_initial_hardware_components_state();
100+
99101
controller_interface::ControllerInterfaceBaseSharedPtr load_controller(
100102
const std::string & controller_name, const std::string & controller_type);
101103

controller_manager/src/controller_manager.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ ControllerManager::ControllerManager(
482482
{
483483
initialize_parameters();
484484
init_controller_manager();
485-
resource_manager_->set_on_component_state_switch_callback(
486-
std::bind(&ControllerManager::publish_activity, this));
485+
set_initial_hardware_components_state();
487486
}
488487
else
489488
{
@@ -665,6 +664,7 @@ void ControllerManager::robot_description_callback(const std_msgs::msg::String &
665664
}
666665

667666
init_resource_manager(robot_description_);
667+
set_initial_hardware_components_state();
668668
if (!is_resource_manager_initialized())
669669
{
670670
resource_manager_ =
@@ -723,6 +723,15 @@ void ControllerManager::init_resource_manager(const std::string & robot_descript
723723
get_logger(), "Exception caught while loading and initializing components: %s", e.what());
724724
return;
725725
}
726+
727+
if (robot_description_notification_timer_)
728+
{
729+
robot_description_notification_timer_->cancel();
730+
}
731+
}
732+
733+
void ControllerManager::set_initial_hardware_components_state()
734+
{
726735
resource_manager_->set_on_component_state_switch_callback(
727736
std::bind(&ControllerManager::publish_activity, this));
728737

@@ -815,7 +824,6 @@ void ControllerManager::init_resource_manager(const std::string & robot_descript
815824
}
816825
}
817826
}
818-
robot_description_notification_timer_->cancel();
819827
auto hw_components_info = resource_manager_->get_components_status();
820828

821829
for (const auto & [component_name, component_info] : hw_components_info)

controller_manager/test/test_controller_manager_with_resource_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ TEST_F(ControllerManagerTest, robot_description_callback_handles_nonexistent_plu
9999

100100
TEST_F(ControllerManagerTest, robot_description_callback_handles_no_geometry)
101101
{
102-
const std::string invalid_urdf = ros2_control_test_assets::minimal_robot_urdf_no_limits;
102+
const std::string invalid_urdf = ros2_control_test_assets::invalid_urdf_no_geometry;
103103

104104
TestControllerManager cm(
105105
executor_, invalid_urdf, false, "test_controller_manager", "", rclcpp::NodeOptions{});

0 commit comments

Comments
 (0)