Skip to content

Commit

Permalink
Namespace Loaded Controllers (ros-controls#852)
Browse files Browse the repository at this point in the history
* ci: 👷 Add ABI check to ros_indiustrial ci (ros-controls#597)

* ci: 👷 Add ABI check to ros_indiustrial ci

refs: ros-controls#583

* ci: 👷 change notation of ci

* ci: 👷 change branch reference

* ci: 👷 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 ros-controls#616) (ros-controls#617)

* No need to get angles from source anymore, causes issues now (ros-controls#616)

(cherry picked from commit 2275f06)

* fix spelling

* Apply suggestions from code review

Co-authored-by: Bence Magyar <[email protected]>

* 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 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Bence Magyar <[email protected]>
Co-authored-by: badr.moutalib <[email protected]>
Co-authored-by: Hoang David HA <[email protected]>
  • Loading branch information
6 people authored Dec 4, 2022
1 parent efcdcc4 commit 30131b4
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions controller_manager/controller_manager/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -150,13 +154,18 @@ 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

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()
Expand All @@ -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
Expand All @@ -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')

Expand Down

0 comments on commit 30131b4

Please sign in to comment.