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

Revision history [back]

You have to call correct service to load the map from file: https://github.com/ros-planning/navigation2/blob/main/nav2_map_server/README.md#services

Services

As in ROS navigation, the map_server node provides a "map" service to get the map. See the nav_msgs/srv/GetMap.srv file for details.

NEW in ROS2 Eloquent, map_server also now provides a "load_map" service and map_saver - a "save_map" service. See nav2_msgs/srv/LoadMap.srv and nav2_msgs/srv/SaveMap.srv for details.

For using these services map_server/map_saver should be launched as a continuously running nav2::LifecycleNode node. In addition to the CLI, Map Saver has a functionality of server handling incoming services. To run Map Saver in a server mode nav2_map_server/launch/map_saver_server.launch.py launch-file could be used.

Service usage examples:

$ ros2 service call /map_server/load_map nav2_msgs/srv/LoadMap "{map_url: /ros/maps/map.yaml}"

$ ros2 service call /map_saver/save_map nav2_msgs/srv/SaveMap "{map_topic: map, map_url: my_map, image_format: pgm, map_mode: trinary, free_thresh: 0.25, occupied_thresh: 0.65}"

Usually everything is done in the Nav2 launcher https://navigation.ros.org/configuration/packages/configuring-map-server.html?highlight=map#map-server-parameters if you don't want to change maps at run-time.

Map Server Parameters

yaml_filename (...) - Path to map yaml file.

Note: This parameter must appear in a yaml file when launched with Nav2’s default launch files. It is overridable as a launch configuration map, which is only possible if the yaml_filename key already exists in the yaml file. If you would like the specify your map file in yaml rather than in launch defaults or launch configurations, remove the launch default so it is not overridden in Nav2’s default launch files. This is an odd quirk that exists to be able to provide users with the option to change maps at run-time on the commandline.