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

Implement managed nodes #865

Merged
merged 34 commits into from
Dec 23, 2021
Merged

Implement managed nodes #865

merged 34 commits into from
Dec 23, 2021

Conversation

ivanpauno
Copy link
Member

@ivanpauno ivanpauno commented Dec 15, 2021

Fixes #604.

I took into account the feedback provided here ros2/rclcpp#1846, so you don't need to manually call on_activate/on_deactivate for managed entities like LifecyclePublisher.
I'm open to revert that bit, though I think it's a good idea.

I have only manually tested that the lifecycle node services work correctly.
I have not tested the lifecycle publisher at all.

This PR has tests now.
I could write some automated tests for the lifecycle builtin services though.
Done as well.

This is not ready to be merged, though early feedback is appreciated anyway.
This is ready now.

I'm working to add a demo equivalent to demos/lifecycle, but that shouldn't block this from being reviewed.
PR with demo ready: ros2/demos#547.

return TransitionCallbackReturn.SUCCESS


class SimpleManagedEntity(ManagedEntity):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there motivation to have the SimpleManagedEntity inherit from a ManagedEntity other than that they share two intended transitions (activate/deactivate). Presumably the other transitions do not do anything.

Copy link
Member Author

@ivanpauno ivanpauno Dec 17, 2021

Choose a reason for hiding this comment

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

I thought in some cases it could be useful to override some of the others, so I left all of them.

e.g. you can inherit from LifecyclePublisher and override on_error().
I'm not sure if that's really useful or not.

If the only use-case we see is something like SimpleManagedEntity, i.e. setting/clearing a flag in on_active/on_deactive, maybe it would be simpler to just keep a reference of the lifecycle node state machine in all managed entities and query if the current state is active or not.
That might be a bit slower, as there a few extra indirections and comparisons.

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
…ally manage child entities

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
…improvements

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
…ce=False

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
@ivanpauno ivanpauno marked this pull request as ready for review December 17, 2021 21:03
Copy link
Member

@audrow audrow 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 pretty good to me. It will be very nice to have lifecycle nodes in rclpy! I've commented on a few TODOs and made a few minor suggestions.

It would also be good to have a tutorial written for this at the same time that we merge in this PR.

Also, do you still intend to add more tests, or does that about cover it?

rclpy/rclpy/lifecycle/node.py Show resolved Hide resolved
rclpy/rclpy/lifecycle/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/lifecycle/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/lifecycle/node.py Show resolved Hide resolved
rclpy/rclpy/lifecycle/node.py Outdated Show resolved Hide resolved
rclpy/rclpy/lifecycle/node.py Outdated Show resolved Hide resolved
rclpy/test/test_lifecycle.py Show resolved Hide resolved
rclpy/test/test_lifecycle.py Show resolved Hide resolved
rclpy/test/test_lifecycle.py Outdated Show resolved Hide resolved
node = LifecycleNode(
'test_lifecycle_state_transitions_1', enable_communication_interface=False)
# normal transitions
assert node.trigger_configure() == TransitionCallbackReturn.SUCCESS
Copy link
Member

Choose a reason for hiding this comment

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

Maybe have a for loop put the node through many transitions, just to confirm that they work back-to-back.

Copy link
Member Author

Choose a reason for hiding this comment

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

IIUC after 4ca2a36 I'm testing all the possible transitions back to back.
I find it clear to do them manually instead of in a for loop, but if you have a code snippet that you find better feel free to share it.

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
ivanpauno and others added 11 commits December 20, 2021 17:30
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>

Co-authored-by: Audrow Nash <audrow.nash@gmail.com>
…r reuse in LifecycleNode and other derived classes

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
…ged entitities. Share implementation of default transtion callbacks

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
…hen shutdown transition is not possible

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Copy link
Member

@audrow audrow left a comment

Choose a reason for hiding this comment

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

Looks good to me with green CI.

rclpy/rclpy/lifecycle/node.py Show resolved Hide resolved
rclpy/test/test_lifecycle.py Show resolved Hide resolved
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
@ivanpauno
Copy link
Member Author

ivanpauno commented Dec 23, 2021

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status (unrelated failure)
  • Windows Build Status

@ivanpauno
Copy link
Member Author

Looks good to me with green CI.

I will request more feedback about the API, particularly considering it doesn't match exactly the rclcpp one (following the suggestion in ros2/rclcpp#1846).
I won't block this PR on that though, we still have time to make API changes until the Humble release.

@ivanpauno
Copy link
Member Author

Going in, thanks for the review @audrow !!

@SteveMacenski
Copy link

@ivanpauno any plans for adding docs that this exists? This came up here: ros-navigation/navigation2#3259 and while trying to show them documentation for the API, I came up with lint in my pockets 😄

@ivanpauno
Copy link
Member Author

@ivanpauno any plans for adding docs that this exists? This came up here: ros-planning/navigation2#3259 and while trying to show them documentation for the API, I came up with lint in my pockets smile

Yes sorry, there's not much more than the demo added in this PR up to now.
I will try to get some time to add better documentation.

@ros-discourse
Copy link

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/lifecycle-nodes-in-python/14547/4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Managed Nodes
5 participants