From 46e01118d0728c50413d532033e63d6e309a1b7e Mon Sep 17 00:00:00 2001 From: Florian Lebecque Date: Thu, 2 Jan 2025 16:26:56 +0100 Subject: [PATCH] Add new service to retreive the different interfaces in the ROS Network --- rosapi/scripts/rosapi_node | 7 +++++++ rosapi/src/rosapi/proxy.py | 7 +++++++ rosapi_msgs/CMakeLists.txt | 1 + rosapi_msgs/srv/Interfaces.srv | 2 ++ 4 files changed, 17 insertions(+) create mode 100644 rosapi_msgs/srv/Interfaces.srv diff --git a/rosapi/scripts/rosapi_node b/rosapi/scripts/rosapi_node index af478ee52..b71843fdc 100755 --- a/rosapi/scripts/rosapi_node +++ b/rosapi/scripts/rosapi_node @@ -65,6 +65,7 @@ from rosapi_msgs.srv import ( TopicsAndRawTypes, TopicsForType, TopicType, + Interfaces, ) @@ -89,6 +90,7 @@ class Rosapi(Node): full_name = self.get_namespace() + "/" + self.get_name() params.init(full_name) self.create_service(Topics, "/rosapi/topics", self.get_topics) + self.create_service(Interfaces, "/rosapi/interfaces", self.get_interfaces) self.create_service(TopicsForType, "/rosapi/topics_for_type", self.get_topics_for_type) self.create_service( TopicsAndRawTypes, @@ -137,6 +139,11 @@ class Rosapi(Node): response.topics, response.types = proxy.get_topics_and_types(self.globs.topics) return response + def get_interfaces(self, request, response): + """Called by the rosapi/Types service. Returns a list of all the types in the system.""" + response.interfaces = proxy.get_interfaces() + return response + def get_topics_for_type(self, request, response): """Called by the rosapi/TopicsForType service. Returns a list of all the topics that are publishing a given type""" response.topics = proxy.get_topics_for_type(request.type, self.globs.topics) diff --git a/rosapi/src/rosapi/proxy.py b/rosapi/src/rosapi/proxy.py index c3bdbb4a0..086c73adc 100644 --- a/rosapi/src/rosapi/proxy.py +++ b/rosapi/src/rosapi/proxy.py @@ -40,6 +40,8 @@ from ros2service.api import get_service_names, get_service_names_and_types from ros2topic.api import get_topic_names, get_topic_names_and_types +from ros2interface.api import type_completer + from .glob_helper import any_match, filter_globs _node = None @@ -59,6 +61,10 @@ def get_topics(topics_glob, include_hidden=False): topic_names = get_topic_names(node=_node, include_hidden_topics=include_hidden) return filter_globs(topics_glob, topic_names) +def get_interfaces(): + """Returns a list of all the types in the ROS system""" + return type_completer() + def get_topics_and_types(topics_glob, include_hidden=False): return get_publications_and_types( @@ -258,3 +264,4 @@ def get_service_node(queried_type, services_glob, include_hidden=False): return node_name[0] else: return "" + diff --git a/rosapi_msgs/CMakeLists.txt b/rosapi_msgs/CMakeLists.txt index 477ab48e4..8764e26c8 100644 --- a/rosapi_msgs/CMakeLists.txt +++ b/rosapi_msgs/CMakeLists.txt @@ -14,6 +14,7 @@ rosidl_generate_interfaces(${PROJECT_NAME} srv/GetROSVersion.srv srv/GetTime.srv srv/HasParam.srv + srv/Interfaces.srv srv/MessageDetails.srv srv/Nodes.srv srv/NodeDetails.srv diff --git a/rosapi_msgs/srv/Interfaces.srv b/rosapi_msgs/srv/Interfaces.srv new file mode 100644 index 000000000..4221e0c87 --- /dev/null +++ b/rosapi_msgs/srv/Interfaces.srv @@ -0,0 +1,2 @@ +--- +string[] interfaces \ No newline at end of file