Skip to content

Commit 12d8e79

Browse files
Migrate qos functions to ros2cli.node
1 parent 3fe424c commit 12d8e79

4 files changed

Lines changed: 90 additions & 64 deletions

File tree

ros2cli/ros2cli/node/qos.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright 2017 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from time import sleep
16+
from typing import Optional
17+
18+
import rclpy
19+
20+
from argparse import ArgumentParser
21+
from rclpy.expand_topic_name import expand_topic_name
22+
from rclpy.topic_or_service_is_hidden import topic_or_service_is_hidden
23+
from rclpy.validate_full_topic_name import validate_full_topic_name
24+
from rosidl_runtime_py import get_message_interfaces
25+
from rosidl_runtime_py import message_to_yaml
26+
from rosidl_runtime_py.utilities import get_message
27+
28+
29+
def profile_configure_short_keys(
30+
profile: rclpy.qos.QoSProfile = None, reliability: str = None,
31+
durability: str = None, depth: Optional[int] = None, history: str = None,
32+
) -> rclpy.qos.QoSProfile:
33+
"""Configure a QoSProfile given a profile, and optional overrides."""
34+
if history:
35+
profile.history = rclpy.qos.QoSHistoryPolicy.get_from_short_key(history)
36+
if durability:
37+
profile.durability = rclpy.qos.QoSDurabilityPolicy.get_from_short_key(durability)
38+
if reliability:
39+
profile.reliability = rclpy.qos.QoSReliabilityPolicy.get_from_short_key(reliability)
40+
if depth and depth >= 0:
41+
profile.depth = depth
42+
else:
43+
if (profile.durability == rclpy.qos.QoSDurabilityPolicy.TRANSIENT_LOCAL
44+
and profile.depth == 0):
45+
profile.depth = 1
46+
47+
48+
def qos_profile_from_short_keys(
49+
preset_profile: str, reliability: str = None, durability: str = None,
50+
depth: Optional[int] = None, history: str = None,
51+
) -> rclpy.qos.QoSProfile:
52+
"""Construct a QoSProfile given the name of a preset, and optional overrides."""
53+
# Build a QoS profile based on user-supplied arguments
54+
profile = rclpy.qos.QoSPresetProfiles.get_from_short_key(preset_profile)
55+
profile_configure_short_keys(profile, reliability, durability, depth, history)
56+
return profile
57+
58+
59+
def add_qos_arguments(parser: ArgumentParser, default_profile_str: str):
60+
parser.add_argument(
61+
'--qos-profile',
62+
choices=rclpy.qos.QoSPresetProfiles.short_keys(),
63+
default=default_profile_str,
64+
help='Quality of service preset profile to subscribe with (default: {})'
65+
.format(default_profile_str))
66+
default_profile = rclpy.qos.QoSPresetProfiles.get_from_short_key(default_profile_str)
67+
parser.add_argument(
68+
'--qos-depth', metavar='N', type=int,
69+
help='Queue size setting to subscribe with '
70+
'(overrides depth value of --qos-profile option)')
71+
parser.add_argument(
72+
'--qos-history',
73+
choices=rclpy.qos.QoSHistoryPolicy.short_keys(),
74+
help='History of samples setting to subscribe with '
75+
'(overrides history value of --qos-profile option, default: {})'
76+
.format(default_profile.history.short_key))
77+
parser.add_argument(
78+
'--qos-reliability',
79+
choices=rclpy.qos.QoSReliabilityPolicy.short_keys(),
80+
help='Quality of service reliability setting to subscribe with '
81+
'(overrides reliability value of --qos-profile option, default: '
82+
'Automatically match existing publishers )')
83+
parser.add_argument(
84+
'--qos-durability',
85+
choices=rclpy.qos.QoSDurabilityPolicy.short_keys(),
86+
help='Quality of service durability setting to subscribe with '
87+
'(overrides durability value of --qos-profile option, default: '
88+
'Automatically match existing publishers )')

ros2service/ros2service/verb/call.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import rclpy
1919
from rclpy.qos import QoSPresetProfiles
2020
from ros2cli.node import NODE_NAME_PREFIX
21+
from ros2cli.node.qos import profile_configure_short_keys, add_qos_arguments
2122
from ros2service.api import ServiceNameCompleter
2223
from ros2service.api import ServicePrototypeCompleter
2324
from ros2service.api import ServiceTypeCompleter
24-
from ros2topic.api import profile_configure_short_keys, add_qos_arguments
2525
from ros2service.verb import VerbExtension
2626
from rosidl_runtime_py import set_message_fields
2727
import yaml

