Reading data from a service via python
I need help understanding how to call and read from a service.
I created a package which launches the map_server node with a map I created from the gmapping node. I need to read data from the /static_map service (of type nav_msgs/GetMap) which is provided by map_server, using the following code:
#!/usr/bin/env python
import rospy
from nav_msgs.srv import GetMap
def printData(datas):
rospy.loginfo("printing : .... ")
return
def testing():
rospy.init_node('map_lists')
rospy.wait_for_service('static_map')
try:
rospy.ServiceProxy('GetMap', 'static_map')
except rospy.ServiceException as e:
rospy.logerr("Service call failed: %s"%e)
print "testing ... testing"
rospy.spin()
if __name__ == '__main__':
testing()
My problem is my printData callback is not being called because my ServiceProxy function call is wrong. The ServiceProxy api says ServiceProxy(name, service_class, persistent=False, headers=None)and I referred to https://answers.ros.org/question/2630... but neigther helped to clarify how to correctly call ServiceProxy.
I need help, please.
Just creating a service proxy doesn't call the service.
Please check the wiki and the basic tutorials and let us know if this solves your questions. Also, the answer you link also shows how to call it...
What exactly is missing for you?
Thank you for responding. To start with, how do I determin the "class that defines your service"? The first argument is the service name as a string i:e (/static_map) but how do I find the second argument the service class?
That's the type of service you want to call. I.e. the service definition detailing what's in the request and response part, respectively. Check out this section for more information.
When you have a system running and are interested in the service class, the standard ROS introspection tools will help you (i.e.
rosnode info
,rosservice list
,rosservice info
etc.).