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

Loading map using a service call

asked 2022-03-29 12:15:02 -0600

Flash gravatar image

updated 2022-03-29 13:28:57 -0600

I am having trouble understanding or creating service calls for loading maps using map_server. This link provides idea of how to call it from the terminal. But unable to understand how can I call it from the python node. What should be my import like nav_msgs.srv or map_msgs.srv. Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-03-29 13:35:30 -0600

Flash gravatar image

updated 2022-03-29 13:36:18 -0600

Updating solution just in case anyone has the same problem.
To import, we have to use.

from nav2_msgs.srv import LoadMap

Sample code for the service call

Class Service(Node):
        self.map_client = self.create_client(LoadMap,'/map_server/load_map')
        self.map_request = LoadMap.Request()
        while not self.map_client.wait_for_service(timeout_sec=10.0):
                self.get_logger().info('Waiting for service')


    def send_request(self):
            self.map_request.map_url = "../maps/my_map.yaml"
            wait = self.map_client.call_async(self.map_request)
            rclpy.spin_until_future_complete(self, wait)
            if wait.result() is not None:
                self.get_logger().info('Request was responded')
                self.get_logger().info('Request Failed')

This will send map data to /map topic that can be used to get the map data

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2022-03-29 12:15:02 -0600

Seen: 472 times

Last updated: Mar 29 '22