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

rclcpp equivalent of 'ros2 run'

asked 2023-03-31 00:46:56 -0600

thejeeb gravatar image

Is there a ros2 C++ API(rclcpp) equivalent of 'ros2 run <pkg> <executable>'. That is, can I launch a node from the C++ API given the package name and node executable name? I know I can probably use a system() call but is there a direct C++ API for this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-03-31 04:14:29 -0600

Nopas gravatar image

As far as I now, in order to manage which nodes to run, when, and with which parameters, you create a my_project_bringup package that mainly contains a launch file.

Then all of your project can be started with ros2 launch my_project_bringup

Is there a reason why this wouldn't suit you ?

edit flag offensive delete link more


Yes, this would not suit me because the list of nodes that the project starts is not static. It may vary from run to run. It is based on the configuration of the system and it could change. I want to be able to start the nodes programmatically based on a configuration file.

thejeeb gravatar image thejeeb  ( 2023-03-31 09:29:30 -0600 )edit

Your launcher could construct a LaunchDescription object adapted to the configuration.

Nopas gravatar image Nopas  ( 2023-03-31 10:39:35 -0600 )edit

It is not easy to do that. LaunchDescription objects are good for static configuration and simple use-cases. There are also other reasons to launch the nodes from C++ code. So my original question remains.

thejeeb gravatar image thejeeb  ( 2023-03-31 10:52:54 -0600 )edit

That's not true, you can have dynamically changing different numbers of nodes or options. We do this quite frequently in Nav2.

stevemacenski gravatar image stevemacenski  ( 2023-03-31 10:58:26 -0600 )edit

That's good to know. Can you provide a link to some examples of this? I still would like to know if this can be done with rclcpp.

thejeeb gravatar image thejeeb  ( 2023-03-31 11:05:10 -0600 )edit

Examples for using LaunchDescription at startup with a dynamic set of nodes would be useful.

We also launch nodes during run-time based on user interaction. This is why a method to launch nodes using the C++ API would be preferable.

thejeeb gravatar image thejeeb  ( 2023-04-12 07:38:41 -0600 )edit

Question Tools

1 follower


Asked: 2023-03-31 00:46:56 -0600

Seen: 240 times

Last updated: Mar 31