Rosanswers logo


I don't understand why I cannot load the config file for RVIZ automatically using a python script.

The script is the following:

import os

from ament_index_python.packages import get_package_share_directory
from launch                      import LaunchDescription
from launch.actions              import DeclareLaunchArgument
from launch.substitutions        import LaunchConfiguration
from launch_ros.actions          import Node

def generate_launch_description():

    config_file_name = 'config_file.rviz'

    print("Loading RVIZ config file: {}".format(config_file_name))

    rviz_config = os.path.join(get_package_share_directory('HHH'), config_file_name)

    return LaunchDescription([DeclareLaunchArgument('use_sim_time',
                                                    default_value = 'false',
                                                    description   = 'Use simulation clock if true'),

                              Node(package    = 'rviz2',
                                   executable = 'rviz2',
                                   name       = 'rviz2',
                                   output     = 'screen',
                                   arguments  = ['-d', rviz_config]),

the file config_file.rviz is stored in the package directory under config:

-> /config
    --> config_file.rviz
    --> params.yaml
-> /urdf
    --> urdf_model.xml
-> /'package_name'
    -->  publisher_node.py

starting the node with:

ros2 launch HHH launch_rviz.py

RVIZ starts, but it doesn't load the config file automatically as expected.

I compile the package with:

colcon build 'package_name'


colcon build --symlink-install

but it doesn't copy my config file into the share directory under install.

What's wrong?


PS: moving the config file into share manually fixes the issue. But it get "resetted" from time to time

Originally posted by Andromeda on ROS Answers with karma: 893 on 2021-07-15

Post score: 0


1 Answer 1


Rosanswers logo

I fixed this problem by simpling leaving the config file config_file.rviz where it is in the package directory.

I then changed the setup.py where it searchs for the config file in the package directory (using glob and path) and not in the install direcory.

colcon doesn't work properly. Sometimes I realize that I need to delete all the folders install, build and log because colcon keeps old codes there without taking the new changes...

Originally posted by Andromeda with karma: 893 on 2021-07-27

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.