From 30131b42f082a06032507040840c7ca4c48a6241 Mon Sep 17 00:00:00 2001 From: sp-sophia-labs <111747728+sp-sophia-labs@users.noreply.github.com> Date: Sun, 4 Dec 2022 10:52:24 +0100 Subject: [PATCH] Namespace Loaded Controllers (#852) * ci: :construction_worker: Add ABI check to ros_indiustrial ci (#597) * ci: :construction_worker: Add ABI check to ros_indiustrial ci refs: #583 * ci: :construction_worker: change notation of ci * ci: :construction_worker: change branch reference * ci: :construction_worker: address PR comments * move abi check to spearate workflow * check abi against base ref * PR against galactic branch * No need to get angles from source anymore, causes issues now (backport #616) (#617) * No need to get angles from source anymore, causes issues now (#616) (cherry picked from commit 2275f06281f297be972af2bb778efb1243f84e3f) * fix spelling * Apply suggestions from code review Co-authored-by: Bence Magyar * first commit * namespace support for load_controller in controller_manager * cleaning up, renaming variables and other small fixes * renaming namespace to manager_namespace to avoid errors * removing namespaced param * add gitignore for __pycache__ folders * remove pycache ignore * run 'pre-commit run --all' and fix flake8 errors * switch init declaration (revert) * remove the need to modify hardware interface * remove useless function arguments * removing namespace argument from manager services * remove namespace from service messages * namespaced->prefixed + minor changes for readability * fix forgotten rebase conflicts * remove galactic related files * revert controller_manager constructor changes Co-authored-by: Jaron <13423952+jaron-l@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Bence Magyar Co-authored-by: badr.moutalib Co-authored-by: Hoang David HA --- .../controller_manager/spawner.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/controller_manager/controller_manager/spawner.py b/controller_manager/controller_manager/spawner.py index be55f69223..2b0b8cac89 100644 --- a/controller_manager/controller_manager/spawner.py +++ b/controller_manager/controller_manager/spawner.py @@ -125,6 +125,10 @@ def main(args=None): '-p', '--param-file', help='Controller param file to be loaded into controller node before configure', required=False) + parser.add_argument( + '-n', '--namespace', + help='Namespace for the controller', default='', + required=False) parser.add_argument( '--load-only', help='Only load the controller and leave unconfigured.', action='store_true', required=False) @@ -150,6 +154,7 @@ def main(args=None): args = parser.parse_args(command_line_args) controller_name = args.controller_name controller_manager_name = args.controller_manager + controller_namespace = args.namespace param_file = args.param_file controller_type = args.controller_type controller_manager_timeout = args.controller_manager_timeout @@ -157,6 +162,10 @@ def main(args=None): if param_file and not os.path.isfile(param_file): raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), param_file) + prefixed_controller_name = controller_name + if controller_namespace: + prefixed_controller_name = controller_namespace + '/' + controller_name + node = Node('spawner_' + controller_name) if not controller_manager_name.startswith('/'): spawner_namespace = node.get_namespace() @@ -171,30 +180,27 @@ def main(args=None): node.get_logger().error('Controller manager not available') return 1 - if is_controller_loaded(node, controller_manager_name, controller_name): + if is_controller_loaded(node, controller_manager_name, prefixed_controller_name): node.get_logger().info('Controller already loaded, skipping load_controller') else: if controller_type: ret = subprocess.run(['ros2', 'param', 'set', controller_manager_name, - controller_name + '.type', controller_type]) - ret = load_controller( - node, controller_manager_name, controller_name) + prefixed_controller_name + '.type', controller_type]) + ret = load_controller(node, controller_manager_name, controller_name) if not ret.ok: # Error message printed by ros2 control return 1 - node.get_logger().info(bcolors.OKBLUE + 'Loaded ' + controller_name + bcolors.ENDC) + node.get_logger().info(bcolors.OKBLUE + 'Loaded ' + prefixed_controller_name + bcolors.ENDC) if param_file: - ret = subprocess.run(['ros2', 'param', 'load', controller_name, - param_file]) + ret = subprocess.run(['ros2', 'param', 'load', prefixed_controller_name, param_file]) if ret.returncode != 0: # Error message printed by ros2 param return ret.returncode - node.get_logger().info('Loaded ' + param_file + ' into ' + controller_name) + node.get_logger().info('Loaded ' + param_file + ' into ' + prefixed_controller_name) if not args.load_only: - ret = configure_controller( - node, controller_manager_name, controller_name) + ret = configure_controller(node, controller_manager_name, controller_name) if not ret.ok: node.get_logger().info('Failed to configure controller') return 1 @@ -213,7 +219,7 @@ def main(args=None): return 1 node.get_logger().info(bcolors.OKGREEN + 'Configured and activated ' + - bcolors.OKCYAN + controller_name + bcolors.ENDC) + bcolors.OKCYAN + prefixed_controller_name + bcolors.ENDC) elif args.stopped: node.get_logger().warn('"--stopped" flag is deprecated use "--inactive" instead')