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

How can we give arguments to the node in launch file?

asked 2022-07-19 00:29:11 -0500

johnny2887 gravatar image

I am using ros2 dashing and making a launch file including cam2image. For cam2image node, I can select the resolution using command line "ros2 run image_tools cam2image -x 1280 -y 960"

I want to do the same thing in the launch file because the default resoltion for cam2image is 320*240 which is too low.

I have no idea how to pass the arguments to the node in launch file properly. There is no example in the document. It always give me the default resolution when I run the following launch file.

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, ThisLaunchFileDir
from ament_index_python.packages import get_package_share_directory

from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='image_tools',
            node_executable='cam2image',
            arguments=[{"width":1280, "height":960, "x":1280, "y":960}],
            parameters=[{"width":1280, "height":960, "x":1280, "y":960}],
            output='screen',
        ),
    ])
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-07-19 02:53:52 -0500

ljaniec gravatar image

Hello,

I used this tutorial to prepare a YAML configuration files to my launchfiles:

I think it could help you too :)

The most important things: - self.declare_parameters(...) in the code of your (Python) node - then, in the launch file:

config = os.path.join(
    get_package_share_directory('ros2_tutorials'),
    'config',
    'params.yaml'
    )

node=Node(
    package = 'your_ros2_package',
    name = 'your_amazing_node',
    executable = 'test_yaml_params',
    parameters = [config]
)
  • additionally, in the setup.py in the package there should be something like this:

    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/*.yaml'))],

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-07-19 00:29:11 -0500

Seen: 134 times

Last updated: Jul 19 '22