Exercise 3.1 LookupError: Could not find the resource 'map_server' of type 'packages'

Hi, as in the title - while trying to ros2 launch localization_server localization.launch.py got this problem and don’t have any idea what can be an issue. Bellow whole output

Hello @Twordify ,

The map_server package is installed with the default ROS2 installation. So, if it’s not being found, it’s probably because you are missing a source in your Shell. Try sourcing ROS2 with the following command:

source /opt/ros/foxy/setup.bash

Let us know if this fixes your issue.

Hello,
sourcing doesn’t fix the issue. Bellow whole output:

[INFO] [launch]: All log files can be found below /home/user/.ros/log/2023-02-27-10-30-53-308256-2_xterm-1409
[INFO] [launch]: Default logging verbosity is set to INFO
Task exception was never retrieved
future: <Task finished name=‘Task-2’ coro=<LaunchService._process_one_event() done, defined at /opt/ros/galactic/lib/python3.8/site-packages/launch/launch_service.py:226> exception=InvalidLaunchFileError(‘py’)>
Traceback (most recent call last):
File “/opt/ros/galactic/lib/python3.8/site-packages/ament_index_python/packages.py”, line 50, in get_package_prefix
content, package_prefix = get_resource(‘packages’, package_name)
File “/opt/ros/galactic/lib/python3.8/site-packages/ament_index_python/resources.py”, line 48, in get_resource
raise LookupError(
LookupError: Could not find the resource ‘map_server’ of type ‘packages’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py”, line 53, in get_launch_description_from_any_launch_file
return loader(launch_file_path)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/python_launch_file_utilities.py”, line 68, in get_launch_description_from_python_launch_file
return getattr(launch_file_module, ‘generate_launch_description’)()
File “/home/user/ros2_ws/install/localization_server/share/localization_server/launch/localization.launch.py”, line 12, in generate_launch_description
map_file = os.path.join(get_package_share_directory(
File “/opt/ros/galactic/lib/python3.8/site-packages/ament_index_python/packages.py”, line 70, in get_package_share_directory
return os.path.join(get_package_prefix(package_name), ‘share’, package_name)
File “/opt/ros/galactic/lib/python3.8/site-packages/ament_index_python/packages.py”, line 52, in get_package_prefix
raise PackageNotFoundError(
ament_index_python.packages.PackageNotFoundError: “package ‘map_server’ not found, searching: [‘/home/user/ros2_ws/install/nav2_project’, ‘/home/user/ros2_ws/install/nav2_course’, ‘/home/user/ros2_ws/install/localization_server’, ‘/home/user/ros2_ws/install/cartographer_slam’, ‘/opt/ros/galactic’]”

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_service.py”, line 228, in _process_one_event
await self.__process_event(next_event)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_service.py”, line 248, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py”, line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py”, line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py”, line 38, in visit_all_entities_and_collect_futures
sub_entities = entity.visit(context)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/action.py”, line 108, in visit
return self.execute(context)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/actions/include_launch_description.py”, line 127, in execute
launch_description = self.__launch_description_source.get_launch_description(context)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_source.py”, line 84, in get_launch_description
self._get_launch_description(self.__expanded_location)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_description_source.py”, line 53, in _get_launch_description
return get_launch_description_from_any_launch_file(location)
File “/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py”, line 56, in get_launch_description_from_any_launch_file
raise InvalidLaunchFileError(extension, likely_errors=exceptions)
launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [py]: “package ‘map_server’ not found, searching: [‘/home/user/ros2_ws/install/nav2_project’, ‘/home/user/ros2_ws/install/nav2_course’, ‘/home/user/ros2_ws/install/localization_server’, ‘/home/user/ros2_ws/install/cartographer_slam’, ‘/opt/ros/galactic’]”

Hi @Twordify ,

Welcome to this Community!

Going through your error output, it seems that there is some mistake in your launch file.

Please post your localization.launch.py file here as a code-block.

I / we can then help you fix the problem.

Regards,
Girish

Thank you for your interest. My current launch file is the one what was shown as solution for this exercise:

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node


def generate_launch_description():

    nav2_yaml = os.path.join(get_package_share_directory(
        'localization_server'), 'config', 'amcl_config.yaml')
    map_file = os.path.join(get_package_share_directory(
        'map_server'), 'config', 'turtlebot_area.yaml')

    return LaunchDescription([
        Node(
            package='nav2_map_server',
            executable='map_server',
            name='map_server',
            output='screen',
            parameters=[{'use_sim_time': True},
                        {'yaml_filename': map_file}]
        ),

        Node(
            package='nav2_amcl',
            executable='amcl',
            name='amcl',
            output='screen',
            parameters=[nav2_yaml]
        ),

        Node(
            package='nav2_lifecycle_manager',
            executable='lifecycle_manager',
            name='lifecycle_manager_localization',
            output='screen',
            parameters=[{'use_sim_time': True},
                        {'autostart': True},
                        {'node_names': ['map_server', 'amcl']}]
        )
    ])

And my setup.py

from setuptools import setup
import os
from glob import glob

package_name = 'localization_server'

setup(
    name=package_name,
    version='0.0.0',
    packages=[package_name],
    data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')),
        (os.path.join('share', package_name, 'config'), glob('config/*')),

    ],
    install_requires=['setuptools'],
    zip_safe=True,
    maintainer='user',
    maintainer_email='user@todo.todo',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
            
        ],
    },
)

Hi @Twordify ,

I just read through your launch and setup files. They seem to be fine.

I guess you have not sourced your workspace correctly, like @aezquerrostudent indicated.

So try doing this:

  1. Reset your current terminal / webshell by pressing on the red X button on the webshell tab.
  2. Run the following commands after the shell is ready:
    cd ~
    source /opt/ros/galactic/setup.bash
    cd ~/ros2_ws
    rm -rf ./build ./install ./log
    colcon build
    source install/setup.bash
    ros2 launch localization_server localization.launch.py
    

This should fix your issue.
Just source the correct version of ROS2.

Regards,
Girish