|
19 | 19 | from rclpy.event_handler import SubscriptionEventCallbacks |
20 | 20 | from rclpy.event_handler import UnsupportedEventTypeError |
21 | 21 | from rclpy.node import Node |
22 | | -from rclpy.qos import QoSDurabilityPolicy |
23 | | -from rclpy.qos import QoSPresetProfiles |
24 | 22 | from rclpy.qos import QoSProfile |
25 | | -from rclpy.qos import QoSReliabilityPolicy |
26 | 23 | from rclpy.task import Future |
27 | 24 | from ros2cli.helpers import unsigned_int |
28 | 25 | from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments |
29 | 26 | from ros2cli.node.strategy import NodeStrategy |
30 | 27 | from ros2topic.api import add_qos_arguments |
| 28 | +from ros2topic.api import choose_qos |
31 | 29 | from ros2topic.api import get_msg_class |
32 | 30 | from ros2topic.api import positive_float |
33 | | -from ros2topic.api import qos_profile_from_short_keys |
34 | 31 | from ros2topic.api import TopicNameCompleter |
35 | 32 | from ros2topic.verb import VerbExtension |
36 | 33 | from rosidl_runtime_py import message_to_csv |
@@ -116,67 +113,6 @@ def add_arguments(self, parser, cli_name): |
116 | 113 | '-n', '--node-name', type=str, default=None, |
117 | 114 | help='The name of the echoing node; by default, will be a hidden node name') |
118 | 115 |
|
119 | | - def choose_qos(self, node, args): |
120 | | - |
121 | | - if (args.qos_reliability is not None or |
122 | | - args.qos_durability is not None or |
123 | | - args.qos_depth is not None or |
124 | | - args.qos_history is not None or |
125 | | - args.qos_liveliness is not None or |
126 | | - args.qos_liveliness_lease_duration_seconds is not None): |
127 | | - |
128 | | - return qos_profile_from_short_keys( |
129 | | - args.qos_profile, |
130 | | - reliability=args.qos_reliability, |
131 | | - durability=args.qos_durability, |
132 | | - depth=args.qos_depth, |
133 | | - history=args.qos_history, |
134 | | - liveliness=args.qos_liveliness, |
135 | | - liveliness_lease_duration_s=args.qos_liveliness_lease_duration_seconds) |
136 | | - |
137 | | - qos_profile = QoSPresetProfiles.get_from_short_key(args.qos_profile) |
138 | | - reliability_reliable_endpoints_count = 0 |
139 | | - durability_transient_local_endpoints_count = 0 |
140 | | - |
141 | | - pubs_info = node.get_publishers_info_by_topic(args.topic_name) |
142 | | - publishers_count = len(pubs_info) |
143 | | - if publishers_count == 0: |
144 | | - return qos_profile |
145 | | - |
146 | | - for info in pubs_info: |
147 | | - if (info.qos_profile.reliability == QoSReliabilityPolicy.RELIABLE): |
148 | | - reliability_reliable_endpoints_count += 1 |
149 | | - if (info.qos_profile.durability == QoSDurabilityPolicy.TRANSIENT_LOCAL): |
150 | | - durability_transient_local_endpoints_count += 1 |
151 | | - |
152 | | - # If all endpoints are reliable, ask for reliable |
153 | | - if reliability_reliable_endpoints_count == publishers_count: |
154 | | - qos_profile.reliability = QoSReliabilityPolicy.RELIABLE |
155 | | - else: |
156 | | - if reliability_reliable_endpoints_count > 0: |
157 | | - print( |
158 | | - 'Some, but not all, publishers are offering ' |
159 | | - 'QoSReliabilityPolicy.RELIABLE. Falling back to ' |
160 | | - 'QoSReliabilityPolicy.BEST_EFFORT as it will connect ' |
161 | | - 'to all publishers' |
162 | | - ) |
163 | | - qos_profile.reliability = QoSReliabilityPolicy.BEST_EFFORT |
164 | | - |
165 | | - # If all endpoints are transient_local, ask for transient_local |
166 | | - if durability_transient_local_endpoints_count == publishers_count: |
167 | | - qos_profile.durability = QoSDurabilityPolicy.TRANSIENT_LOCAL |
168 | | - else: |
169 | | - if durability_transient_local_endpoints_count > 0: |
170 | | - print( |
171 | | - 'Some, but not all, publishers are offering ' |
172 | | - 'QoSDurabilityPolicy.TRANSIENT_LOCAL. Falling back to ' |
173 | | - 'QoSDurabilityPolicy.VOLATILE as it will connect ' |
174 | | - 'to all publishers' |
175 | | - ) |
176 | | - qos_profile.durability = QoSDurabilityPolicy.VOLATILE |
177 | | - |
178 | | - return qos_profile |
179 | | - |
180 | 116 | def main(self, *, args): |
181 | 117 |
|
182 | 118 | self.csv = args.csv |
@@ -210,7 +146,7 @@ def main(self, *, args): |
210 | 146 |
|
211 | 147 | with NodeStrategy(args, node_name=args.node_name) as node: |
212 | 148 |
|
213 | | - qos_profile = self.choose_qos(node, args) |
| 149 | + qos_profile = choose_qos(node, topic_name=args.topic_name, qos_args=args) |
214 | 150 |
|
215 | 151 | if args.message_type is None: |
216 | 152 | message_type = get_msg_class( |
|
0 commit comments