Skip to content

Commit 0b75d70

Browse files
authored
fix param list for nodes which don't have the service (#265)
Signed-off-by: Dirk Thomas <[email protected]>
1 parent 2de6f09 commit 0b75d70

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

ros2param/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<depend>ros2cli</depend>
1515

1616
<exec_depend>ros2node</exec_depend>
17+
<exec_depend>ros2service</exec_depend>
1718

1819
<test_depend>ament_copyright</test_depend>
1920
<test_depend>ament_flake8</test_depend>

ros2param/ros2param/verb/list.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ros2node.api import get_node_names
2424
from ros2node.api import NodeNameCompleter
2525
from ros2param.verb import VerbExtension
26+
from ros2service.api import get_service_names
2627

2728

2829
class ListVerb(VerbExtension):
@@ -54,18 +55,23 @@ def main(self, *, args): # noqa: D102
5455
n for n in node_names if node_name == n.full_name]
5556

5657
with DirectNode(args) as node:
58+
service_names = get_service_names(node=node)
59+
5760
clients = {}
5861
futures = {}
59-
# create clients
62+
# create clients for nodes which have the service
6063
for node_name in node_names:
61-
client = node.create_client(
62-
ListParameters,
63-
'{node_name.full_name}/list_parameters'.format_map(locals()))
64-
clients[node_name] = client
64+
service_name = '{node_name.full_name}/list_parameters' \
65+
.format_map(locals())
66+
if service_name in service_names:
67+
client = node.create_client(ListParameters, service_name)
68+
clients[node_name] = client
6569

6670
# wait until all clients have been called
6771
while True:
68-
for node_name in [n for n in node_names if n not in futures]:
72+
for node_name in [
73+
n for n in clients.keys() if n not in futures
74+
]:
6975
# call as soon as ready
7076
client = clients[node_name]
7177
if client.service_is_ready():
@@ -80,8 +86,8 @@ def main(self, *, args): # noqa: D102
8086
rclpy.spin_once(node, timeout_sec=1.0)
8187

8288
# wait for all responses
83-
for node_name in node_names:
84-
rclpy.spin_until_future_complete(node, futures[node_name])
89+
for future in futures.values():
90+
rclpy.spin_until_future_complete(node, future)
8591

8692
# print responses
8793
for node_name in sorted(futures.keys()):

0 commit comments

Comments
 (0)