Skip to content

Commit

Permalink
Add new service to retreive the different interfaces in the ROS Network
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLebecque committed Jan 2, 2025
1 parent ffa2675 commit 46e0111
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rosapi/scripts/rosapi_node
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ from rosapi_msgs.srv import (
TopicsAndRawTypes,
TopicsForType,
TopicType,
Interfaces,
)


Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions rosapi/src/rosapi/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -258,3 +264,4 @@ def get_service_node(queried_type, services_glob, include_hidden=False):
return node_name[0]
else:
return ""

1 change: 1 addition & 0 deletions rosapi_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rosapi_msgs/srv/Interfaces.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
string[] interfaces

0 comments on commit 46e0111

Please sign in to comment.