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

ROS2 nav2 map_server - Problems loading map with nav2_map_server

asked 2022-03-28 07:36:21 -0500

lcfs gravatar image

I am using ROS-Foxy with ubuntu 20.04 LTS. I was uses to ROS1, so I am new in the ROS2 world and I am working in the transition of my software for ROS2. Map_server is a simple, yet important package for me. So I got surprised with it's complexity to work in ROS2.

https://github.com/ros-planning/navig...

I followed the instructions in the documentation, so:

1- Created the "map_server_params.yaml" (I found out later that indentation is crucial in this file)

# map_server_params.yaml
map_server:
    ros__parameters:
        yaml_filename: "map.yaml"

2- the map.yaml is just like in ROS1 version:

image: map.pgm
resolution: 0.050000
origin: [-1.000000, -17.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

3 - run the node:

$ ros2 run nav2_map_server map_server _params:=map_server_params.yaml

4- As a result, the the map is not published:

[INFO] [1648467290.572912903] [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] [1648467290.572984105] [map_server]: Creating

5 - I managed to find that it is necessary to activate the "lifecycle" , which is not indicated in the original documentation! I

$ ros2 run nav2_util lifecycle_bringup map_server

6 - However, it is not working either:

$ ros2 run nav2_map_server map_server _params:=map_server_params.yaml
[INFO] [1648467520.824391783] [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] [1648467520.824462825] [map_server]: Creating
[INFO] [1648467538.673566146] [map_server]: Configuring
[ERROR] [1648467538.673770244] []: Caught exception in callback for transition 10
[ERROR] [1648467538.673809412] []: Original error: yaml_filename
[WARN] [1648467538.673851628] []: Error occurred while doing error handling.
[FATAL] [1648467538.673883971] [map_server]: Lifecycle node map_server does not have error state implemented
[WARN] [1648467538.674845275] [rcl_lifecycle]: No transition matching 3 found for current state unconfigured
[ERROR] [1648467538.674900522] []: Unable to start transition 3 from current state unconfigured: Transition is not registered., at /tmp/binarydeb/ros-foxy-rcl-lifecycle-1.1.13/src/rcl_lifecycle.c:350

7- I decided to create a launch file (which actually worked, partially solving the problem)

import os
import yaml
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import ExecuteProcess
from launch.substitutions import LaunchConfiguration
import launch_ros.actions


def generate_launch_description():

    ld = LaunchDescription()

    # Map server
    map_server_config_path = os.path.join(
        get_package_share_directory('agrob_path'),
        'launch',
        'map_server_params.yaml'
    )
    map_server_cmd = Node(
        package='nav2_map_server',
        executable='map_server',
        output='screen',
        parameters=[map_server_config_path])


    ld.add_action(map_server_cmd)

    return ld

8 - I had to add the data folder to cmake in order to use the launch File (I am mentioning this in case someone else gets stuck too)

install(DIRECTORY
    config
    launch
    DESTINATION share/${PROJECT_NAME})

9 - After compiling, I managed to publish a map, yet I still need to run it with two commands:

$ ros2 launch agrob_path map_simple.launch.py

$ ros2 run nav2_util lifecycle_bringup map_server

10 - This works, but I wanted to publish a map with one simple command, or at least with one file! So, I tried to add the lifecycle_bringup to the map launch ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2022-03-28 10:36:22 -0500

lcfs gravatar image

It magically stopped working again.. It is requiring the absolute path in the YAML file! I do not know what do to anymore!

EDIT: I found out that for some reason this is only working when I run the launch file in a terminal that is in the launch file directory....

Anyway, I found a simpler and robust approach by ignoring one of the YAML files and passing directly the argument in the launch file. This way I am using the absolute path, the OS python library is responsible for it. So just forget the file "map_server_params.yaml", and use the following launch file:

import os import yaml from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription from launch_ros.actions import Node from launch.actions import ExecuteProcess from launch.substitutions import LaunchConfiguration import launch_ros.actions

def generate_launch_description():

ld = LaunchDescription()

# Map server
map_server_config_path = os.path.join(
    get_package_share_directory('agrob_path'),
    'launch',
    'map.yaml'
)

map_server_cmd = Node(
    package='nav2_map_server',
    executable='map_server',
    output='screen',
    parameters=[{'yaml_filename': map_server_config_path}])


lifecycle_nodes = ['map_server']
use_sim_time = True
autostart = True

start_lifecycle_manager_cmd = launch_ros.actions.Node(
        package='nav2_lifecycle_manager',
        executable='lifecycle_manager',
        name='lifecycle_manager',
        output='screen',
        emulate_tty=True,  # https://github.com/ros2/launch/issues/188
        parameters=[{'use_sim_time': use_sim_time},
                    {'autostart': autostart},
                    {'node_names': lifecycle_nodes}])




ld.add_action(map_server_cmd)
ld.add_action(start_lifecycle_manager_cmd)

return ld

.

edit flag offensive delete link more
0

answered 2023-07-20 04:49:17 -0500

marcomasa gravatar image

Thanks for this post! I struggled a lot to get the map server running in ros2 with a given map file until i found this..

I just wanna add my launch config here, because it does not require the extra param yaml file you used.


My map_server.launch.py file:

import os
import yaml
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import ExecuteProcess
from launch.substitutions import LaunchConfiguration
import launch_ros.actions


def generate_launch_description():

ld = LaunchDescription()

# map file
map_file_path = os.path.join(
    get_package_share_directory('nav2_benchmark'),
    'maps',
    'map.yaml'
)

map_server_cmd = Node(
    package='nav2_map_server',
    executable='map_server',
    output='screen',
    parameters=[{'yaml_filename': map_file_path}])


lifecycle_nodes = ['map_server']
use_sim_time = True
autostart = True

start_lifecycle_manager_cmd = launch_ros.actions.Node(
        package='nav2_lifecycle_manager',
        executable='lifecycle_manager',
        name='lifecycle_manager',
        output='screen',
        emulate_tty=True,  # https://github.com/ros2/launch/issues/188
        parameters=[{'use_sim_time': use_sim_time},
                    {'autostart': autostart},
                    {'node_names': lifecycle_nodes}])


ld.add_action(map_server_cmd)
ld.add_action(start_lifecycle_manager_cmd)

return ld

Note: To make this work using more or less "classic" ROS1 Workflow, you will need to add these lines to your CMakeLists.txt:

# Install the launch file
   install(DIRECTORY launch/
   DESTINATION share/${PROJECT_NAME}/launch
)

# Install the map file
   install(DIRECTORY maps/
   DESTINATION share/${PROJECT_NAME}/maps
)

And this to your package.xml:

<exec_depend>ros2launch</exec_depend>

Now my output looks like this and i can see the map in RVIZ:

marco@md3v360c:~/ros2_ws$ ros2 launch nav2_benchmark map_server.launch.py 
[INFO] [launch]: All log files can be found below /home/marco/.ros/log/2023-07-20-11-47-15-309631-md3v360c-26348
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [lifecycle_manager-2]: process started with pid [26351]
[INFO] [map_server-1]: process started with pid [26349]
[lifecycle_manager-2] [INFO] [1689846435.421007174] [lifecycle_manager]: Creating
[lifecycle_manager-2] [INFO] [1689846435.422937482] [lifecycle_manager]: Creating and initializing lifecycle service clients
[lifecycle_manager-2] [INFO] [1689846435.429748909] [lifecycle_manager]: Starting managed nodes bringup...
[lifecycle_manager-2] [INFO] [1689846435.429841009] [lifecycle_manager]: Configuring map_server
[map_server-1] [INFO] [1689846435.431032914] [map_server]: 
[map_server-1]  map_server lifecycle node launched. 
[map_server-1]  Waiting on external lifecycle transitions to activate
[map_server-1]  See https://design.ros2.org/articles/node_lifecycle.html for more information.
[map_server-1] [INFO] [1689846435.431162214] [map_server]: Creating
[map_server-1] [INFO] [1689846435.431647816] [map_server]: Configuring
[map_server-1] [INFO] [map_io]: Loading yaml file: /home/marco/ros2_ws/install/nav2_benchmark/share/nav2_benchmark/maps/map.yaml
[map_server-1] [DEBUG] [map_io]: resolution: 0.025
[map_server-1] [DEBUG] [map_io]: origin[0]: -8
[map_server-1] [DEBUG] [map_io]: origin[1]: -4
[map_server-1] [DEBUG] [map_io]: origin[2]: 0
[map_server-1] [DEBUG] [map_io]: free_thresh: 0.25
[map_server-1] [DEBUG] [map_io]: occupied_thresh: 0.65
[map_server-1] [DEBUG] [map_io]: mode: trinary
[map_server-1] [DEBUG] [map_io]: negate: 0
[map_server-1] [INFO] [map_io]: Loading image_file: /home/marco/ros2_ws/install/nav2_benchmark/share/nav2_benchmark/maps/modified_map_2.pgm
[map_server-1] [DEBUG] [map_io]: Read map /home/marco/ros2_ws/install/nav2_benchmark/share/nav2_benchmark/maps/modified_map_2.pgm: 549 X 412 map @ 0.025 m/cell
[lifecycle_manager-2] [INFO] [1689846435.453434802] [lifecycle_manager]: Activating map_server
[map_server-1] [INFO] [1689846435.453657303] [map_server]: Activating
[map_server-1] [INFO] [1689846435.454019105] [map_server]: Creating bond (map_server) to lifecycle manager.
[lifecycle_manager-2] [INFO] [1689846435.557139113] [lifecycle_manager]: Server map_server connected with bond.
[lifecycle_manager-2] [INFO] [1689846435.557207313] [lifecycle_manager]: Managed nodes are active
[lifecycle_manager-2] [INFO] [1689846435.557242914] [lifecycle_manager]: Creating bond timer...
edit flag offensive delete link more

Comments

I will also just add a XML-based launchfile here for others to look up.

This way the map_server is at least able to load the file.

Unfortunately, this does not activate the lifecycle stuff, so the node is still stuck in the Creating.. Stage

My map_server.launch:

<launch>

 <arg name="map_path" default="$(find-pkg-share nav2_benchmark)/maps/map.yaml"/>

 <!-- Launch the map server -->
 <node
   name="map_server"
   pkg="nav2_map_server"
   exec="map_server"
   output="screen">
   <param name="yaml_filename" value="$(var map_path)" />
   <param name="use_sim_time" value="false" />
   <param name="topic_name" value="map" />

<!-- Missing Lifecycle Stuff? -->

 </node>


</launch>

marcomasa gravatar image marcomasa  ( 2023-07-20 05:45:24 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-03-28 07:36:21 -0500

Seen: 3,211 times

Last updated: Jul 20 '23