ros2topic/ros2topic/api/__init__.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -155,65 +155,3 @@ def __init__(self, *, topic_type_key=None):
155155
def __call__(self, prefix, parsed_args, **kwargs):
156156
message = get_message(getattr(parsed_args, self.topic_type_key))
157157
return [message_to_yaml(message())]
158-
159-
160-
def profile_configure_short_keys(
161-
profile: rclpy.qos.QoSProfile = None, reliability: str = None,
162-
durability: str = None, depth: Optional[int] = None, history: str = None,
163-
) -> rclpy.qos.QoSProfile:
164-
"""Configure a QoSProfile given a profile, and optional overrides."""
165-
if history:
166-
profile.history = rclpy.qos.QoSHistoryPolicy.get_from_short_key(history)
167-
if durability:
168-
profile.durability = rclpy.qos.QoSDurabilityPolicy.get_from_short_key(durability)
169-
if reliability:
170-
profile.reliability = rclpy.qos.QoSReliabilityPolicy.get_from_short_key(reliability)
171-
if depth and depth >= 0:
172-
profile.depth = depth
173-
else:
174-
if (profile.durability == rclpy.qos.QoSDurabilityPolicy.TRANSIENT_LOCAL
175-
and profile.depth == 0):
176-
profile.depth = 1
177-
178-
179-
def qos_profile_from_short_keys(
180-
preset_profile: str, reliability: str = None, durability: str = None,
181-
depth: Optional[int] = None, history: str = None,
182-
) -> rclpy.qos.QoSProfile:
183-
"""Construct a QoSProfile given the name of a preset, and optional overrides."""
184-
# Build a QoS profile based on user-supplied arguments
185-
profile = rclpy.qos.QoSPresetProfiles.get_from_short_key(preset_profile)
186-
profile_configure_short_keys(profile, reliability, durability, depth, history)
187-
return profile
188-
189-
190-
def add_qos_arguments(parser, default_profile_str):
191-
parser.add_argument(
192-
'--qos-profile',
193-
choices=rclpy.qos.QoSPresetProfiles.short_keys(),
194-
default=default_profile_str,
195-
help='Quality of service preset profile to subscribe with (default: {})'
196-
.format(default_profile_str))
197-
default_profile = rclpy.qos.QoSPresetProfiles.get_from_short_key(default_profile_str)
198-
parser.add_argument(
199-
'--qos-depth', metavar='N', type=int,
200-
help='Queue size setting to subscribe with '
201-
'(overrides depth value of --qos-profile option)')
202-
parser.add_argument(
203-
'--qos-history',
204-
choices=rclpy.qos.QoSHistoryPolicy.short_keys(),
205-
help='History of samples setting to subscribe with '
206-
'(overrides history value of --qos-profile option, default: {})'
207-
.format(default_profile.history.short_key))
208-
parser.add_argument(
209-
'--qos-reliability',
210-
choices=rclpy.qos.QoSReliabilityPolicy.short_keys(),
211-
help='Quality of service reliability setting to subscribe with '
212-
'(overrides reliability value of --qos-profile option, default: '
213-
'Automatically match existing publishers )')
214-
parser.add_argument(
215-
'--qos-durability',
216-
choices=rclpy.qos.QoSDurabilityPolicy.short_keys(),
217-
help='Quality of service durability setting to subscribe with '
218-
'(overrides durability value of --qos-profile option, default: '
219-
'Automatically match existing publishers )')

ros2topic/ros2topic/verb/echo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
from rclpy.task import Future
2828
from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments
2929
from ros2cli.node.strategy import NodeStrategy
30+
from ros2cli.node.qos import qos_profile_from_short_keys, add_qos_arguments
3031
from ros2topic.api import get_msg_class
31-
from ros2topic.api import qos_profile_from_short_keys, add_qos_arguments
3232
from ros2topic.api import TopicNameCompleter
3333
from ros2topic.api import unsigned_int
3434
from ros2topic.verb import VerbExtension

0 commit comments

Comments
 (0)