How to call an msg file inside an srv file?

asked 2021-08-06 09:16:40 -0500

KhalidOwlWalid gravatar image

In the project I am currently working on, I am trying to call the /static_map service using python file. Generally, what I am trying to do is print the map from /static_map in which /static_map is of type nav_msgs/GetMap.

GetMap.srv on the other hand consists of:

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

My question is how can I print the map from the GetMap.srv file considering that OccupancyGrid is an msg file?

This is OccupancyGrid.msg file:

# This represents a 2-D grid map, in which each cell represents the probability of
# occupancy.

Header header

#MetaData for the map
MapMetaData info

# The map data, in row-major order, starting with (0,0).  Occupancy
# probabilities are in the range [0,100].  Unknown is -1.
int8[] data

What I have implemented so far is as follow:

#! /usr/bin/env python

import rospy
from nav_msgs.srv import GetMap, GetMapResponse
from nav_msgs.msg import OccupancyGrid

def my_callback(request):

    my_response = GetMapResponse()

    return my_response

rospy.init_node('get_map_service')
map_service = rospy.Service('/static_map', GetMap, my_callback)
rospy.spin()

I have no errors whatsoever when I run this python file, but I just need it to print the map.

edit retag flag offensive close merge delete

Comments

@gvdhoorn I have tried to answer this question twice, and both times it was rejected as spam. The 2nd attempt did not even contain a live url.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-07 07:59:00 -0500 )edit

Not entirely sure why you @-mention me specifically, but I guess it's because of this.

I've also opened osrf/infrastructure#6.

gvdhoorn gravatar image gvdhoorn  ( 2021-08-07 08:00:37 -0500 )edit

@gvdhoorn Thank you for opening the ticket. Your username has the highest karma I've seen here, so I figured you might be able to do something about it. To who should these kinds of site issues be reported?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-07 08:12:34 -0500 )edit

Your username has the highest karma I've seen here, so I figured you might be able to do something about it.

I'm just a user, like you. But with more imaginary internet points.

To who should these kinds of site issues be reported?

There is an issue tracker specifically for ROS Answers: ros-infrastructure/answers.ros.org.

And a more generic one for "OSRF hosted infrastructure": osrf/infrastructure.

I've broken etiquette by posting to both (and ROS Discourse), but I figured it might save some people some frustration (this being a weekend and all, and it'll probably take some time to get things fixed).

gvdhoorn gravatar image gvdhoorn  ( 2021-08-07 08:19:51 -0500 )edit