-
Notifications
You must be signed in to change notification settings - Fork 42
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
Added qos autodetect #76
Merged
gonzodepedro
merged 3 commits into
ros-visualization:foxy-devel
from
gonzodepedro:gonzodepedro/qos-autodetect
Aug 17, 2021
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,10 @@ | |
import threading | ||
import time | ||
|
||
from rclpy.qos import QoSDurabilityPolicy | ||
from rclpy.qos import QoSProfile | ||
from rosidl_runtime_py.utilities import get_message | ||
from rclpy.qos import QoSReliabilityPolicy | ||
from rqt_py_common.message_helpers import get_message_class | ||
from std_msgs.msg import Bool | ||
from python_qt_binding.QtCore import qWarning | ||
|
||
|
@@ -101,12 +103,56 @@ def __init__(self, node, topic, start_time): | |
topic_type, real_topic, fields = get_topic_type(node, topic) | ||
if topic_type is not None: | ||
self.field_evals = generate_field_evals(fields) | ||
data_class = get_message(topic_type) | ||
data_class = get_message_class(topic_type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this change? IMO, it seems like a backwards step. I would prefer to use the utility further upstream, all else being equal. |
||
self.sub = node.create_subscription( | ||
data_class, real_topic, self._ros_cb, qos_profile=QoSProfile(depth=10)) | ||
data_class, real_topic, self._ros_cb, qos_profile=self.choose_qos(node, real_topic)) | ||
else: | ||
self.error = RosPlotException("Can not resolve topic type of %s" % topic) | ||
|
||
def choose_qos(self, node, topic_name): | ||
|
||
qos_profile=QoSProfile(depth=10) | ||
reliability_reliable_endpoints_count = 0 | ||
durability_transient_local_endpoints_count = 0 | ||
pubs_info = node.get_publishers_info_by_topic(topic_name) | ||
publishers_count = len(pubs_info) | ||
|
||
if publishers_count == 0: | ||
return qos_profile | ||
|
||
for info in pubs_info: | ||
if (info.qos_profile.reliability == QoSReliabilityPolicy.RELIABLE): | ||
reliability_reliable_endpoints_count += 1 | ||
if (info.qos_profile.durability == QoSDurabilityPolicy.TRANSIENT_LOCAL): | ||
durability_transient_local_endpoints_count += 1 | ||
|
||
# If all endpoints are reliable, ask for reliable | ||
if reliability_reliable_endpoints_count == publishers_count: | ||
qos_profile.reliability = QoSReliabilityPolicy.RELIABLE | ||
else: | ||
if reliability_reliable_endpoints_count > 0: | ||
print( | ||
'Some, but not all, publishers are offering ' | ||
'QoSReliabilityPolicy.RELIABLE. Falling back to ' | ||
'QoSReliabilityPolicy.BEST_EFFORT as it will connect ' | ||
'to all publishers' | ||
) | ||
qos_profile.reliability = QoSReliabilityPolicy.BEST_EFFORT | ||
|
||
# If all endpoints are transient_local, ask for transient_local | ||
if durability_transient_local_endpoints_count == publishers_count: | ||
qos_profile.durability = QoSDurabilityPolicy.TRANSIENT_LOCAL | ||
else: | ||
if durability_transient_local_endpoints_count > 0: | ||
print( | ||
'Some, but not all, publishers are offering ' | ||
'QoSDurabilityPolicy.TRANSIENT_LOCAL. Falling back to ' | ||
'QoSDurabilityPolicy.VOLATILE as it will connect ' | ||
'to all publishers' | ||
) | ||
qos_profile.durability = QoSDurabilityPolicy.VOLATILE | ||
return qos_profile | ||
|
||
def close(self): | ||
self.node.destroy_subscription(self.sub) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to also undo the change to the imports. We're using
get_message
fromrosidl_runtime_py
instead ofget_message_class
.