Not able to launch the file (showing error ros2 launch cartographer_slam cartographer.launch.py file 'cartographer.launch.py' was not found in the share directory of package 'cartog...)

ros2 launch cartographer_slam cartographer.launch.py

file ‘cartographer.launch.py’ was not found in the share directory of package ‘cartographer_slam’ which is at '/home/user/ros2_ws/install/cartographer_slam/share/cartographer_slam

Hi @ROSBUILD ,

You should add the launch folder to setup.py file, so that the launch file is copied into the install folder during compilation.

Add the following lines into your setup.py file: (DO NOT COPY-PASTE AS-IS, IT WILL NOT WORK)

# imports (add these lines if not added yet)
import os
from glob import glob

data_files=[
        ('share/ament_index/resource_index/packages',
            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        # add the following line after the above line
        (os.path.join('share', package_name, 'launch'), glob('launch/*.launch.*')),
    ],

This should fix your problem.

Regards,
Girish

Hello, I am facing a similar error while doing the first part of the Nav2 project. The following error is output:

launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [py]: "package 'cartographer_slam' not found,

I have already added and sourced the needed insetup.py and this is my file:

from setuptools import setup
import os
from glob import glob
package_name = 'project_mapping'

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': [
        ],
    },
)

The error still persists.

Hi @Abboud ,

Try to source ROS2 and then source the workspace after building.

source /opt/ros/galactic/setup.py
cd ~/ros2_ws
rm -rf ./build ./install ./log
colcon build
source install/setup.bash

This should solve your problem.

If it does not, I believe that cartographer_slam package is not installed in your virtual machine. [Which I am not 100% sure. If this is the case, to install you have to run sudo apt install ros-galactic-cartographer .]

Regards,
Girish

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.