Printing out service object error
I am working on an exercise which requires that I output the dimensions and resolution of map data to the command-line output.
I am calling the static_map
service from python code but when I try printing the required output I get Service has no attribute info type messages. The following is my code:
#!/usr/bin/env python
import rospy
from nav_msgs.srv import GetMap
def print_map_data(req):
print "Returning [%s]"%(req.info.resolution)
def read_map_service():
rospy.init_node('my_map_service_reader')
s = rospy.Service('/static_map', GetMap, print_map_data)
print "Ready to print ...."
rospy.loginfo("Ready to print ....")
rospy.spin()
if __name__ == "__main__":
read_map_service()
I have confirmed the structure of the service object by running rossrv show nav_msgs/GetMap
and getting the following:
---
nav_msgs/OccupancyGrid map
std_msgs/Header header
uint32 seq
time stamp
string frame_id
nav_msgs/MapMetaData info
time map_load_time
float32 resolution
uint32 width
uint32 height
geometry_msgs/Pose origin
geometry_msgs/Point position
float64 x
float64 y
float64 z
geometry_msgs/Quaternion orientation
float64 x
float64 y
float64 z
float64 w
int8[] data
I would appreciate help in understanding what I'm doing wrong or missing here.