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 script1.py (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():
rospy.init_node('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
rospy.spin()
if __name__ == "__main__":
get_pose_array_server()
On the other side in script2.py 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():
rospy.wait_for_service('get_pose_array')
try:
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__":
get_pose_array_client()