Skip to content

Add wait_for_message overload using node interfaces - #3230

Open
Yadunund wants to merge 1 commit into
rollingfrom
yadu/generic_wait_for_message
Open

Add wait_for_message overload using node interfaces#3230
Yadunund wants to merge 1 commit into
rollingfrom
yadu/generic_wait_for_message

Conversation

@Yadunund

Copy link
Copy Markdown
Member

Description

Add a rclcpp::wait_for_message overload that takes NodeParametersInterface and NodeTopicsInterface instead of rclcpp::Node::SharedPtr.

The existing topic convenience overload requires a Node::SharedPtr, so it cannot be used with rclcpp_lifecycle::LifecycleNode, or during node construction when shared_from_this() is unavailable. The new overload uses the same rclcpp::create_subscription interface path already used elsewhere in rclcpp. The Node::SharedPtr overload now delegates to it.

Also extend coverage with:

  • unit tests for the explicit-interfaces overload in rclcpp
  • an isolated gtest in rclcpp_lifecycle that waits via a LifecycleNode held in a unique_ptr (no shared_from_this)

Related to #1953 (LifecycleNode / non-Node::SharedPtr support from the original proposal). This does not address the still-open executor / wait-set concern discussed there (calling wait_for_message from inside a node already managed by an executor).

Is this user-facing behavior change?

Yes. Callers can wait for a topic message using node interfaces, which enables LifecycleNode and construction-time use without shared_from_this(). Existing Node::SharedPtr and subscription+context overloads are unchanged in behavior.

Did you use Generative AI?

Yes. Cursor (Grok) was used to help draft the overload, tests, and this PR description. Changes were reviewed, adjusted and tested manually.

Additional Information

Example:

std_msgs::msg::String msg;
rclcpp::wait_for_message(
  msg,
  this->get_node_parameters_interface(),
  this->get_node_topics_interface(),
  "my_topic",
  std::chrono::seconds(1));

Tested via:

colcon test \
  --packages-select rclcpp rclcpp_lifecycle \
  --ctest-args -R 'wait_for_message' \
  --event-handlers console_direct+

@mergify

mergify Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Signed-off-by: Yadunund Vijay <yadunund@gmail.com>
@Yadunund
Yadunund force-pushed the yadu/generic_wait_for_message branch from bf353ac to 834930e Compare August 19, 2026 05:20

@skyegalaxy skyegalaxy left a comment

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.

lgtm. surprised we didn't already have this in the API before

@skyegalaxy

Copy link
Copy Markdown
Member

Pulls: #3230
Gist: https://gist.githubusercontent.com/skyegalaxy/e7ad2c217f84d2976b863d04657c7452/raw/4e3ae7ea59f91f9e5c90a892621fdd10004abc9f/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/20137

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

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.

2 participants