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

[CLI] Add set_hardware_component_state verb #1248

Merged

Conversation

christophfroehlich
Copy link
Contributor

@christophfroehlich christophfroehlich commented Dec 25, 2023

I updated the hardware lifecylce demo as part of the multi robot example ros-controls/ros2_control_demos#417 and realized that there is no cli verb for changing hardware lifecycle.

This PR adds the verb set_hardware_component_state to our CLI.

@christophfroehlich christophfroehlich 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 Dec 25, 2023
Copy link

codecov bot commented Dec 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.02%. Comparing base (35bb5f7) to head (5e42962).
Report is 7 commits behind head on master.

❗ Current head 5e42962 differs from pull request most recent head 6fa3492. Consider uploading reports for the commit 6fa3492 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1248       +/-   ##
===========================================
- Coverage   75.51%   48.02%   -27.49%     
===========================================
  Files          41       41               
  Lines        3328     3525      +197     
  Branches     1921     1912        -9     
===========================================
- Hits         2513     1693      -820     
- Misses        421      442       +21     
- Partials      394     1390      +996     
Flag Coverage Δ
unittests 48.02% <ø> (-27.49%) ⬇️

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

see 32 files with indirect coverage changes

Copy link
Contributor

@olivier-stasse olivier-stasse left a comment

Choose a reason for hiding this comment

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

LGTM.
Thanks a lot.

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.

Few smaller comments and one bigger to discuss

ros2controlcli/ros2controlcli/verb/set_controller_state.py Outdated Show resolved Hide resolved
Comment on lines 72 to 114
if args.state == "inactive":
inactive_state = State()
inactive_state.id = State.PRIMARY_STATE_INACTIVE
inactive_state.label = "inactive"

if matched_hardware_components.state.label == "unconfigured":
response = set_hardware_component_state(
node, args.controller_manager, args.hardware_component_name, inactive_state
)
if not response.ok:
return (
"Error configuring hardware component, check controller_manager logs"
)

print(
f"Successfully set {args.hardware_component_name} to state {response.state}"
)
return 0

elif matched_hardware_components.state.label == "active":
response = set_hardware_component_state(
node, args.controller_manager, args.hardware_component_name, inactive_state
)
if not response.ok:
return "Error stopping hardware component, check controller_manager logs"

print(
f"Successfully set {args.hardware_component_name} to state {response.state}"
)
return 0

else:
return (
f'cannot put {matched_hardware_components.name} in "inactive" state '
f"from its current state {matched_hardware_components.state}"
)

if args.state == "active":
if matched_hardware_components.state.label != "inactive":
return (
f"cannot activate {matched_hardware_components.name} "
f"from its current state {matched_hardware_components.state}"
)
Copy link
Member

Choose a reason for hiding this comment

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

This logic is also written in the ResourceManager, should we just let any request come through and then return here error or success with a message. Not sure if doubling logic is good for maintainability, but it is good for efficiency. Still, not sure that this degree of efficiency is needed here.

Copy link
Contributor Author

@christophfroehlich christophfroehlich Jan 12, 2024

Choose a reason for hiding this comment

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

I also think that we shouldn't duplicate the logic,
But what I want to avoid is something like with other controller-manager services, where one log-line is an error from controller-manager but the service returns OK. I'll have a look if response.ok is fine for giving useful feedback with the CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the logic now..

destogl
destogl previously approved these changes Jan 25, 2024
Copy link
Contributor

@mateusmenezes95 mateusmenezes95 left a comment

Choose a reason for hiding this comment

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

Just a minor minor fix

ros2controlcli/doc/userdoc.rst Outdated Show resolved Hide resolved
christophfroehlich and others added 4 commits March 23, 2024 15:30
Co-authored-by: Dr. Denis <denis@stoglrobotics.de>
Co-authored-by: Mateus Menezes <mateusmenezes95@gmail.com>
Copy link
Member

@saikishor saikishor left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Thanks!

@destogl destogl merged commit a902e27 into ros-controls:master Apr 1, 2024
6 of 11 checks passed
mergify bot pushed a commit that referenced this pull request Apr 1, 2024
Co-authored-by: Dr. Denis <denis@stoglrobotics.de>
Co-authored-by: Mateus Menezes <mateusmenezes95@gmail.com>
(cherry picked from commit a902e27)
mergify bot pushed a commit that referenced this pull request Apr 1, 2024
Co-authored-by: Dr. Denis <denis@stoglrobotics.de>
Co-authored-by: Mateus Menezes <mateusmenezes95@gmail.com>
(cherry picked from commit a902e27)
destogl pushed a commit that referenced this pull request Apr 2, 2024
Co-authored-by: Dr. Denis <denis@stoglrobotics.de>
Co-authored-by: Mateus Menezes <mateusmenezes95@gmail.com>
(cherry picked from commit a902e27)

Co-authored-by: Christoph Fröhlich <christophfroehlich@users.noreply.github.com>
destogl pushed a commit that referenced this pull request Apr 2, 2024
Co-authored-by: Dr. Denis <denis@stoglrobotics.de>
Co-authored-by: Mateus Menezes <mateusmenezes95@gmail.com>
(cherry picked from commit a902e27)

Co-authored-by: Christoph Fröhlich <christophfroehlich@users.noreply.github.com>
@christophfroehlich christophfroehlich deleted the set_hardware_component_state branch April 7, 2024 20:32
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.

None yet

6 participants