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

python service cannot return int32[]

asked 2016-02-24 04:44:58 -0500

Slava gravatar image

updated 2016-02-25 06:11:36 -0500

gvdhoorn gravatar image

Hi all,

I'm trying to create a package (in Python) which contains a service that returns int32[] named 'ids'. Unfortunately it throws two exceptions in two scenarios:

  1. The Python's list contains 1 item. The exception: "NameError: global name '_x' is not defined:
  2. The Python's list contains more than 1 item. The exception: "Invalid number of arguments, args should be ['ids'] args are(1, 2)"

Please help!

FindItems.srv:

string type
string xml_data
---
int32[] ids

service:

import rospy
from pengo_srvs.srv import *

def on_find_items(req):
      return [1, 2, 3]

if __name__ == '__main__':
    node_name = "knowledge_representation"
    rospy.init_node(node_name, anonymous=True)
    service = rospy.Service("kr/find_items", FindItems, on_find_items)

    rospy.spin()

client:

import rospy, os, time
from pengo_srvs.srv import *

if __name__ == '__main__':
    node_name = "knowledge_representation_test"
    rospy.init_node(node_name, anonymous=True)

    service_name = "kr/find_items"
    rospy.wait_for_service(service_name)
    findItemsProxy  = rospy.ServiceProxy(service_name,  FindItems)

    nodeIDs = findItemsProxy.call("Node", "cvc")

Regards, Slava

edit retag flag offensive close merge delete

Comments

Please provide source code.

yasagitov gravatar image yasagitov  ( 2016-02-24 07:55:47 -0500 )edit

Done. Thanks!

Slava gravatar image Slava  ( 2016-02-25 05:16:57 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-02-25 06:07:41 -0500

yasagitov gravatar image

updated 2016-02-25 06:09:21 -0500

In service script you should replace return [1,2,3] with return FindItemsResponse([1, 2, 3]) You should return appropriate types.

edit flag offensive delete link more

Comments

1

@asagitov, thank you very much for help. I did not mention that in the documentation. Moreover I've tried to return several simple types and it worked w/o the wrapper!

Slava gravatar image Slava  ( 2016-02-25 12:20:39 -0500 )edit

Question Tools

Stats

Asked: 2016-02-24 04:44:58 -0500

Seen: 1,300 times

Last updated: Feb 25 '16