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

how to publish map in ros2 galactic?

asked 2022-09-06 16:08:44 -0500

dastan_forum gravatar image

Hi

I installed ros galactic on ubuntu 20.04 using this bash script (https://github.com/turtlebot/TurtleBo...), then I ran turtlebot4 simulation in depot and map its surrounding. I saved the map with

**

ros2 service call /slam_toolbox/save_map slam_toolbox/srv/SaveMap "name:
  data: 'map_name'

**

then when I want to publish the map, and use

ros2 run nav2_map_server map_server $PWD/map_name.yaml

I get stuck with the following log

[INFO] [1662497993.651852411] [map_server]: 
    map_server lifecycle node launched. 
    Waiting on external lifecycle transitions to activate
    See https://design.ros2.org/articles/node_lifecycle.html for more information.
[INFO] [1662497993.651943245] [map_server]: Creating

here is the available service list:

ros2 service list
/map_server/change_state
/map_server/describe_parameters
/map_server/get_available_states
/map_server/get_available_transitions
/map_server/get_parameter_types
/map_server/get_parameters
/map_server/get_state
/map_server/get_transition_graph
/map_server/list_parameters
/map_server/set_parameters
/map_server/set_parameters_atomically

and here is the result of node list

ros2 node list
/map_server

Am I doing something wrong? should I add any other node to this?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
2

answered 2022-09-10 20:26:55 -0500

dastan_forum gravatar image

first create a map_server_params.yaml file to set the ros parameters,

map_server:
    ros__parameters:
    frame_id: map   
    topic_name: map
    use_sim_time: false
    yaml_filename: "/home/dastan/map.yaml"

then run the map_server node with passing the .yaml file as the input,

ros2 run nav2_map_server map_server --ros-args --params-file map_server_params.yaml

then since all nodes in nav2 are lifecycle nodes, you need to transition them into active mode,

ros2 lifecycle set /map_server configure
ros2 lifecycle set /map_server activate

then the subscriber to the /map topic should have the QoS of local_transient in order to recieve the map data.

edit flag offensive delete link more

Comments

Good work! It was a bit more than I thought, you should self-accept this answer to your question

ljaniec gravatar image ljaniec  ( 2022-09-11 07:58:41 -0500 )edit

Thanks @ljaniec

dastan_forum gravatar image dastan_forum  ( 2022-09-12 09:35:15 -0500 )edit
1

answered 2022-09-07 13:03:54 -0500

All nodes in Nav2 are lifecycle nodes - you must transition them up into the active state. Also, I think you need to specify that map as a param argument.

edit flag offensive delete link more

Comments

I did as you said, there's just one problem, it only publishes the map once!

dastan_forum gravatar image dastan_forum  ( 2022-09-08 00:36:15 -0500 )edit

I will reply thorough answer on how to do as your comment tomorrow

dastan_forum gravatar image dastan_forum  ( 2022-09-08 00:36:46 -0500 )edit

It should only publish once, its a transient local QoS topic, any late joining subscription should be able to get it.

stevemacenski gravatar image stevemacenski  ( 2022-09-08 18:42:35 -0500 )edit

it doesn't! Only the early subscription are able to get it

dastan_forum gravatar image dastan_forum  ( 2022-09-08 18:52:18 -0500 )edit

Are you subscribing with a transient local QoS?

stevemacenski gravatar image stevemacenski  ( 2022-09-09 20:23:03 -0500 )edit

thanks Steve

dastan_forum gravatar image dastan_forum  ( 2022-09-10 20:27:40 -0500 )edit
1

answered 2022-09-07 07:57:04 -0500

ljaniec gravatar image

You have to call correct service to load the map from file: https://github.com/ros-planning/navig...

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/configurat... 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.

edit flag offensive delete link more

Comments

when I call

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

I receive waiting for service to become available..., how to activate the service server for this?

dastan_forum gravatar image dastan_forum  ( 2022-09-08 00:09:09 -0500 )edit

??????????

dastan_forum gravatar image dastan_forum  ( 2022-09-10 20:27:28 -0500 )edit

Question Tools

Stats

Asked: 2022-09-06 16:08:44 -0500

Seen: 1,665 times

Last updated: Sep 10 '22