From a00022648c92b8dab0284d19b0141bfbc8b3bd03 Mon Sep 17 00:00:00 2001 From: Lebecque Florian Date: Sat, 4 Jan 2025 20:06:39 +0100 Subject: [PATCH] Add new service to retrieve the different interfaces in the ROS Network (#988) --- rosapi/scripts/rosapi_node | 7 +++++++ rosapi/src/rosapi/proxy.py | 6 ++++++ rosapi_msgs/CMakeLists.txt | 1 + rosapi_msgs/srv/Interfaces.srv | 2 ++ 4 files changed, 16 insertions(+) create mode 100644 rosapi_msgs/srv/Interfaces.srv diff --git a/rosapi/scripts/rosapi_node b/rosapi/scripts/rosapi_node index af478ee52..013b0729a 100755 --- a/rosapi/scripts/rosapi_node +++ b/rosapi/scripts/rosapi_node @@ -48,6 +48,7 @@ from rosapi_msgs.srv import ( GetROSVersion, GetTime, HasParam, + Interfaces, MessageDetails, NodeDetails, Nodes, @@ -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..48ed7835f 100644 --- a/rosapi/src/rosapi/proxy.py +++ b/rosapi/src/rosapi/proxy.py @@ -31,6 +31,7 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +from ros2interface.api import type_completer from ros2node.api import ( get_node_names, get_publisher_info, @@ -60,6 +61,11 @@ def get_topics(topics_glob, include_hidden=False): 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( topics_glob, get_topic_names_and_types, include_hidden_topics=include_hidden 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..53355592a --- /dev/null +++ b/rosapi_msgs/srv/Interfaces.srv @@ -0,0 +1,2 @@ +--- +string[] interfaces