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

rosservice geometry_msgs/Posearray example

asked 2019-04-12 07:38:43 -0500

ArunPrasanth gravatar image

So, I'm getting an array of poses from the robot(from a python script say And I want this array of poses to be used in another python script( I would like to use rosservice to do so. Whenever I request the service from it should give me the array of poses from Is this possible? How it works? I have read the tutorials and , but I'm not sure to proceed for this particular message type. I cannot find any examples to look into. Also when I save the array of poses as a PoseArray in, Should I also save the header too? I'm bit confused here. Can someone give an hint here? Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-04-12 09:12:47 -0500

pavel92 gravatar image

updated 2019-04-12 09:15:25 -0500

This is definitely possible. You would need to create your custom service which will contain the pose array msg as a response. A service description file consists of a request and a response msg type. Since in your case you just need to receive the array on a service call you will not need a request (it will act as trigger srv) and the response should contain the pose array. For example this can be your bare bone service description:

geometry_msgs/PoseArray arr

You can name this srv file as getPoseArray.srv (check again the service creation tutorial for this).

The geometry_msgs/PoseArray msg contains a header and array of poses. When you create/save the array of poses in (I guess you are using a global variable for this, for example my_array) and you can also populate the header (especially the frame_id since you are dealing with poses). You will need to advertise the service where in the service callback you will just return the pose array (check again the service/client tutorials)). In python it will look something like this:

#!/usr/bin/env python

import rospy
from your_package.srv import getPoseArray
from geometry_msgs.msg import PoseArray

def handle_get_pose_array(req):
    return getPoseArrayResponse(my_array)

def get_pose_array_server():
    s =rospy.Service('get_pose_array', getPoseArray, handle_get_pose_array)

   my_array = PoseArray()
   my_array.header.frame_id = some_frame
   my_array.poses = ... # assign/populate here


if __name__ == "__main__":

On the other side in you need to create the client and call the service:

#!/usr/bin/env python

import rospy
from your_package.srv import getPoseArray
from geometry_msgs.msg import PoseArray

def get_pose_array_client():
        client_handle = rospy.ServiceProxy('get_pose_array', getPoseArray)
        resp1 = client_handle()
        return resp1.arr
    except rospy.ServiceException, e:
        print "Service call failed: %s"%e

if __name__ == "__main__":
edit flag offensive delete link more

Question Tools



Asked: 2019-04-12 07:38:43 -0500

Seen: 3,903 times

Last updated: Apr 12 '19