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

[ROS2] node names relation between launch file and executable

asked 2022-08-07 05:53:24 -0500

comala gravatar image

Hi there,

this might be a basic question but thus far I haven't found specifics in the docs or tutorials.

What is the actual relation between node names specified within the launch file and the executable?

For example in my Python launch file, I include the node:

move_group_node = Node(
            package='motion_planner', # name of my package
            executable='mgi_planner', # name of my executable as given in CMake file
            name='move_group_interface_planner', # name my node will have
            output='screen',
            parameters=[robot_description, robot_description_semantic, kinematics_yaml]
        )

In my executable i use:

auto move_group_node = rclcpp::Node::make_shared("move_group_interface_planner", node_options);

Do the names have to match or will the name given in the launch file simply overwrite the one given in the .cpp? Meaning is the name given within the .cpp only for use within the file?

And what would happen if my executable contains multiple nodes? How do I distinguish them in the launch file?

I'm using ROS2 foxy on Ubuntu 20.04.4 LTS

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-08-08 21:16:21 -0500

ravijoshi gravatar image

updated 2022-08-08 21:17:30 -0500

Do the names have to match

No.

will the name given in the launch file simply overwrite the one given in the .cpp?

Yes.

what would happen if my executable contains multiple nodes? How do I distinguish them in the launch file?

One executable contains one node. However, you may want to run one node many times. In this situation, you should assign a unique name to each node. For example, consider you are trying to use two cameras. You have already written the node which process image from a camera. Therefore, you can simply do the following:

camera_node_1 = Node(
            package='my_camera_pkg',
            executable='image_proc',
            name='camera_1',         # <- assign a unique name here
            output='screen',
            parameters=[camera_serial_no]
        )
camera_node_2 = Node(
            package='my_camera_pkg',
            executable='image_proc',
            name='camera_2',         # <- assign a unique name here
            output='screen',
            parameters=[camera_serial_no]
        )

This is one feature out of many great features provided by launch files. It allows you to change the name, namespace, etc., without touching the code.

edit flag offensive delete link more

Comments

Thanks, that cleared it up!

comala gravatar image comala  ( 2022-08-09 02:13:19 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-08-07 05:53:24 -0500

Seen: 615 times

Last updated: Aug 08 '22