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

How to solve 'file 'rviz2.launch.py' was not found in the share directory of package'?

asked 2019-12-09 05:35:21 -0600

sam gravatar image

updated 2019-12-09 05:37:05 -0600

I'm using ROS2 Dashing on ubuntu 18.04 64bits.

I have run:

cd ~/ros2_overlay_ws/src/
ros2 pkg create sam_empty_package_with_rviz2
cd ~/ros2_overlay_ws/src/sam_empty_package_with_rviz2
mkdir -p rviz2/
mkdir -p launch/

vim launch/rviz2.launch.py

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():
    rviz_config_dir = os.path.join(
            get_package_share_directory('sam_empty_package_with_rviz2'),
            'rviz2',
            'sam_empty_package_with_rviz2.rviz')

    return LaunchDescription([
        Node(
            package='rviz2',
            node_executable='rviz2',
            node_name='rviz2',
            arguments=['-d', rviz_config_dir],
            output='screen'),
    ])

Compile:

colcon build --packages-select sam_empty_package_with_rviz2

After compile I run:

ros2 launch sam_empty_package_with_rviz2 rviz2.launch.py

And I got errors:

sam@sam-ub1804:~$ ros2 launch sam_empty_package_with_rviz2 rviz2.launch.py
file 'rviz2.launch.py' was not found in the share directory of package 'sam_empty_package_with_rviz2' which is at '/home/sam/ros2_dashing_overlay_ws/install/sam_empty_package_with_rviz2/share/sam_empty_package_with_rviz2'
sam@sam-ub1804:~$

How to solve it?

Thank you~

edit retag flag offensive close merge delete

Comments

Just making sure: have you sourced the correct setup.bash file after you built your workspace?

gvdhoorn gravatar image gvdhoorn  ( 2019-12-09 05:41:42 -0600 )edit
2

Also make sure you have something like this

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

in your CMakeLists.txt. Otherwise "colcon build" does not actually place your launchfiles in the share folder (which is where ros2 launch looks for launchfiles).

MCornelis gravatar image MCornelis  ( 2019-12-09 08:33:05 -0600 )edit

If you plan on changing the .rviz2 file and launchfile a lot I recommend building with --symlink-install. This way you don't have to source after every change to these 2 files.

MCornelis gravatar image MCornelis  ( 2019-12-09 08:36:14 -0600 )edit

I'm sure I have already sourced that setup.bash on my ROS2 workspace. And it works when I use that install. Thank you very much! Please post as an answer! Another simple question is why if I use --symlink-install, it will cause my rviz2 could not save file anymore?

sam gravatar image sam  ( 2019-12-10 02:12:11 -0600 )edit
1

A normal colcon build will copy the launch directory to the share directory. So if you then change something in the launch folder you have to colcon build again, otherwise the share directory is not updated (at least this is my understanding). If you do colcon build --symlink-install a link to the launch folder is placed in the share directory. So if you then update something in the launch folder even if you look in the share directory you will get the updated version. I am not aware of --symlink-install preventing you from saving the .rviz2 config. This is new to me, my bad I think :P? You are free to do a normal colcon build if that works for you, but like I said it will require rebuilding every time you change something to your .launch.py or your .rviz2/.rviz file.

MCornelis gravatar image MCornelis  ( 2019-12-10 06:44:56 -0600 )edit

You can btw also make a config folder in one of your packages where you put the .rviz file and then do

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

in the CMakeLists.txt. In your launch file you can then do something like

rviz_config_dir = os.path.join(
            get_package_share_directory('<my_package_name>'),
            'config',
            '<my_rviz_config_file_name>.rviz')
MCornelis gravatar image MCornelis  ( 2019-12-10 06:52:03 -0600 )edit

You can btw also just hit the up-arrow next to a comment. I believe this also gives me karma? You might even be able to accept a comment as an answer, I'm not entirely sure how this all works :P Just glad I was able to help ^^

MCornelis gravatar image MCornelis  ( 2019-12-10 06:55:11 -0600 )edit

Thanks for very detail information. I'm not able to set the comment as an answer. Please post your comment as an answer and I will mark it.

sam gravatar image sam  ( 2019-12-11 01:59:26 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
5

answered 2019-12-12 04:05:56 -0600

MCornelis gravatar image

As per request of the questioin poster I'll highlight the answer in the comments that worked for him here:

In CMakeLists.txt you need to put an install() command which basically tells colcon build to put either a copy or a link to a certain folder in the share directory. The share directory is the default place where ros2 launch will look for things. So if you add

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

To your CMakeLists.txt and then do a colcon build your share directory, so for instance ros2_ws/install/<pkg_name>/share/<pkg_name>/, will have a copy of your launch directory in it.

If you do colcon build --symlink-install, then instead of a copy of the launch file it will put a symbolic link to the launchfile. This means that if you change something to the launch file in your package you don't have to rebuild the package for the changes to take effect. This is only true for files that don require compilation, so --symlink-install will work for config files or python code / launch files etc.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-12-09 05:35:21 -0600

Seen: 14,925 times

Last updated: Dec 12 '19