ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

link composable node into standalone executable

asked 2021-11-21 10:53:17 -0500

Christian Rauch gravatar image

updated 2021-11-21 11:12:12 -0500

I created a composable node that I want to link into a standalone executable for easier debugging with different parameters. The idea is that the library with the composable node is linked to an executable that behaves as if this would be a standalone node.

Using the launch system will involve other processes and makes debugging via gdb more difficult. Using the component manager for debugging a single component is quite tedious as you have to start the component manager with gdb and load the component manually.

One alternative is the dlopen_composition executable from the composition package, which dynamically loads the library with the component node, instantiates and runs it: ros2 run composition dlopen_composition <workspace>_ws/install/<package>/lib/lib<node>.so. However, the dlopen_composition does not allow to pass configuration parameters like --ros-args --params-file.

I found a node template node_main.cpp.inat It looks as if this is doing the same as the dlopen_composition just with a hardcoded library. Can this be used in some way to create a standalone executable from a single composable node?

I do not want to use the header to specifically link or compile the node's source code into the main executable. I strongly prefer to use the standard node factories for this.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-26 19:35:14 -0500

Christian Rauch gravatar image

I found that, besides rclcpp_components_register_nodes which is heavily used in the node composition tutorial, there is also rclcpp_components_register_node. This additionally takes a parameter EXECUTABLE to define the name of a standalone executable for that component.

Instead of only registering one (or more) component(s) via:

add_library(camera_component SHARED src/CameraNode.cpp)
rclcpp_components_register_nodes(camera_component "camera::CameraNode")

as suggested by the tutorial, you can instead register a component and create a standalone executable like:

add_library(camera_component SHARED src/CameraNode.cpp)
rclcpp_components_register_node(camera_component PLUGIN "camera::CameraNode" EXECUTABLE "camera_node")

The node executable camera_node can then be used like any other standalone executable node, e.g.: ros2 run <package> camera_node --ros-args -p <param>:=<value>.

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

1 follower


Asked: 2021-11-21 10:53:17 -0500

Seen: 145 times

Last updated: Nov 26 '21