ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Array as response in service

asked 2015-02-08 22:40:02 -0500

genericsoup gravatar image

updated 2015-02-09 05:01:35 -0500

I'm trying to create a service that returns an array of a custom msg. However, when I call this using roservice call /myservice [input params...] I get the following error:

ERROR: service [/myservice] responded with an error: service cannot process request: handler returned wrong number of values: Invalid number of arguments, args should be ['parsed'] args are(operation: travel_to
target: a1
time_step: 0, operation:open ... )

Based on this I assumed that the type I was returning was wrong, so outputted the type just before the return statement in Python, however they seem to be what I expect them to be based on the documentation here

type: type 'list'
element type: class 'asp_model.msg._SubGoal.SubGoal'

.srv file

string goal
string entityA
string entityB
Subgoal[] parsed
.msg file
string operation
string target
int16 time_step

Some additional info: I also tried simply returning a list of integers [1, 2, 3], which with the response type set to Int16[] which resulted in the same error. I'm running on ROS Hydro, Ubuntu 12.04, no other errors show up when running catkin_make or running the server

Any ideas on how to go about fixing this? I'm not sure if I'm completely misunderstanding the error message!

Edit1: Python on server, I've removed code indicated by the '...' as its some lengthy regex and string parsing stuff:

    def parse_answer(self, raw):
        parsed = []  # Use this to save list of SubGoals
        for step in anslist:
            if step:
                parsed.append(SubGoal(operation=operation[0], target=target[0], time_step=int(time_step)))

        return parsed

edit retag flag offensive close merge delete



Please post the python code for your server. I suspect you're returning the wrong type.

ahendrix gravatar image ahendrix  ( 2015-02-09 00:40:44 -0500 )edit

Edited question to include relevant code - unsure if you get a notification when I edit, hence the comment. Thanks :)

genericsoup gravatar image genericsoup  ( 2015-02-09 05:05:14 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-02-09 06:19:56 -0500

BennyRe gravatar image

@ahendrix is right. You returned the wrong type.

Have a detailed look at the python service tutorial.

You have to return an instance of <YourServiceType>Response instead of a list of SubGoal. In this Response you can store the SubGoals.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-02-08 22:40:02 -0500

Seen: 5,197 times

Last updated: Feb 09 '15