Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor spawner to be able to reuse code for ros2controlcli #1661

Merged

Conversation

saikishor
Copy link
Member

@christophfroehlich has mentioned that ros2 control CLI is missing the functionality to load controllers with the parameter files as we have now with the spawner. upon reviewing the code, the code would need some refactoring to reduce some duplication of code in both places and to be able also to load controllers with namespaced controller manager

This PR would be the first part of refactoring that can go along with #1562, once both the PRs are done, the ros2 control CLI can be modified to add the parameter parsing from the file and proper usage with namespacing.

Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 73.21429% with 15 lines in your changes missing coverage. Please review.

Project coverage is 86.66%. Comparing base (80c264f) to head (6592413).
Report is 1 commits behind head on master.

Files Patch % Lines
.../controller_manager/controller_manager_services.py 74.54% 8 Missing and 6 partials ⚠️
controller_manager/controller_manager/spawner.py 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1661      +/-   ##
==========================================
+ Coverage   86.64%   86.66%   +0.01%     
==========================================
  Files         115      115              
  Lines       10542    10519      -23     
  Branches      970      970              
==========================================
- Hits         9134     9116      -18     
+ Misses       1059     1054       -5     
  Partials      349      349              
Flag Coverage Δ
unittests 86.66% <73.21%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
controller_manager/controller_manager/__init__.py 100.00% <ø> (ø)
...ler_manager/controller_manager/hardware_spawner.py 0.00% <ø> (ø)
controller_manager/test/test_spawner_unspawner.cpp 99.04% <ø> (-0.02%) ⬇️
controller_manager/controller_manager/spawner.py 71.66% <0.00%> (-3.20%) ⬇️
.../controller_manager/controller_manager_services.py 70.00% <74.54%> (+3.84%) ⬆️

... and 1 file with indirect coverage changes

Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this, this PR lgtm.

Copy link
Contributor

@fmauch fmauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some nice refactoring.

Comment on lines 42 to 51
class bcolors:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKCYAN = "\033[96m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see this only as a comment, not as a request:

This might be considered to be moved to a different file? Importing this from the controller_manager_services module seems to work fine for the given use cases, but maybe it would be more intuitive to declare it in the init file directly or move it to a separate helpers module.

Copy link
Member Author

@saikishor saikishor Aug 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very beginning i wanted to do it in the init file itself, but then if that's the case I couldn't use it inside the controller_manager_services file and then later add it as a module inside the init file. So, in theory you should be able to import in other python files as from controller_manager import bcolors, this is how it's done for the ros2controlcli

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And besides that, we should rethink on renaming colors, the names are quite fuzzy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Good idea. Maybe we can do it in a separate PR? What do you say?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renaming separately

@saikishor saikishor changed the title Refactor spawner to be able to reuse code Refactor spawner to be able to reuse code for ros2controlcli Aug 14, 2024
Copy link
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should backport this?

I think it is worth the work as it makes user-interface nicer and make it easier to maintain for few more humble years.

@saikishor
Copy link
Member Author

Sure! I agree it's much easier for maintenance

@bmagyar bmagyar added backport-humble This label should be used by maintaines only! Label triggers PR backport to ROS2 humble. backport-iron This label should be used by maintaines only! Label triggers PR backport to ROS2 Iron. labels Aug 16, 2024
@bmagyar bmagyar merged commit 0631e3e into ros-controls:master Aug 19, 2024
19 checks passed
mergify bot pushed a commit that referenced this pull request Aug 19, 2024
(cherry picked from commit 0631e3e)

# Conflicts:
#	controller_manager/controller_manager/spawner.py
#	controller_manager/test/test_spawner_unspawner.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-humble This label should be used by maintaines only! Label triggers PR backport to ROS2 humble. backport-iron This label should be used by maintaines only! Label triggers PR backport to ROS2 Iron.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants