ros-navigation / navigation2

ROS 2 Navigation Framework and System
https://nav2.org/
Other
2.46k stars 1.24k forks source link

Launch navigation with namespace #4291

Closed ruibartsegura closed 4 months ago

ruibartsegura commented 4 months ago

I'm trying to launch the navigation of a Kobuki with a namespace, and when I do, I encounter an error indicating that it cannot find the map file. However, when I attempt the same process without the namespace, it works perfectly

The error:

[map_server-2] [ERROR] [1714596637.989463402] [map_server]: Caught exception in callback for transition 10 [map_server-2] [ERROR] [1714596637.989474228] [map_server]: Original error: parameter 'yaml_filename' is not initialized [map_server-2] [WARN] [1714596637.989491908] [map_server]: Error occurred while doing error handling. [map_server-2] [FATAL] [1714596637.989505657] [map_server]: Lifecycle node map_server does not have error state implemented

SteveMacenski commented 4 months ago

Please properly fill in the issue template, include your precise commands and error messages.

ruibartsegura commented 4 months ago

Required Info:

- Operating System:
   Ubuntu 22.04

- ROS2 Version:
    Humble

- Version or commit hash:
    ros-humble-nav2-amcl    1.1.14-1jammy.20240407.024740
    ros-humble-nav2-behavior-tree   1.1.14-1jammy.20240407.024820
    ros-humble-nav2-behaviors   1.1.14-1jammy.20240407.033140
    ros-humble-nav2-bringup 1.1.14-1jammy.20240407.042212
    ros-humble-nav2-bt-navigator    1.1.14-1jammy.20240407.033140
    ros-humble-nav2-collision-monitor   1.1.14-1jammy.20240407.031918
    ros-humble-nav2-common  1.1.14-1jammy.20240407.022742
    ros-humble-nav2-constrained-smoother    1.1.14-1jammy.20240407.032128
    ros-humble-nav2-controller  1.1.14-1jammy.20240407.032126
    ros-humble-nav2-core    1.1.14-1jammy.20240407.031918
    ros-humble-nav2-costmap-2d  1.1.14-1jammy.20240407.025649
    ros-humble-nav2-dwb-controller  1.1.14-1jammy.20240407.033138
    ros-humble-nav2-lifecycle-manager   1.1.14-1jammy.20240407.024841
    ros-humble-nav2-map-server  1.1.14-1jammy.20240407.024841
    ros-humble-nav2-mppi-controller 1.1.14-1jammy.20240407.032145
    ros-humble-nav2-msgs    1.1.14-1jammy.20240407.023105
    ros-humble-nav2-navfn-planner   1.1.14-1jammy.20240407.032142
    ros-humble-nav2-planner 1.1.14-1jammy.20240407.032129
    ros-humble-nav2-regulated-pure-pursuit-controller   1.1.14-1jammy.20240407.032148
    ros-humble-nav2-rotation-shim-controller    1.1.14-1jammy.20240407.032807
    ros-humble-nav2-rviz-plugins    1.1.14-1jammy.20240407.025255
    ros-humble-nav2-simple-commander    1.1.14-1jammy.20240407.023753
    ros-humble-nav2-smac-planner    1.1.14-1jammy.20240407.032151
    ros-humble-nav2-smoother    1.1.14-1jammy.20240407.032225
    ros-humble-nav2-theta-star-planner  1.1.14-1jammy.20240407.032248
    ros-humble-nav2-util    1.1.14-1jammy.20240407.023837
    ros-humble-nav2-velocity-smoother   1.1.14-1jammy.20240407.024846
    ros-humble-nav2-voxel-grid  1.1.14-1jammy.20240407.023142
    ros-humble-nav2-waypoint-follower   1.1.14-1jammy.20240407.032248

DDS implementation:
    ros-humble-rmw-dds-common    1.6.0-2jammy.20240217.051355     amd64

Steps to reproduce issue

I have two launcher and with both I have the same issue, these are the launchers:

# Copyright (c) 2024 Intelligent Robotics Lab (URJC)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Modified by Juan Carlos Manzanares Serrano
import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import SetRemap

def generate_launch_description():
    package_dir = get_package_share_directory('kobuki')
    nav2_dir = get_package_share_directory('nav2_bringup')

    # Configuration Variables
    use_sim_time = LaunchConfiguration('use_sim_time')
    slam = LaunchConfiguration('slam')
    rviz = LaunchConfiguration('rviz')
    map_file = LaunchConfiguration('map')
    params_file = LaunchConfiguration('params_file')
    namespace = LaunchConfiguration('namespace')
    container_name_full = LaunchConfiguration('container_name_full')

    declare_use_sim_time_cmd = DeclareLaunchArgument(
        'use_sim_time', default_value='false')

    declare_slam_cmd = DeclareLaunchArgument(
        'slam', default_value='False')

    declare_use_rviz_cmd = DeclareLaunchArgument(
        'rviz', default_value='True')

    declare_map_cmd = DeclareLaunchArgument(
        'map', default_value=os.path.join(
            package_dir,
            'maps',
            'mapa_lab.yaml'))

    declare_nav_params_cmd = DeclareLaunchArgument(
        'params_file', default_value=os.path.join(
            package_dir,
            'config',
            'kobuki_nav_params.yaml')
    )

    declare_namespace_cmd = DeclareLaunchArgument(
        'namespace', default_value='robot1'
    )

    # Actions
    localization_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(nav2_dir, 'launch', 'localization_launch.py')
        ),
        launch_arguments={
            'use_sim_time': use_sim_time,
            'slam': slam,
            'map': map_file,
            'params_file': params_file,
            'namespace': namespace
        }.items()
    )

    navigation_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(nav2_dir, 'launch', 'navigation_launch.py')
        ),
        launch_arguments={
            'use_sim_time': use_sim_time,
            'params_file': params_file,
            'namespace': namespace
        }.items()
    )

    rviz_cmd = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(nav2_dir, 'launch', 'rviz_launch.py')
        ),
        launch_arguments={
            'use_sim_time': use_sim_time,
            'rviz': rviz,
            'use_namespace': 'True',
            'namespace': namespace
        }.items()
    )

    # Remappings
    cmd_vel_remap = SetRemap(src='cmd_vel_nav', dst='cmd_vel')

    ld = LaunchDescription()
    ld.add_action(declare_use_sim_time_cmd)
    ld.add_action(declare_slam_cmd)
    ld.add_action(declare_nav_params_cmd)
    ld.add_action(declare_use_rviz_cmd)
    ld.add_action(declare_map_cmd)
    ld.add_action(declare_namespace_cmd)
    ld.add_action(localization_cmd)
    ld.add_action(navigation_cmd)
    ld.add_action(rviz_cmd)
    ld.add_action(cmd_vel_remap)

    return ld

launch command: ros2 launch kobuki navigation.launch.py namespace:=robot1 use_namespace:=True And with the kobuki launched with the same namespace

The other launcher:

# Copyright (c) 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Modified by: Jose Miguel Guerrero Hernandez <josemiguel.guerrero@urjc.es>
# Modified by: Rui Bartolome Segura <r.bartolome.2022@alumnos.urjc.es>

"""
Example for launching the navigation to robots with namespace

This is an example on how to create a launch file for the navigation of a robot with namespace.
The robot co-exist on a shared environment and is controlled by independent nav stack.
"""

import os
import yaml

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import (DeclareLaunchArgument, ExecuteProcess, GroupAction,
                            IncludeLaunchDescription, LogInfo)
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, TextSubstitution
from launch_ros.actions import SetRemap

