Ask Your Question
1

Python Nodelet

asked 2018-03-12 15:40:34 -0500

lalten gravatar image

Is there a way (or even a tutorial) to write nodelet plugins in Python?

I have one python node in my image processing pipeline. All the other nodes are roscpp nodelets.

The question nodelets in python suggests it should be possible?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2018-03-13 02:18:50 -0500

ahendrix gravatar image

Nodelets are a performance optimization for C++ nodes, and they avoid the serialization and copying by running multiple nodes in the same process. If you're writing image processing nodes in Python, these costs are probably less than the other costs incurred by running the python interpreter.

Since you're asking about nodelets, you're either trying to use them because they're there (in which case, don't worry about it) or you're trying to make your code faster.

If you're trying to make your code faster (and as always with performance optimization), the best course of action is to measure the performance of your system through profiling. This will give you a much better idea of which parts of your code are slow, and how much performance you may gain by optimizing each part of your program.

edit flag offensive delete link more
2

answered 2018-03-12 23:43:08 -0500

JamesGiller gravatar image

updated 2018-03-12 23:46:09 -0500

As far as I know, nodelets are C++ only. A nodelet manager is in basic terms a node that creates multiple threads in which arbitrary user code that calls the ROS APIs can be run, and handles the communication over topics, services etc. The user code running in each thread is a nodelet, and the recommended way to create nodelets from your code, as so-called plugins, is just a consequence of dynamic loading requirements in C++ (uniform interface, shared object libraries, defined paths to library locations etc.).

It is possible to dynamically import Python modules, and actually much easier than dynamic loading with C++, but there is no equivalent pre-written "nodelet manager" program that will coordinate everything for you, and you still wouldn't be able to take advantage of copy-free message passing on topics etc.

edit flag offensive delete link more
2

answered 2018-03-13 01:50:57 -0500

gvdhoorn gravatar image

ROS Nodelets are essentially nodes that can exploit the fact that they share an address space with other nodelets running in the same nodelet manager. This is because they are nodes mapped on threads (instead of individual processes). Sharing an address space lets nodelets exchange pointers, which allows for their increased performance, as they can then skip (de)serialisation of messages.

Technically it is probably possible to get (a) Python interpreter(s) to be hosted by a (custom) nodelet manager and then hijack the messaging pipeline in rospy to allow exchanging pointers with other processes, but as of today (2018-03-13), there is no built-in support for that.

The question nodelets in python suggests it should be possible?

#q46342 doesn't exactly state that nodelets in Python are possible. @tfoote essentially comments on the fact that writing and loading plugins in Python is easier than in C++. But loading plugins is only one part of what nodelets would need.

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

2 followers

Stats

Asked: 2018-03-12 15:40:34 -0500

Seen: 1,248 times

Last updated: Mar 13 '18