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

rclcpp equivalent of 'ros2 run'

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

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
0

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

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 my_launcher.launch.py

https://docs.ros.org/en/foxy/Tutorial...

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

edit flag offensive delete link more

Comments

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 -0500 )edit

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

Nopas gravatar image Nopas  ( 2023-03-31 10:39:35 -0500 )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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 338 times

Last updated: Mar 31 '23