def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('nav2_bringup')
    launch_dir = os.path.join(bringup_dir, 'launch')

    multi_dir = get_package_share_directory('multi_robot')
    config = os.path.join(multi_dir, 'config', 'params.yaml')

    with open(config, "r") as stream:
        try:
            conf = (yaml.safe_load(stream))

        except yaml.YAMLError as exc:
            print(exc)

    # Names and poses of the robot, read from yaml file
    robots_number = conf['multi_robot']['robots_number']

    robots = []
    robots_params = []

    # Change this rb_name with the namespace 
    rb_name = 'robot1'
    rb_position = conf['multi_robot'][rb_name]
    rb_data = {'name': rb_name, 'x_pose': rb_position['x'], 'y_pose': rb_position['y'], 'z_pose': rb_position['z'],
                'roll': rb_position['roll'], 'pitch': rb_position['pitch'], 'yaw': rb_position['yaw']}
    robots.append(rb_data)
    rb_params = DeclareLaunchArgument(
        rb_name + '_params_file',
        default_value=os.path.join(multi_dir, 'params', 'nav2_params_' + rb_name + '.yaml'),
        description='Full path to the ROS2 parameters file to use for ' + rb_name + ' launched nodes')
    robots_params.append(rb_params)

    # On this example all robots are launched with the same settings
    map_yaml_file = LaunchConfiguration('map')

    autostart = LaunchConfiguration('autostart')
    rviz_config_file = LaunchConfiguration('rviz_config')
    use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')
    use_rviz = LaunchConfiguration('use_rviz')
    log_settings = LaunchConfiguration('log_settings', default='true')

    world_name = conf['multi_robot']['world']

    # Change the map with the yours
    map_yaml_file = os.path.join(
        get_package_share_directory('multi_robot'),
        'maps',
        'aws_house.yaml'
    )

    # Declare the launch arguments
    declare_map_yaml_cmd = DeclareLaunchArgument(
        'map',
        default_value=os.path.join(multi_dir, 'maps', 'mapa_lab.yaml'),
        description='Full path to map file to load')

    declare_autostart_cmd = DeclareLaunchArgument(
        'autostart', default_value='false',
        description='Automatically startup the stacks')

    declare_rviz_config_file_cmd = DeclareLaunchArgument(
        'rviz_config',
        default_value=os.path.join(bringup_dir, 'rviz', 'nav2_namespaced_view.rviz'),
        description='Full path to the RVIZ config file to use.')

    declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
        'use_robot_state_pub',
        default_value='True',
        description='Whether to start the robot state publisher')

    declare_use_rviz_cmd = DeclareLaunchArgument(
        'use_rviz',
        default_value='True',
        description='Whether to start RVIZ')

    # Define commands for launching the navigation instances
    nav_instances_cmds = []
    for robot in robots:
        params_file = LaunchConfiguration(f"{robot['name']}_params_file")

        group = GroupAction([
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource(
                        os.path.join(launch_dir, 'rviz_launch.py')),
                condition=IfCondition(use_rviz),
                launch_arguments={
                                  'namespace': TextSubstitution(text=robot['name']),
                                  'use_namespace': 'True',
                                  'rviz_config': rviz_config_file,
                                  'use_sim_time': 'False',}.items()),

            IncludeLaunchDescription(

                PythonLaunchDescriptionSource(os.path.join(bringup_dir, 'launch',
                                                           'localization_launch.py')),
                launch_arguments={'namespace': robot['name'],
                                  'map': map_yaml_file,
                                  'use_sim_time': 'False',
                                  'params_file': params_file,
                                  'use_rviz': 'False',
                                  'use_composition': 'False',
                                  }.items()),

            IncludeLaunchDescription(

                PythonLaunchDescriptionSource(os.path.join(bringup_dir, 'launch',
                                                           'navigation_launch.py')),
                launch_arguments={'namespace': robot['name'],
                                  'autostart': 'False',
                                  'use_sim_time': 'False',
                                  'params_file': params_file,
                                  'use_rviz': 'False',
                                  'use_composition': 'True',
                                  }.items()),

            LogInfo(
                condition=IfCondition(log_settings),
                msg=['Launching ', robot['name']]),
            LogInfo(
                condition=IfCondition(log_settings),
                msg=[robot['name'], ' map yaml: ', map_yaml_file]),
            LogInfo(
                condition=IfCondition(log_settings),
                msg=[robot['name'], ' params yaml: ', params_file]),
            LogInfo(
                condition=IfCondition(log_settings),
                msg=[robot['name'], ' rviz config file: ', rviz_config_file]),
            LogInfo(
                condition=IfCondition(log_settings),
                msg=[robot['name'], ' using robot state pub: ', use_robot_state_pub]),
            LogInfo(
                condition=IfCondition(log_settings),
                msg=[robot['name'], ' autostart: ', autostart])
        ])

        nav_instances_cmds.append(group)

    # Remappings
    cmd_vel_remap = SetRemap(src='cmd_vel_nav', dst='cmd_vel')

    # Create the launch description and populate
    ld = LaunchDescription()

    # Declare the launch options
    for param in robots_params:
        ld.add_action(param)

    ld.add_action(declare_use_rviz_cmd)
    ld.add_action(declare_autostart_cmd)
    ld.add_action(declare_rviz_config_file_cmd)
    ld.add_action(declare_use_robot_state_pub_cmd)

    for simulation_instance_cmd in nav_instances_cmds:
        ld.add_action(simulation_instance_cmd)

    ld.add_action(cmd_vel_remap)

    return ld

