From 89e2ff45625382bffbf114893cb4700f4c36ad21 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Wed, 9 Oct 2024 15:14:46 +0200 Subject: [PATCH] Improve launch utils to support the multiple controller names (#1782) --- .../controller_manager/launch_utils.py | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/controller_manager/controller_manager/launch_utils.py b/controller_manager/controller_manager/launch_utils.py index ead11a1ec8..4cef8743ac 100644 --- a/controller_manager/controller_manager/launch_utils.py +++ b/controller_manager/controller_manager/launch_utils.py @@ -19,8 +19,11 @@ from launch_ros.actions import Node -def generate_load_controller_launch_description( - controller_name, controller_type=None, controller_params_file=None, extra_spawner_args=[] +def generate_controllers_spawner_launch_description( + controller_names: list, + controller_type=None, + controller_params_file=None, + extra_spawner_args=[], ): """ Generate launch description for loading a controller using spawner. @@ -32,11 +35,11 @@ def generate_load_controller_launch_description( Examples -------- # Assuming the controller type and controller parameters are known to the controller_manager - generate_load_controller_launch_description('joint_state_broadcaster') + generate_controllers_spawner_launch_description(['joint_state_broadcaster']) - # Passing controller type and controller parameter file to load - generate_load_controller_launch_description( - 'joint_state_broadcaster', + # Passing controller type and parameter file to load the controller + generate_controllers_spawner_launch_description( + ['joint_state_broadcaster'], controller_type='joint_state_broadcaster/JointStateBroadcaster', controller_params_file=os.path.join(get_package_share_directory('my_pkg'), 'config', 'controller_params.yaml'), @@ -55,11 +58,13 @@ def generate_load_controller_launch_description( description="Wait until the node is interrupted and then unload controller", ) - spawner_arguments = [ - controller_name, - "--controller-manager", - LaunchConfiguration("controller_manager_name"), - ] + spawner_arguments = controller_names + spawner_arguments.extend( + [ + "--controller-manager", + LaunchConfiguration("controller_manager_name"), + ] + ) if controller_type: spawner_arguments += ["--controller-type", controller_type] @@ -98,3 +103,14 @@ def generate_load_controller_launch_description( spawner, ] ) + + +def generate_load_controller_launch_description( + controller_name: str, controller_type=None, controller_params_file=None, extra_spawner_args=[] +): + return generate_controllers_spawner_launch_description( + controller_names=[controller_name], + controller_type=controller_type, + controller_params_file=controller_params_file, + extra_spawner_args=extra_spawner_args, + )