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

Revision history [back]

click to hide/show revision 1
initial version

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):
    def__init__(self):   
        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')

        self.send_request()

    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')
            else:
                self.get_logger().info('Request Failed')

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

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):
    def__init__(self):   
        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')

        self.send_request()

    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')
            else:
                self.get_logger().info('Request Failed')

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

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

from nav2_msgs.srv import LoadMap

Sample code for the service call

Class Service(Node):
    def__init__(self):   
        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')

        self.send_request()

    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')
            else:
                self.get_logger().info('Request Failed')

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