Skip to content
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

feat(RaiBaseNode): add qos policy matching #353

Merged
merged 10 commits into from
Jan 9, 2025

Conversation

maciejmajek
Copy link
Member

@maciejmajek maciejmajek commented Dec 31, 2024

Purpose

QoS matching is essential for proper data transfer in ROS 2. Incompatible QoS settings may result in miscommunication between publishers and subscribers.

Proposed Changes

Simple QoS matching (copying) mechanism, based on Node.get_publishers_info_by_topic

Issues

#336

Testing

  • Performance tests, results will be published in this PR comments

Summary by CodeRabbit

  • New Features

    • Enhanced Quality of Service (QoS) profile management for ROS 2 message handling
    • Introduced adaptive QoS profile selection for message retrieval
    • Added caching mechanism for QoS profiles to improve efficiency
  • Tests

    • Created new test framework for publishing and retrieving ROS 2 messages
    • Added test publisher for Image and String message types
    • Implemented message transport validation tests

@maciejmajek maciejmajek force-pushed the feat/qos-matching branch 2 times, most recently from a946222 to b10954f Compare December 31, 2024 16:06
@maciejmajek
Copy link
Member Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Dec 31, 2024

Walkthrough

The changes involve enhancements to the ROS 2 node implementation in src/rai/rai/node.py and the addition of a new test file tests/messages/test_transport.py. The modifications focus on improving Quality of Service (QoS) profile handling in message retrieval, introducing a new method to adapt QoS profiles based on available publishers, and implementing a QoS profile cache. The new test file provides a comprehensive test for message transport, creating a test publisher and verifying message retrieval capabilities.

Changes

File Change Summary
src/rai/rai/node.py - Added adapt_requests_to_offers method to dynamically adjust QoS profiles
- Introduced qos_profile_cache to store and reuse QoS profiles
- Modified get_raw_message_from_topic to use cached QoS profiles
tests/messages/test_transport.py - Added TestPublisher class for creating test publishers
- Implemented test_transport function to verify message retrieval
- Created publishers for Image and String messages

Sequence Diagram

sequenceDiagram
    participant Node as RaiBaseNode
    participant Cache as QoS Profile Cache
    participant Publishers as Topic Publishers

    Node->>Publishers: Request Topic Endpoint Info
    Publishers-->>Node: Return Publisher QoS Profiles
    Node->>Node: adapt_requests_to_offers()
    Node->>Cache: Store Adapted QoS Profile
    Node->>Publishers: Subscribe with Adapted QoS
    Publishers-->>Node: Publish Messages
    Node->>Node: Retrieve Messages
Loading

The sequence diagram illustrates the new QoS profile adaptation process, showing how the RaiBaseNode dynamically adjusts its subscription QoS based on available publishers and caches the resulting profile for efficient message retrieval.

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/rai/rai/node.py (2)

292-340: Expand QoS matching logic if needed.
Currently, adapt_requests_to_offers accounts for reliability and durability but does not address potential conflicts with HistoryPolicy or LivelinessPolicy. This may be acceptable for your immediate use case. However, if comprehensive QoS matching is needed in the future, consider extending the logic to handle those fields.


348-353: Validate QoS usage for dynamic publisher changes.
Caching QoS profiles is a solid optimization. However, if the set of publishers changes (e.g., a new reliable publisher appears later), the node may continue to use an outdated QoS profile. Periodic refresh or a cache invalidation strategy can help maintain optimal QoS handling.

tests/messages/test_transport.py (2)

27-53: Confirm resource usage in tests.
This publisher repeatedly generates large random images. While it's acceptable for a short-running test, you might want to restrict image resolution or frequency in larger test suites to keep resource usage manageable.


55-69: Broad coverage, consider QoS mismatch tests.
This test checks basic message reception. Consider adding scenarios with deliberate QoS mismatches (e.g., a best-effort publisher and a reliable subscriber) to validate the newly introduced QoS adaptation logic more thoroughly.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f441e0 and b10954f.

📒 Files selected for processing (2)
  • src/rai/rai/node.py (3 hunks)
  • tests/messages/test_transport.py (1 hunks)
🔇 Additional comments (4)
src/rai/rai/node.py (4)

45-45: Good import.
Importing TopicEndpointInfo is a necessary step for retrieving QoS information from publishers.


272-272: Consider concurrency and cache refresh logic.
You might want to ensure that this cache stays consistent if new publishers appear with different QoS settings. Consider re-checking or clearing stale entries whenever the node discovers new endpoints so that new publishers' QoS settings are applied.


354-357: Efficient reuse of cached QoS.
Reusing a cached QoS profile here is beneficial for performance. Be mindful about whether further concurrency handling is needed if multiple threads invoke get_raw_message_from_topic simultaneously.


