-
Notifications
You must be signed in to change notification settings - Fork 522
Automatically transition lifecycle entities when node transitions #1863
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
Changes from all commits
02901df
988b77b
b2c73ec
469f5d7
0035757
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2022 Open Source Robotics Foundation, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef RCLCPP_LIFECYCLE__MANAGED_ENTITY_HPP_ | ||
| #define RCLCPP_LIFECYCLE__MANAGED_ENTITY_HPP_ | ||
|
|
||
| #include <atomic> | ||
|
|
||
| #include "rclcpp_lifecycle/visibility_control.h" | ||
|
|
||
| namespace rclcpp_lifecycle | ||
| { | ||
|
|
||
| /// Base class for lifecycle entities, like `LifecyclePublisher`. | ||
| class ManagedEntityInterface | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The interface in rclpy is a bit different (see here):
We could either modify this PR to do exactly what rclpy does or reduce rclpy flexibility to match more closely what this PR is adding.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Having less failure points sounds nice to me. I haven't thought through scenarios where someone may want to fail during activation/deactivation, but we could add it if the need arises.
If one or more of the callbacks fail, I would think we would want to transition all entities to the I agree that in most cases people will probably provide their own on_configure/on_shutdown logic. I think that it still might be nice if we call the transitions on all managed entities though. E.g. call any user-defined callback for the node and then, if that is successful, call the transition callbacks for managed entities. Or do you see something wrong with that behavior?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we could do that.
The only problem I see is that the logic is a bit complex and might not be actually useful in practice (we don't have any lifecycle entity that do work on configure/shutdown currently).
I think this has been resolved in the discussion here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. I'm fine keeping the implementation simple for now; we can add complexity if the need arises. |
||
| { | ||
| public: | ||
| RCLCPP_LIFECYCLE_PUBLIC | ||
| virtual | ||
| ~ManagedEntityInterface() {} | ||
|
|
||
| RCLCPP_LIFECYCLE_PUBLIC | ||
| virtual | ||
| void | ||
| on_activate() = 0; | ||
|
|
||
| RCLCPP_LIFECYCLE_PUBLIC | ||
| virtual | ||
| void | ||
| on_deactivate() = 0; | ||
| }; | ||
|
|
||
| /// A simple implementation of `ManagedEntityInterface`, which toogles a flag. | ||
| class SimpleManagedEntity : public ManagedEntityInterface | ||
| { | ||
| public: | ||
| RCLCPP_LIFECYCLE_PUBLIC | ||
| ~SimpleManagedEntity() override = default; | ||
|
|
||
| RCLCPP_LIFECYCLE_PUBLIC | ||
| void | ||
| on_activate() override; | ||
|
|
||
| RCLCPP_LIFECYCLE_PUBLIC | ||
| void | ||
| on_deactivate() override; | ||
|
|
||
| RCLCPP_LIFECYCLE_PUBLIC | ||
| bool | ||
| is_activated() const; | ||
|
|
||
| private: | ||
| std::atomic<bool> activated_ = false; | ||
| }; | ||
|
|
||
| } // namespace rclcpp_lifecycle | ||
| #endif // RCLCPP_LIFECYCLE__MANAGED_ENTITY_HPP_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright 2022 Open Source Robotics Foundation, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "rclcpp_lifecycle/managed_entity.hpp" | ||
|
|
||
| namespace rclcpp_lifecycle | ||
| { | ||
|
|
||
| void SimpleManagedEntity::on_activate() | ||
| { | ||
| activated_.store(true); | ||
| } | ||
|
|
||
| void SimpleManagedEntity::on_deactivate() | ||
| { | ||
| activated_.store(false); | ||
| } | ||
|
|
||
| bool SimpleManagedEntity::is_activated() const | ||
| { | ||
| return activated_.load(); | ||
| } | ||
|
|
||
| } // namespace rclcpp_lifecycle |
Uh oh!
There was an error while loading. Please reload this page.