-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Added Lifecycle Subscription wrapper #5772
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
35640ef
2ee17a2
26c33df
c49f05c
92d3264
ef44b00
53d59d6
df658f7
c114c21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. File Purpose: Added test executable for lifecycle subscription feature validation. Change Summary:
|
|
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. File Purpose: -Implements lifecycle-aware create_subscription and Provides overloads for rclcpp::Node and rclcpp_lifecycle::LifecycleNode. Changes: |
|
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. File Purpose: Extended LifecycleNode with managed entity interface support for lifecycle management. Additions:
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| #include "rcl_interfaces/msg/parameter_descriptor.hpp" | ||
| #include "nav2_ros_common/node_thread.hpp" | ||
| #include "rclcpp_lifecycle/lifecycle_node.hpp" | ||
| #include "rclcpp_lifecycle/managed_entity.hpp" | ||
| #include "rclcpp/rclcpp.hpp" | ||
| #include "bondcpp/bond.hpp" | ||
| #include "bond/msg/constants.hpp" | ||
|
|
@@ -145,11 +146,9 @@ class LifecycleNode : public rclcpp_lifecycle::LifecycleNode | |
| * @param callback Callback function to handle incoming messages | ||
| * @param qos QoS settings for the subscription (default is nav2::qos::StandardTopicQoS()) | ||
| * @param callback_group The callback group to use (if provided) | ||
| * @return A shared pointer to the created nav2::Subscription | ||
| * @return A shared pointer to the created nav2::LifecycleSubscription | ||
| */ | ||
| template< | ||
| typename MessageT, | ||
| typename CallbackT> | ||
| template<typename MessageT, typename CallbackT> | ||
| typename nav2::Subscription<MessageT>::SharedPtr | ||
| create_subscription( | ||
| const std::string & topic_name, | ||
|
|
@@ -369,6 +368,47 @@ class LifecycleNode : public rclcpp_lifecycle::LifecycleNode | |
| } | ||
| } | ||
|
|
||
| // ADDED: New methods for lifecycle interface management | ||
| /** | ||
| * @brief Add a managed entity (publisher, subscription, etc.) to be lifecycle-managed | ||
| * @param entity Shared pointer to the managed entity | ||
| */ | ||
| void add_managed_entity(std::shared_ptr<rclcpp_lifecycle::ManagedEntityInterface> entity) | ||
| { | ||
| managed_entities_.push_back(entity); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Activate all managed interfaces in the correct order | ||
| * Order: Publishers -> Service Clients -> Action Clients -> | ||
| * Subscriptions -> Service Servers -> Action Servers | ||
| */ | ||
| void activateInterfaces() | ||
| { | ||
| RCLCPP_INFO(get_logger(), "Activating all managed interfaces for %s", get_name()); | ||
| for (auto & entity : managed_entities_) { | ||
| if (entity) { | ||
| entity->on_activate(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @brief Deactivate all managed interfaces in reverse order | ||
| * Order: Action Servers -> Service Servers -> Subscriptions -> | ||
| * Action Clients -> Service Clients -> Publishers | ||
| */ | ||
| void deactivateInterfaces() | ||
| { | ||
| RCLCPP_INFO(get_logger(), "Deactivating all managed interfaces for %s", get_name()); | ||
| // Deactivate in reverse order | ||
| for (auto it = managed_entities_.rbegin(); it != managed_entities_.rend(); ++it) { | ||
| if (*it) { | ||
| (*it)->on_deactivate(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected: | ||
| /** | ||
| * @brief Print notifications for lifecycle node | ||
|
|
@@ -427,6 +467,9 @@ class LifecycleNode : public rclcpp_lifecycle::LifecycleNode | |
| double bond_heartbeat_period{0.1}; | ||
| rclcpp::TimerBase::SharedPtr autostart_timer_; | ||
|
|
||
| // ADDED: Vector to store all managed entities (publishers, subscriptions, etc.) | ||
|
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. This line and ones like it are making me think this is the output of an LLM. How did you validate, test, review, and compile this? We do not typically review AI outputs without you taking responsibility for quality control, we cannot review direct AI outputs - it is not a good use of maintainer time and resources. If you want to contribute a feature or fix, please put in your own legwork / effort to at least do QA and testing.
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. Thanks for your feedback @SteveMacenski ,
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. Its ok - just for the future its important to do your own QC before involving other developers :-) |
||
| std::vector<std::shared_ptr<rclcpp_lifecycle::ManagedEntityInterface>> managed_entities_; | ||
|
|
||
| private: | ||
| /** | ||
| * @brief Get the enable_lifecycle_services parameter value from NodeOptions | ||
|
|
||
|
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. File Purpose: Nav2 nodes rely on managed entities to ensure subscriptions follow lifecycle |
|
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. File Purpose: Updated action server test to use LifecycleNode and SharedPtr callbacks for lifecycle subscription compatibility. Change Summary:
|
|
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. File Purpose: New test executable to validate lifecycle-aware subscription . What Tests are cover:
Test exercise on |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright (c) 2025 Open Navigation LLC | ||
| // | ||
| // 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, | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
| #include <std_msgs/msg/string.hpp> | ||
| #include "nav2_ros_common/lifecycle_node.hpp" | ||
|
|
||
| class TestNode : public nav2::LifecycleNode | ||
| { | ||
| public: | ||
| TestNode() | ||
| : nav2::LifecycleNode("test_lifecycle_sub") | ||
| { | ||
| RCLCPP_INFO(get_logger(), "Test node created"); | ||
| } | ||
|
|
||
| void initialize() | ||
| { | ||
| RCLCPP_INFO(get_logger(), "Creating lifecycle subscription"); | ||
|
|
||
| sub_ = create_subscription<std_msgs::msg::String>( | ||
| "test_topic", | ||
| [this](const std_msgs::msg::String::SharedPtr msg) { | ||
| RCLCPP_INFO(get_logger(), "Received: %s", msg->data.c_str()); | ||
| }); | ||
|
|
||
| RCLCPP_INFO(get_logger(), "Subscription created"); | ||
| } | ||
|
|
||
| protected: | ||
| nav2::CallbackReturn on_configure(const rclcpp_lifecycle::State &) override | ||
| { | ||
| RCLCPP_INFO(get_logger(), "Configuring"); | ||
| return nav2::CallbackReturn::SUCCESS; | ||
| } | ||
|
|
||
| nav2::CallbackReturn on_activate(const rclcpp_lifecycle::State &) override | ||
| { | ||
| RCLCPP_INFO(get_logger(), "Activating - subscription will now process messages"); | ||
| return nav2::CallbackReturn::SUCCESS; | ||
| } | ||
|
|
||
| nav2::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &) override | ||
| { | ||
| RCLCPP_INFO(get_logger(), "Deactivating - subscription will ignore messages"); | ||
| return nav2::CallbackReturn::SUCCESS; | ||
| } | ||
|
|
||
| private: | ||
| nav2::Subscription<std_msgs::msg::String>::SharedPtr sub_; | ||
| }; | ||
|
|
||
| int main(int argc, char ** argv) | ||
| { | ||
| rclcpp::init(argc, argv); | ||
|
|
||
| // Create node using shared_ptr | ||
| auto node = std::make_shared<TestNode>(); | ||
|
|
||
| // Initialize when shared_ptr is created | ||
| node->initialize(); | ||
|
|
||
| rclcpp::spin(node->get_node_base_interface()); | ||
| rclcpp::shutdown(); | ||
| return 0; | ||
| } |
|
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. File Purpose: Updated route operations test callback signature to use SharedPtr for lifecycle subscription compatibility. Change Summary:
|
|
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. File Purpose: Updated PathConverter test callback signature to use SharedPtr for lifecycle subscription compatibility. Change Summary:
|
|
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. File Purpose: Updated TwistPublisher test callback signatures to use SharedPtr for lifecycle subscription compatibility. Change Summary:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File Purpose: Updated trajectory visualization test callback signatures to use SharedPtr for lifecycle subscription compatibility.
Summary:
*msg)