save_composite_map
Service type: map_manager/srv/SaveCompositeMap
Service name: /save_composite_map
Description
Saves the current runtime map to the archive directory in map_path and exports map.pgm and map.yaml. An existing target directory is replaced.
Request (Request)
| Field | Type | Description |
|---|---|---|
| map_path | string | Archive directory to write. |
| compress | bool | Compatibility field; GRW does not use it to select an export format. |
Response (Response)
| Field | Type | Description |
|---|---|---|
| success | bool | Whether the operation succeeded. |
| message | string | Result or error message. |
| saved_path | string | The requested map_path. |
Example
Complete Environment Preparation first: the CLI examples require
ROBOT_NAMESPACEto be set; the Python and C++ examples use relative service names, so append--ros-args -r __ns:=$ROBOT_NAMESPACEwhen running them.
CLI call
ros2 service call $ROBOT_NAMESPACE/save_composite_map map_manager/srv/SaveCompositeMap \
"{map_path: '/data/maps/office', compress: false}"
compress is not an export-format switch on GRW. Pass an archive directory and take saved_path from the response as the save result.
Notes: In rare cases this service may return success=false, message='save failed'; retrying after a robot restart usually recovers. Keep known-good archives as a fallback. Annotations (POIs/virtual walls/forbidden areas) are stored inside the archive and restored on load - see the annotation lifecycle notes in ros_api.md section 9.2.
Python example
import rclpy
from rclpy.node import Node
from map_manager.srv import SaveCompositeMap
class MapSaver(Node):
def __init__(self):
super().__init__('map_saver')
self.client = self.create_client(
SaveCompositeMap, 'save_composite_map')
def save(self, map_path: str):
self.client.wait_for_service()
request = SaveCompositeMap.Request()
request.map_path = map_path
request.compress = False
future = self.client.call_async(request)
rclpy.spin_until_future_complete(self, future)
return future.result()
rclpy.init()
node = MapSaver()
result = node.save('/data/maps/office')
print(result.message, result.saved_path)
node.destroy_node()
rclpy.shutdown()
C++ example
#include <memory>
#include <rclcpp/rclcpp.hpp>
#include <map_manager/srv/save_composite_map.hpp>
auto node = std::make_shared<rclcpp::Node>("map_saver");
auto client = node->create_client<map_manager::srv::SaveCompositeMap>(
"save_composite_map");
client->wait_for_service();
auto request = std::make_shared<map_manager::srv::SaveCompositeMap::Request>();
request->map_path = "/data/maps/office";
request->compress = false;
auto future = client->async_send_request(request);
if (rclcpp::spin_until_future_complete(node, future) ==
rclcpp::FutureReturnCode::SUCCESS) {
const auto response = future.get();
RCLCPP_INFO(node->get_logger(), "%s: %s",
response->message.c_str(), response->saved_path.c_str());
}
Archive contents
- Map archive data reloadable by this module
map.pgmmap.yaml
Related services
- LoadCompositeMap - Loads an archive
- ClearCompositeMap - Clears the runtime map
- DeleteMapArchive - Deletes a saved archive