To this launcher the command is: ros2 launch namespace_nav ns_nav.launch.py autostart:=True use_composition:=False

Expected behavior

The navigation launches correctly, and RViz2 displays the map.

Actual behavior

The RViz launch is successful, but the Global Status shows an error with the map frame, and the map does not appear Fixed Frame | Frame [map] does not exist

And in the terminal the error show this: [lifecycle_manager-3] [INFO] [1714658615.134659839] [lifecycle_manager_localization]: Configuring map_server

[map_server-1] [ERROR] [1714658615.135033901] [map_server]: Caught exception in callback for transition 10 [map_server-1] [ERROR] [1714658615.135051486] [map_server]: Original error: parameter 'yaml_filename' is not initialized [map_server-1] [WARN] [1714658615.135074598] [map_server]: Error occurred while doing error handling. [map_server-1] [FATAL] [1714658615.135094939] [map_server]: Lifecycle node map_server does not have error state implemented [lifecycle_manager-3] [ERROR] [1714658615.137107867] [lifecycle_manager_localization]: Failed to change state for node: map_server [lifecycle_manager-3] [ERROR] [1714658615.137148249] [lifecycle_manager_localization]: Failed to bring up all requested nodes. Aborting bringup.

Additional information:

Topics of the kobuki alone:

/diagnostics /parameter_events /robot1/commands/controller_info /robot1/commands/digital_output /robot1/commands/external_power /robot1/commands/led1 /robot1/commands/led2 /robot1/commands/motor_power /robot1/commands/reset_odometry /robot1/commands/sound /robot1/commands/velocity /robot1/controller_info /robot1/debug/raw_control_command /robot1/debug/raw_data_command /robot1/debug/raw_data_stream /robot1/events/bumper /robot1/events/button /robot1/events/cliff /robot1/events/digital_input /robot1/events/power_system /robot1/events/robot_state /robot1/events/wheel_drop /robot1/joint_states /robot1/odom /robot1/robot_description /robot1/sensors/battery_state /robot1/sensors/core /robot1/sensors/dock_ir /robot1/sensors/imu_data /robot1/sensors/imu_data_raw /robot1/tf /robot1/tf_static /robot1/version_info /rosout

Topics with the first launcher of the navigation:

/amcl/transition_event /behavior_server/transition_event /bt_navigator/transition_event /controller_server/transition_event /diagnostics /downsampled_costmap /downsampled_costmap_updates /global_costmap/costmap /global_costmap/costmap_updates /global_costmap/global_costmap/transition_event /global_costmap/voxel_marked_cloud /local_costmap/costmap /local_costmap/costmap_raw /local_costmap/costmap_updates /local_costmap/footprint /local_costmap/local_costmap/transition_event /local_costmap/published_footprint /local_costmap/voxel_marked_cloud /local_plan /map /map_server/transition_event /map_updates /mobile_base/sensors/bumper_pointcloud /parameter_events /particle_cloud /plan /planner_server/transition_event /robot1/clicked_point /robot1/commands/controller_info /robot1/commands/digital_output /robot1/commands/external_power /robot1/commands/led1 /robot1/commands/led2 /robot1/commands/motor_power /robot1/commands/reset_odometry /robot1/commands/sound /robot1/commands/velocity /robot1/controller_info /robot1/debug/raw_control_command /robot1/debug/raw_data_command /robot1/debug/raw_data_stream /robot1/events/bumper /robot1/events/button /robot1/events/cliff /robot1/events/digital_input /robot1/events/power_system /robot1/events/robot_state /robot1/events/wheel_drop /robot1/initialpose /robot1/joint_states /robot1/map /robot1/odom /robot1/robot_description /robot1/sensors/battery_state /robot1/sensors/core /robot1/sensors/dock_ir /robot1/sensors/imu_data /robot1/sensors/imu_data_raw /robot1/tf /robot1/tf_static /robot1/version_info /robot1/waypoints /rosout /scan /smoother_server/transition_event /tf /tf_static /velocity_smoother/transition_event /waypoint_follower/transition_event /waypoints

Topics with the secons launcher:

/amcl/transition_event /diagnostics /map_server/transition_event /parameter_events /robot1/commands/controller_info /robot1/commands/digital_output /robot1/commands/external_power /robot1/commands/led1 /robot1/commands/led2 /robot1/commands/motor_power /robot1/commands/reset_odometry /robot1/commands/sound /robot1/commands/velocity /robot1/controller_info /robot1/debug/raw_control_command /robot1/debug/raw_data_command /robot1/debug/raw_data_stream /robot1/events/bumper /robot1/events/button /robot1/events/cliff /robot1/events/digital_input /robot1/events/power_system /robot1/events/robot_state /robot1/events/wheel_drop /robot1/global_costmap/costmap /robot1/global_costmap/costmap_updates /robot1/initialpose /robot1/joint_states /robot1/local_costmap/costmap /robot1/local_costmap/costmap_updates /robot1/local_costmap/published_footprint /robot1/local_plan /robot1/map /robot1/map_updates /robot1/mobile_base/sensors/bumper_pointcloud /robot1/odom /robot1/particle_cloud /robot1/plan /robot1/robot_description /robot1/scan /robot1/sensors/battery_state /robot1/sensors/core /robot1/sensors/dock_ir /robot1/sensors/imu_data /robot1/sensors/imu_data_raw /robot1/tf /robot1/tf_static /robot1/version_info /robot1/waypoints /rosout

padhupradheep commented 4 months ago

Hey @ruibartsegura, Please check your multi_robot directory if your map exists and you have given the correct path to the map in your launch file. This seems to be a customized version of the Nav2 launch and I see this to be not originating at the Nav2 end. Note that I also cannot reproduce the issue locally as well. Therefore closing the issue.

ruibartsegura commented 4 months ago

The route to the map is correct because when I use the same launcher but without the namespace it work rightly.

padhupradheep commented 4 months ago

I understand, could you please ask your question at https://robotics.stackexchange.com/ ?

I think you will get the necessary help there.

SteveMacenski commented 4 months ago

[map_server-1] [ERROR] [1714658615.135051486] [map_server]: Original error: parameter 'yaml_filename' is not initialized

This is a common issue if you're grabbing files from the main branch and trying to apply it to older distributions. We changed how this was handled, so you should base both your launch files and nav2 params yaml file on those from the humble branch.

Can you see that the multirobot on humble that we provide works? If so, you should be able to look through your files and those and identify any other potential issues