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

Autodetect QoS #806

Open
wants to merge 3 commits into
base: rolling
Choose a base branch
from
Open

Autodetect QoS #806

wants to merge 3 commits into from

Conversation

fmrico
Copy link

@fmrico fmrico commented Dec 5, 2021

Dear RViz2 developers,

This PR contains a way to determine the topic QoS when subscribing to a topic.

I would appreciate the opinion of @LoyVanBeek and @zmk5, because we were talking about this in this thread and maybe they want to contribute to this PR.

I hope it helps!!

Signed-off-by: Francisco Martín Rico fmrico@gmail.com

Signed-off-by: Francisco Martín Rico <fmrico@gmail.com>
Signed-off-by: Francisco Martín Rico <fmrico@gmail.com>
Signed-off-by: Francisco Martín Rico <fmrico@gmail.com>
@LoyVanBeek
Copy link

LoyVanBeek commented Dec 6, 2021

Seems to work!

I tested this briefly from ipython

import rclpy
from rclpy.node import Node
from rclpy.qos import DurabilityPolicy, HistoryPolicy, LivelinessPolicy, HistoryPolicy, QoSProfile, qos_profile_sensor_data
from sensor_msgs.msg import LaserScan

rclpy.init()
node = Node('ipython')
rclpy.spin_once(node, timeout_sec=0.01)
node.create_publisher(LaserScan, 'laser', qos_profile_sensor_data)

weird_qos = QoSProfile(history=HistoryPolicy.KEEP_ALL, durability=DurabilityPolicy.TRANSIENT_LOCAL)

node.create_publisher(LaserScan, 'weird_laser', weird_qos)
rclpy.spin_once(node, timeout_sec=0.01)

and indeed the weird QoS settings are automatically set in RViz if you add the topics laser and weird_laser in RViz 👍 👍

Looks good to me!

@fmrico
Copy link
Author

fmrico commented Jan 4, 2022

Dear @ivanpauno @clalancette

Any comment about this PR? Do you think it is useful/valid? Any improvement that you want I do.

Thanks!!

// Check if there is any Subscriber with the same QoS as set
bool any_publisher_qos_compatible = false;
for (const auto & publisher : publishers) {
if (qos_profile == publisher.qos_profile()) {
Copy link
Member

Choose a reason for hiding this comment

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

The profile doesn't have to be the same in order to be compatible.
We should check for compatibility instead.

There's https://github.com/ros2/rmw/blob/05f973575e8e93454e39f51da6227509061ff189/rmw/include/rmw/qos_profiles.h#L176.

There's no rclcpp wrapper, so you can either use the rmw function directly or add one.

Comment on lines +121 to +124
if (!any_publisher_qos_compatible) {
qos_profile = publishers[0].qos_profile();
qos_profile_property_->setQoSProfile(qos_profile);
}
Copy link
Member

Choose a reason for hiding this comment

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

This is not great, because e.g. if you pick RELIABLE reliability and there was another published that used BEST_EFFORT, you're going to only match the first one.
Whereas if you picked BEST_EFFORT for the subscription, that was going to match both publishers.

In practice, having more than one publisher in the same topic with different reliability is not a good idea, and when that's found the best thing to do is warn the user.
Anyways if we need to pick one default in those cases, it should be the one that matches the most cases.
For durability, if we find publishers with different settings we should pick VOLATILE, which matches all publisher.

Copy link
Member

Choose a reason for hiding this comment

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

I think you can find an example of this logic in ros2/ros2cli#653

@clalancette clalancette added the more-information-needed Further information is required label Jan 20, 2022
@audrow audrow changed the base branch from ros2 to rolling June 28, 2022 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants