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

Printing out service object error

asked 2020-12-30 22:02:27 -0500

sisko gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-01-01 03:28:47 -0500

gvdhoorn gravatar image
def print_map_data(req):
    print "Returning [%s]"%(req.info.resolution)

The first (and only) field at the top-level of the nav_msgs/GetMap service is map:

# Get the map as a nav_msgs/OccupancyGrid
---
nav_msgs/OccupancyGrid map

the map field then contains the header, info and the data fields.

So you'd need to change your callback to:

def print_map_data(req):
    print "Returning [%s]"%(req.map.info.resolution)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-12-30 22:02:27 -0500

Seen: 178 times

Last updated: Jan 01 '21