- name
- ros2-composition
- description
- ROS 2 component composition, intra-process communication, UniquePtr callbacks, loaned messages, and Nav2-style container bringup. Use when loading composable nodes, component_container, intra-process, loaned messages, iceoryx, or type adaptation.
# ROS 2 Composition and Zero-Copy
## Components
Composable nodes: `rclcpp::Node` with `NodeOptions`, registered via:
```cpp
RCLCPP_COMPONENTS_REGISTER_NODE(my_pkg::MyComponent)
```
CMake: `rclcpp_components_register_node` on a **SHARED** lib. Launch: `ComposableNodeContainer` or `ros2 component load`.
No `rclcpp::init` / `spin` inside the component — the **container** spins.
## Containers (stack practice)
| Container | Executor | Use |
|-----------|----------|-----|
| `component_container` | Single-threaded | Simple; no parallel callbacks |
| `component_container_mt` | Multi-threaded | Need callback groups (Nav2-style servers) |
| Isolated process per server | Separate container | Fault isolation / RT control away from perception |
Composition ≠ free concurrency: ST container ignores your MT hopes (`ros2-executors`).
## Intra-process
`NodeOptions.use_intra_process_comms(true)` on components that should zero-copy.
Requires:
- Sub callback `UniquePtr<Msg>` (not `SharedPtr`)
- `publish(std::move(unique_msg))`
- Compatible QoS; **same process only**
## Loaned messages (inter-process)
`borrow_loaned_message()` needs RMW support; unbounded strings/sequences often disable loans; static `Type[N]` friendlier (`ros2-interfaces`). Measure — fallback is copy.
## Type adaptation
`rclcpp::TypeAdapter` for native types in-process; still ROS msgs on the wire to others.
GitHub에서 보기