Service return array of arrays
UPDATED AFTER VERY HELPFUL RESPONSE FROM Weasfas:
I have created a service which I want to return and array which contains array elements of the following structure:
[
['/turtle1/color_sensor', 'turtlesim/Color'],
['/client_count', 'std_msgs/Int32'],
['/rosout', 'rosgraph_msgs/Log'],
]
To achieve the structure, I created the following message type, Topic.msg :
string name
string type
And in my FetchTopics.srv file I defined the request, response of my service as follows:
---
Topic[] topics
Catkin_make executes successfully. When I call my service I get the following error:
ERROR: service [/fetch_topics] responded with an error: error processing request: Invalid number of arguments, args should be ['topics'] args are(['/turtle1/color_sensor', 'turtlesim/Color'], ['/client_count', 'std_msgs/Int32'], ['/rosout', 'rosgraph_msgs/Log'])
Here is the code in my topics_server.py:
from topics_lister.srv import FetchTopics, FetchTopicsResponse
import rospy
from topics_lister.msg import Topic
def sendTopics(request):
# print("%s" %request)
print("_________________________")
return FetchTopicsResponse(
['/turtle1/color_sensor', 'turtlesim/Color'],
['/client_count', 'std_msgs/Int32'],
['/rosout', 'rosgraph_msgs/Log'],
)
rospy.init_node('fetch_topics_server')
s = rospy.Service('fetch_topics', FetchTopics, sendTopics)
print ("Serving topics ...")
rospy.spin()
Can someone tell me if my approach is correct and if it is, how do I solve the error above ?