362-362: Correct QoS passing to wait_for_message.
Passing the computed QoS profile to the subscription-based helper is consistent with your new QoS matching mechanism.

@maciejmajek
Copy link
Member Author

maciejmajek commented Jan 2, 2025

image

QoS matching massively improved performance (latency, standard deviation)

@maciejmajek
Copy link
Member Author

image
In agriculture demo performance did not improve.

@maciejmajek
Copy link
Member Author

maciejmajek commented Jan 2, 2025

Default (no matching) subscriber qos

        self.qos_profile = QoSProfile(
            history=HistoryPolicy.KEEP_LAST,
            depth=1,
            reliability=ReliabilityPolicy.BEST_EFFORT,
            durability=DurabilityPolicy.VOLATILE,
            liveliness=LivelinessPolicy.AUTOMATIC,
        )

Manipulation image publisher

12:07:51 mmajek@robo-pc-054 ~ → ros2 topic info /color_image5 -v
Type: sensor_msgs/msg/Image

Publisher count: 1

Node name: o3de_ros2_node
Node namespace: /
Topic type: sensor_msgs/msg/Image
Topic type hash: RIHS01_d31d41a9a4c4bc8eae9be757b0beed306564f7526c88ea6a4588fb9582527d47
Endpoint type: PUBLISHER
GID: 01.0f.3b.3c.2e.ef.eb.b8.00.00.00.00.00.00.2b.03
QoS profile:
  Reliability: RELIABLE
  History (Depth): UNKNOWN
  Durability: VOLATILE
  Lifespan: Infinite
  Deadline: Infinite
  Liveliness: AUTOMATIC
  Liveliness lease duration: Infinite

Subscription count: 0

Performance gains can be attributed to changing subscriber's QoS from Best Effort to Reliable.

Publisher Subscriber
Before Reliable Best effort
After Reliable Reliable

Agriculture image publisher

12:06:50 mmajek@robo-pc-054 ~ → ros2 topic info /tractor1/camera_image_color -v
Type: sensor_msgs/msg/Image

Publisher count: 1

Node name: o3de_ros2_node
Node namespace: /
Topic type: sensor_msgs/msg/Image
Topic type hash: RIHS01_d31d41a9a4c4bc8eae9be757b0beed306564f7526c88ea6a4588fb9582527d47
Endpoint type: PUBLISHER
GID: 01.0f.3b.3c.ed.e9.48.8c.00.00.00.00.00.00.2e.03
QoS profile:
  Reliability: BEST_EFFORT
  History (Depth): UNKNOWN
  Durability: VOLATILE
  Lifespan: Infinite
  Deadline: Infinite
  Liveliness: AUTOMATIC
  Liveliness lease duration: Infinite

Subscription count: 0

No improvement is due to no change in qos settings.

Publisher Subscriber
Before Best effort Best effort
After Best effort Best effort

@maciejmajek
Copy link
Member Author

maciejmajek commented Jan 2, 2025

As shown before, performance gains are not guaranteed. Due to the nature of ROS 2 and it's subscriber-publisher design dynamic subscriptions are bound to be slower than their static counterpart due to discovery and subscription event overhead.

@@ -287,18 +289,77 @@ def discovery(self):
get_action_names_and_types(self),
)

def adapt_requests_to_offers(
Copy link
Member Author

Choose a reason for hiding this comment

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

src/rai/rai/node.py Outdated Show resolved Hide resolved
@maciejmajek maciejmajek requested a review from pijaro January 2, 2025 19:36
src/rai/rai/node.py Outdated Show resolved Hide resolved
@maciejmajek maciejmajek force-pushed the feat/qos-matching branch 2 times, most recently from 45625f9 to 1971b45 Compare January 7, 2025 12:25
Copy link
Member

@boczekbartek boczekbartek left a comment

Choose a reason for hiding this comment

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

Haven't tested yet, I'll continue the review. One small refactoring suggestion for now

tests/messages/test_transport.py Show resolved Hide resolved
Copy link
Member

@boczekbartek boczekbartek left a comment

Choose a reason for hiding this comment

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

I tried this feature with rosbot-xl demo.
Tested with my own topic, camera topics (color & depth) and nav2 costmap. All messages were retrieved by the agent without problems. Good job!

When all the comments to the code will be resolved I'll approve.

@maciejmajek
Copy link
Member Author

As discussed with @boczekbartek, we are merging this PR without the xfail change. Xfail will be added later.

@maciejmajek maciejmajek dismissed boczekbartek’s stale review January 9, 2025 15:24

Discussed outside of git

@maciejmajek maciejmajek merged commit 95e7124 into development Jan 9, 2025
5 checks passed
@maciejmajek maciejmajek deleted the feat/qos-matching branch January 9, 2025 15:24
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