Ask Your Question

Loading map using a service call

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

Flash gravatar image

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

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 -0500

Flash gravatar image

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 54 times

Last updated: Mar 29