ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to run nodelets in parallel?

asked 2018-11-08 05:11:36 -0500

Galadriel1233 gravatar image

I am trying to parallellize a certain algorithm on point cloud processing for which I decided to take advantage of ROS nodelets' zero copy transport. So I will have one nodelet publishing them and the other subscribing, However, my issue is that the nodelets never run parallelly - either by using a launch file or by using the nodelet::loader class. Thanks in advance, I have been really tearing my hair out on this one.

edit retag flag offensive close merge delete

Comments

I'm not sure how this is a duplicate question. Can you clarify?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-12 04:13:18 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-11-08 05:34:09 -0500

gvdhoorn gravatar image

updated 2018-11-08 05:37:00 -0500

The documentation (wiki/nodelet) says this:

A nodelet manager has a pool of threads which is shared across all nodelets run within the manager. This is set by the parameter "num_worker_threads".

There are two possible threading APIs to use in code running in nodelets. The default threading model has a single thread for all callbacks. There is a multithreaded API as well.

[..]

1.6.3 Multi Threaded API

Using the methods getMTNodeHandle() and getMTPrivateNodeHandle() callbacks will be distributed over the thread pool of the manager.

Are you using those?


There are some gotchas though, see ros/nodelet_core#77 and ros/nodelet_core#25 fi (and the linked lucasw/nodelet_demo@c43e08bf).

edit flag offensive delete link more

Comments

Thanks @gvdhoorn, but I've tried setting the parameter num_worker_threads and using getMTNodeHandle. I think the real issue here is that the onInit() function is first called when loading the nodelet and the publisher subscriber code is in there. Maybe I am a nodelet noob, but is this how it's done?

Galadriel1233 gravatar image Galadriel1233  ( 2018-11-08 23:42:32 -0500 )edit

onInit() function is first called

yes, that's how it works.

and the publisher subscriber code is in there

again, expected.

And in there you use getMTNodeHandle() which returns a NodeHandle which will use multithreading to service your callback queue.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-09 02:22:31 -0500 )edit

Yes. I am using 'getMTNodeHandle()'. The issue here is that my publisher is in one nodelet and my subscriber is in another nodelet. So what happens is I load my first nodelet and I publish in its onInit() function. Then, my subscriber nodelet is loaded and runs its Init() function and gets nothing.

Galadriel1233 gravatar image Galadriel1233  ( 2018-11-09 02:40:46 -0500 )edit

I have seen pretty much one example online like so http://www.clearpathrobotics.com/asse... where the publisher and subscriber are both in one nodelet. @gvdhoorn, can you have seperate nodelets subscribing & publishing? Am I misunderstanding nodelets ? Thanks alot

Galadriel1233 gravatar image Galadriel1233  ( 2018-11-09 02:43:49 -0500 )edit

I publish in its onInit() function.

I'm not sure you're supposed to do that.

onInit() should initialise your nodelet (ie: allocate resources, open files, create pubs/subs, etc). It's not meant to do any 'real work'.

Can you show some code that illustrates what you're doing?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-09 02:45:48 -0500 )edit

re: example: there are multiple projects using nodelets. One I already linked: lucasw/nodelet_demo.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-09 02:51:18 -0500 )edit

Thanks @gvdhoorn. Sorry for the delay. I haave posted a more clear question here along with code which I guess explains the problem better. Sorry about that. I wasn't very clear here.

Galadriel1233 gravatar image Galadriel1233  ( 2018-11-12 04:06:50 -0500 )edit

I'm not sure why you had to post a new question for that: couldn't you have edited this one?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-12 04:11:07 -0500 )edit

Question Tools

Stats

Asked: 2018-11-08 05:11:36 -0500

Seen: 823 times

Last updated: Nov 08 '18