Skip to content

refactor: move topic logic to topic api#785

Open
maciejmajek wants to merge 6 commits intomainfrom
refactor/topic-api-logic
Open

refactor: move topic logic to topic api#785
maciejmajek wants to merge 6 commits intomainfrom
refactor/topic-api-logic

Conversation

@maciejmajek
Copy link
Copy Markdown
Member

@maciejmajek maciejmajek commented Apr 9, 2026

Purpose

Move one-shot topic receive logic out of ROS2BaseConnector and into ROS2TopicAPI, giving ROS2TopicAPI full ownership of subscriber lifecycle for receive_message calls. This also activates the previously stored but never-used _destroy_subscribers flag.

Proposed Changes

ROS2TopicAPI (src/rai_core/rai/communication/ros2/api/topic.py):

  • Added receive_message(topic, timeout_sec, msg_type, qos_profile, auto_qos_matching) method.
    • Creates an internal subscriber (tracked in the already-declared _subscriptions dict) backed by the existing _generic_callback, which caches raw messages in _last_msg.
    • Returns a cached message immediately if it is fresh enough (received within timeout_sec).
    • Otherwise polls _last_msg until a message arrives or the timeout expires, raising TimeoutError on failure.
    • When destroy_subscribers=True, destroys and removes the subscription immediately after the first message is received (flag defaults to False to avoid the rclpy executor crash described in [launch_pytest] publishing error: cannot use Destroyable because destruction was requested ros2/rclpy#1142).

ROS2BaseConnector (src/rai_core/rai/communication/ros2/connectors/base.py):

  • Removed self.last_msg cache dict and _last_message_callback helper — both are now superseded by ROS2TopicAPI.
  • receive_message is now a thin delegation: calls _topic_api.receive_message(...) then wraps the raw result with general_callback_preprocessor.
  • Removed unused Dict from the typing import.

Issues

Testing

CI + Local

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.53%. Comparing base (f3a4598) to head (ae93608).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #785      +/-   ##
==========================================
+ Coverage   73.17%   74.53%   +1.35%     
==========================================
  Files          82       82              
  Lines        3579     3589      +10     
==========================================
+ Hits         2619     2675      +56     
+ Misses        960      914      -46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maciejmajek maciejmajek force-pushed the refactor/topic-api-logic branch from 648a5b8 to ae93608 Compare April 9, 2026 13:03
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.

1 participant