Ask Your Question
0

How to run rviz2 with own settings in .rviz from launch file which refers to my my package via arguments = ["-d", "$(find my_package)/rviz/my.rviz"]

asked 2021-09-12 13:24:32 -0500

mac137 gravatar image

updated 2021-09-12 13:38:39 -0500

Hello! As in question. How to run rviz2 with my own settings saved in .rviz from the launch file which refers to my_package by name? I can add that when I refer to the .rviz file using its absolute path, it works.

The following launches rviz2 but without own settings:

     my_rviz2 = Node(package = "rviz2", 
                    executable = "rviz2",
                    arguments = ["-d", "$(find my_package)/rviz/my.rviz"]
                    )


    ld = LaunchDescription()

    ld.add_action(declare_use_sim_time_argument)
    ld.add_action(declare_params_file_cmd)
    ld.add_action(log_param_change)
    ld.add_action(my_rviz2)

    return ld
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-09-22 09:14:47 -0500

ChuiV gravatar image

I've done something like:

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

def generate_launch_description():
    my_package_dir = get_package_share_directory('my_package')
    return launch.LaunchDescription([
        Node(package='rviz2',
             executable='rviz2',
             arguments=['-d', os.path.join(my_package_dir, 'rviz', 'my.rviz')])
    ])

The key here is the get_package_share_directory function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-09-12 13:24:32 -0500

Seen: 144 times

Last updated: Sep 22 '21