Re: How to use nodelets in ROS
Posted by
matlabbe on
URL: http://official-rtab-map-forum.206.s1.nabble.com/How-to-use-nodelets-in-ROS-tp671p672.html
Hi,
1. A nodelet always requires a manager. We can see the manager as a node, in which we can put nodelets that will run in the same process. When you use a nodelet in a launch file, you have the choice to attach it to a manager or create it as a standalone nodelet (it will create its own manager). A standalone nodelet works exactly like a node and can be used in a launch file like that (note the "standalone" argument):
<node pkg="nodelet" type="nodelet" name="points_xyzrgb" args="standalone rtabmap_ros/point_cloud_xyzrgb"/>
For efficiency, if you want to create a point cloud from openni messages a lower rate, you may want to put the nodelets in the nodelet manager of openni (called "camera_nodelet_manager"):
<include file="$(find openni)/launch/openni.launch"/>
<group ns="camera">
<!-- Throttling openni images at 5 Hz -->
<node pkg="nodelet" type="nodelet" name="data_throttle" args="load rtabmap_ros/data_throttle camera_nodelet_manager">
<param name="rate" type="double" value="5"/>
<remap from="rgb/image_in" to="rgb/image_rect_color"/>
<remap from="depth/image_in" to="depth_registered/image_raw"/>
<remap from="rgb/camera_info_in" to="depth_registered/camera_info"/>
<remap from="rgb/image_out" to="rgb/image_rect_color_throttled"/>
<remap from="depth/image_out" to="depth_registered/image_raw_throttled"/>
<remap from="rgb/camera_info_out" to="depth_registered/camera_info_throttled"/>
</node>
<!-- Create point clouds -->
<node pkg="nodelet" type="nodelet" name="points_xyzrgb" args="load rtabmap_ros/point_cloud_xyzrgb camera_nodelet_manager">
<remap from="rgb/image" to="rgb/image_rect_color_throttled"/>
<remap from="depth/image" to="depth_registered/image_raw_throttled"/>
<remap from="rgb/camera_info" to="depth_registered/camera_info_throttled"/>
</node>
</group>
Note that
rgbd_launch (which openni includes) uses a lot the nodelets if you need more examples.
2. The copy cost issue is why nodelets exist. If you have algorithms running in different processes (different nodes), they should serialize/deserialize messages between them (over TCP/IP). If they run in the same process as nodelets in the same manager, the message can be copied directly in memory between the processes (I think they are not even deep copied if they use smart pointers) without serialization/deserialization. Generally, I use nodelets when I have algorithms on the same machine exchanging data at high framerate and/or that have large size (algorithms connected to openni is a good example, which process images at high frame rate).
3. In RTAB-Map, most nodelets are intended to be used with data coming from openni. Other nodes are used with data at a lower framerate. For convenience, I've seen other projects creating all algorithms as nodelets, but they provide also node wrappers, so you have the choice to use the nodelet interface or the node interface in the launch file.
cheers