Ask Your Question
1

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

1 Answer

Sort by ยป oldest newest most voted
2

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 198 times

Last updated: Mar 28