Skip to content

Added Lifecycle Subscription wrapper#5772

Closed
Prathmesh2931 wants to merge 9 commits into
ros-navigation:mainfrom
Prathmesh2931:feat/5298-lifecycle-subscription
Closed

Added Lifecycle Subscription wrapper#5772
Prathmesh2931 wants to merge 9 commits into
ros-navigation:mainfrom
Prathmesh2931:feat/5298-lifecycle-subscription

Conversation

@Prathmesh2931
Copy link
Copy Markdown

  • Added new LifecycleSubscription wrapper class.

  • Integrated lifecycle-state checking before executing user callbacks.

  • Added new create_subscription() helper that automatically:

    • Applies Nav2 QoS & SubscriptionOptions

    • Wraps user callbacks in lifecycle checks

    • Registers the subscription inside the lifecycle wrapper

  • Updated:

    • interface_factories.hpp
    • lifecycle_node.hpp
    • subscription.hpp
      to support the new lifecycle subscription interface.
  • Added the new header:
    nav2_ros_common/lifecycle_subscription.hpp

Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
@mini-1235
Copy link
Copy Markdown
Collaborator

@Prathmesh2931
Copy link
Copy Markdown
Author

Prathmesh2931 commented Dec 9, 2025

@mini-1235
Thanks for the clarification. I’m currently trying to set up a clean, reproducible build environment for testing changes on the main branch, but I’m running into container-related issues (mainly DevContainer build failures, /tmp/devcontainercli-* temp folder problems, and incomplete multi-stage builds).

@mini-1235
Copy link
Copy Markdown
Collaborator

Take a look at https://github.com/ros-navigation/nav2_docker/pkgs/container/nav2_docker, you can directly pull the image:

docker pull ghcr.io/ros-navigation/nav2_docker:rolling-nightly

@SteveMacenski
Copy link
Copy Markdown
Member

Please fill in the PR template properly :-)

Comment on lines -52 to -59
const bool allow_parameter_qos_overrides = true,
const rclcpp::CallbackGroup::SharedPtr callback_group_ptr = nullptr,
rclcpp::QOSMessageLostCallbackType qos_message_lost_callback = nullptr,
rclcpp::SubscriptionMatchedCallbackType subscription_matched_callback = nullptr,
rclcpp::IncompatibleTypeCallbackType incompatible_qos_type_callback = nullptr,
rclcpp::QOSRequestedIncompatibleQoSCallbackType requested_incompatible_qos_callback = nullptr,
rclcpp::QOSDeadlineRequestedCallbackType qos_deadline_requested_callback = nullptr,
rclcpp::QOSLivelinessChangedCallbackType qos_liveliness_changed_callback = nullptr)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need all this, do not change

*/
template<typename MessageT>
using Subscription = rclcpp::Subscription<MessageT>;
using Subscription = LifecycleSubscription<MessageT>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file should contain the new subscription, not lifecycle_subscription.hpp. This is now Nav2 subscription

double bond_heartbeat_period{0.1};
rclcpp::TimerBase::SharedPtr autostart_timer_;

// ADDED: Vector to store all managed entities (publishers, subscriptions, etc.)
Copy link
Copy Markdown
Member

@SteveMacenski SteveMacenski Dec 9, 2025

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for your feedback @SteveMacenski ,
The issue was on my side -I hadn’t fully verified the build environment and Docker setup before submitting the changes. That’s my mistake.
I will make sure to do Proper checks , validation and QC from my end .
I really appreciate your guidance and it means lot to me .
Sorry for inconvenience .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 :-)

@SteveMacenski
Copy link
Copy Markdown
Member

Any update?

@Prathmesh2931
Copy link
Copy Markdown
Author

Yes , I am doing some lifecycle subscription testing

Prathmesh2931 and others added 2 commits December 28, 2025 14:08
Add nav2::Subscription class that wraps rclcpp subscriptions with
lifecycle state management, blocking message processing when inactive.

Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
@Prathmesh2931
Copy link
Copy Markdown
Author

Prathmesh2931 commented Dec 28, 2025

I am running into a build issue here - the existing test files are trying to use the old subscription type but I changed it to a lifecycle wrapper class.
Can you please guide me or any hint , how should i be proceeding further .
Should I fix the test or any other approach ?

@Prathmesh2931
Copy link
Copy Markdown
Author

Prathmesh2931 commented Dec 29, 2025

