机器人操作系统ROS(15):nodelet

ROS的数据通信是以XML-RPC的方式,在graph结构中以topic,service和param的方式传输数据,天生的数据交互存在一定的延时和阻塞。

Nodelet 包就是改善这一状况设计的, 使得多个算法运行在同一个过程中,并且算法间数据传输无需拷贝就可实现。 简单的讲就是可以将以前启动的多个node捆绑在一起manager,使得同一个manager里面的topic的数据传输更快,数据通讯中roscpp采用boost shared pointer方式进行publish调用,实现zero copy。  The nodelet package is designed to provide a way to run multiple algorithms in the same process with zero copy transport between algorithms. This package provides both the nodelet base class needed for implementing a nodelet, as well as the NodeletLoader class used for instantiating nodelets.

Regular nodes use TCP and this works fine for a lot of things. But if you have multiple processes that need to use messages that contain large amounts of data (like images or point clouds) packaging the message, sending it, then unpacking it can take a bit of time.
So if the two processes are on the same computer, it is quicker to just send a pointer to that data rather than sending the data itself over TCP. This only works for processes (aka nodelets) on the same computer though since a pointer for one computer doesn’t make sense for another computer.
So nodelets don’t make the processes quicker, but it is a quicker way to get information from one process to another.

TCPROS style

BUT, I recommend you don’t use nodelet. If you’re thinking of using it, you might want to first consider just launching two threads in a single node, instead of two nodes. If you create two threads in a single node, it will be more memory efficient than launching two “nodelets” in ROS.
e.g. REF: kobuki Tutorials Write your own controller for Kobuki

特点
1 nodelets间数据传输zero copy,有效避免数据copy和网络传输代价
2 支持pulgin的方式动态加载
3  使用C++ ROS的接口方式

nodelet 基类
1 定义基类nodelet::Nodelet, 任何nodelet继承自它可以使用plugin的方式动态加载。
2 提供命名空间,参数可remap
3  nodelet的manager的过程可以加载更多的nodelets. 同一个manager过程的nodelet数据传输zero copy .

Basic Usage
nodelet usage:
nodelet load pkg/Type manager – Launch a nodelet of type pkg/Type on manager manager
nodelet standalone pkg/Type   – Launch a nodelet of type pkg/Type in a standalone nod
nodelet unload name manager   – Unload a nodelet a nodelet by name from manager
nodelet manager               – Launch a nodelet manager node

Bring up a manager
A nodelet will be run inside a NodeletManager. A nodelet manager is a c++ program which is setup to listen to ROS services and will be the executable in which the nodelet is dynamically loaded. In this case we will run a standalone manager, but in many cases these managers will be embedded within running nodes.
$ rosrun nodelet nodelet manager __name:=nodelet_manager

Launching the nodelet
The nodelet executable, called here, will contact the nodelet_manager and ask it to instantiate an instance of the nodelet_tutorial_math/Plus nodelet. It will pass through the name, nodelet1, and also any remappings if applied to the code inside the nodelet. And parameters appear in the right namespace too.
$ rosrun nodelet nodelet load nodelet_tutorial_math/Plus nodelet_manager __name:=nodelet1 nodelet1/in:=foo _value:=1.1

0 回复

发表评论

Want to join the discussion?
Feel free to contribute!

发表评论