There are 2 types of components to write the source code in ros2: node and nodelets.
Node | Nodelets (It is called as component in ros2) |
It is separate executable | It is a shared library. |
Components can run as an individual process (easier to debug as components are isolated) and also in single process (more efficient and better communication between components).
As a component is a shared library, it should be registered in the cmakefile as follows:
add_library(talker_component SHARED
src/talker_component.cpp)
rclcpp_components_register_nodes(talker_component "composition::Talker")
# To register multiple components in the same shared library, use multiple calls
# rclcpp_components_register_nodes(talker_component "composition::Talker2")
Reference:
https://docs.ros.org/en/foxy/Concepts/About-Composition.html