Skip to content

Commit 9e57adf

Browse files
authored
Fix unload of controllers when spawned with --unload-on-kill (#1717)
1 parent 7a5779c commit 9e57adf

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

controller_manager/controller_manager/spawner.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def main(args=None):
234234

235235
node.get_logger().info(
236236
bcolors.OKGREEN
237-
+ "Configured and activated all the parsed controllers list!"
237+
+ f"Configured and activated all the parsed controllers list : {controller_names}!"
238238
+ bcolors.ENDC
239239
)
240240

@@ -258,16 +258,25 @@ def main(args=None):
258258
)
259259
return 1
260260

261-
node.get_logger().info("Deactivated controller")
262-
263-
ret = unload_controller(node, controller_manager_name, controller_name)
264-
if not ret.ok:
265-
node.get_logger().error(
266-
bcolors.FAIL + "Failed to unload controller" + bcolors.ENDC
261+
node.get_logger().info(
262+
f"Successfully deactivated controllers : {controller_names}"
267263
)
268-
return 1
269264

270-
node.get_logger().info("Unloaded controller")
265+
unload_status = True
266+
for controller_name in controller_names:
267+
ret = unload_controller(node, controller_manager_name, controller_name)
268+
if not ret.ok:
269+
unload_status = False
270+
node.get_logger().error(
271+
bcolors.FAIL
272+
+ f"Failed to unload controller : {controller_name}"
273+
+ bcolors.ENDC
274+
)
275+
276+
if unload_status:
277+
node.get_logger().info(f"Successfully unloaded controllers : {controller_names}")
278+
else:
279+
return 1
271280
return 0
272281
except KeyboardInterrupt:
273282
pass

controller_manager/test/test_spawner_unspawner.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,25 @@ TEST_F(TestLoadController, unload_on_kill)
328328
ASSERT_EQ(cm_->get_loaded_controllers().size(), 0ul);
329329
}
330330

331+
TEST_F(TestLoadController, unload_on_kill_activate_as_group)
332+
{
333+
// Launch spawner with unload on kill
334+
// timeout command will kill it after the specified time with signal SIGINT
335+
ControllerManagerRunner cm_runner(this);
336+
cm_->set_parameter(rclcpp::Parameter("ctrl_3.type", test_controller::TEST_CONTROLLER_CLASS_NAME));
337+
cm_->set_parameter(rclcpp::Parameter("ctrl_2.type", test_controller::TEST_CONTROLLER_CLASS_NAME));
338+
std::stringstream ss;
339+
ss << "timeout --signal=INT 5 "
340+
<< std::string(coveragepy_script) +
341+
" $(ros2 pkg prefix controller_manager)/lib/controller_manager/spawner "
342+
<< "ctrl_3 ctrl_2 --activate-as-group -c test_controller_manager --unload-on-kill";
343+
344+
EXPECT_NE(std::system(ss.str().c_str()), 0)
345+
<< "timeout should have killed spawner and returned non 0 code";
346+
347+
ASSERT_EQ(cm_->get_loaded_controllers().size(), 0ul);
348+
}
349+
331350
TEST_F(TestLoadController, spawner_test_fallback_controllers)
332351
{
333352
const std::string test_file_path = ament_index_cpp::get_package_prefix("controller_manager") +

0 commit comments

Comments
 (0)