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 12ef35c
Show file tree
Hide file tree
Showing 4 changed files with 16 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 @@ -48,6 +48,7 @@ from rosapi_msgs.srv import (
GetROSVersion,
GetTime,
HasParam,
Interfaces,
MessageDetails,
NodeDetails,
Nodes,
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions rosapi/src/rosapi/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
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 12ef35c

Please sign in to comment.