And also the ordering of parameter is different of rclcpp::Node::create_subscription and nav2::LifecycleNode::create_subscription .
I guess that is what causing build problem and also rclcpp::Subscription does not have virtual callback methods to override.

Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
@Prathmesh2931 Prathmesh2931 force-pushed the feat/5298-lifecycle-subscription branch from 9ca0dbc to ef44b00 Compare January 10, 2026 14:50
Add subscription helpers that are aware of LifecycleNode state.
Subscriptions created from a LifecycleNode will ignore incoming
messages when the node is inactive, while regular Node subscriptions
continue to behave as before.

Update affected tests to use SharedPtr callback signatures to match
the updated interfaces.

This change preserves backwards compatibility with existing Nav2 code

Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jan 12, 2026

This pull request is in conflict. Could you fix it @Prathmesh2931?

Prathmesh2931 and others added 2 commits January 12, 2026 11:56
Signed-off-by: Prathmesh2931 <145354550+Prathmesh2931@users.noreply.github.com>
- Adjust indentation in test_service_server.cpp
- Fix alignment in geometry_utils.hpp"

Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
@Prathmesh2931
Copy link
Copy Markdown
Author

Hi @mini-1235 ,
This PR addresses the lifecycle subscription functionality discussed in issue #5298. All changes have been manually tested and verified to work correctly with both active and inactive lifecycle states.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

File Purpose: Updated callback signatures in TwistSubscriber test to use SharedPtr for lifecycle subscription compatibility.

Change Summary:

  1. Changed callback parameters from raw messages to SharedPtr
  2. Updated assignment logic to dereference SharedPtr (*msg)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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:

  1. Updated create_subscription callbacks from raw message to SharedPtr pattern
  2. Modified assignment to dereference SharedPtr (*msg)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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:

  1. Updated Path subscription callback from raw message to SharedPtr pattern
  2. Modified assignment to dereference SharedPtr (*msg)

Copy link
Copy Markdown
Author

@Prathmesh2931 Prathmesh2931 Jan 12, 2026

Choose a reason for hiding this comment

The 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:

  1. Updated SpeedLimit subscription callback from raw message to SharedPtr pattern
  2. Modified assignment to dereference SharedPtr (*msg)
  3. Preserved both the flag setting and message capture logic

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

File Purpose: Added test executable for lifecycle subscription feature validation.

Change Summary:

  1. Added test_lifecycle_sub executable target
  2. Configure dependencies for lifecycle subscription testing
  3. Added installation directive for the test binary

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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:
Creates a test for lifecycle subscriptions which shows:

  1. Messages are not received while the node is unconfigured or inactive
  2. Messages are processed only after activation
  3. Subscriptions correctly stop receiving messages once the node is deactivated

Test exercise on on_configure , on_activate and on_deactivate callbacks to confirm behavior

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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:

  1. Class Inheritance: Changed from rclcpp::Node to nav2::LifecycleNode
  2. Callback Signatures: Updated from UniquePtr to SharedPtr pattern
  3. Constructor Update: Updated base class initialization
  4. QoS Syntax: Fixed subscription parameter order

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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
transitions like activate and deactivate correctly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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:

  1. Managed Entity System: Track publishers, subscriptions, services, actions as lifecycle-managed entities
  2. Coordinated Activation and Deactivation: activateInterfaces() - activate all entities and deactivateInterfaces() - deactivate all entities in order.
  3. Entity Registration: add_managed_entity() - register entities for lifecycle management

Copy link
Copy Markdown
Author

@Prathmesh2931 Prathmesh2931 Jan 12, 2026

Choose a reason for hiding this comment

The 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:
Replaced single complex create_subscription function with two overloads that automatically select appropriate behavior based on node type.

Copy link
Copy Markdown
Author

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:

  1. Updated multiple test callbacks from raw message to SharedPtr pattern
  2. Modified assignments to dereference SharedPtr (*msg)
  3. Consistent pattern across all visualization test cases

@SteveMacenski
Copy link
Copy Markdown
Member

SteveMacenski commented Jan 22, 2026

@Prathmesh2931 I think #5834 should supersede. Thanks for your work here and collaborating with @Lotusymt -- I think that has yielded a really nice solution 😄

Any interest in working on the services / actions?

Closing since I think we're moving forward with Lotusymt's design

@Prathmesh2931
Copy link
Copy Markdown
Author

Thanks Steve, appreciate the feedback .
Yes, I would definitely be interested in working on the services side. Happy to continue from @Lotusymt design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants