2323from ros2node .api import get_node_names
2424from ros2node .api import NodeNameCompleter
2525from ros2param .verb import VerbExtension
26+ from ros2service .api import get_service_names
2627
2728
2829class 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