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

Multiple Threads in Single ROS Node

asked 2011-06-20 02:28:08 -0600

SyllogismRXS gravatar image

updated 2014-01-28 17:09:53 -0600

ngrennan gravatar image

What is the preferred threading library to use when trying to write a ROS node with multiple threads? Boost::Thread ? Posix ? Pthreads ?

Are there any issues with callback functions when multiple threads are used?

The reason I want to use multiple threads in a single node instead of writing multiple nodes is that I am trying to integrated ROS with another publish and subscribe system called MOOS, which is used heavily in the underwater robotics community. (Found here: http://oceanai.mit.edu/moos-ivp/pmwiki/pmwiki.php). Unfortunately, the MOOS architecture relies upon the user calling a blocking function that sits and spins in a loop (similar to ROS, but all the initial logic is tied up in that one function as well). I want to run that blocking function in its own separate loop, grabbing data from the MOOS system and then publishing it to the ROS side.

Any tips?

edit retag flag offensive close merge delete

Comments

ROS package posest in vslam uses Intel TBB, but from my experience TBB aims at parallelization of computationally expensive tasks, so you're probably looking for sth. else here.
Julius gravatar image Julius  ( 2011-06-21 01:03:24 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
4

answered 2011-06-21 06:13:16 -0600

bhaskara gravatar image

updated 2011-06-21 20:52:48 -0600

Boost::threads is commonly used, but the others should work as well. Info on callbacks in roscpp is at http://www.ros.org/wiki/roscpp/Overview/Callbacks%20and%20Spinning. For your case, spinning off a thread that calls the moos loop, then calling ros::spin in the main thread, sounds like it will work.

edit flag offensive delete link more

Comments

This is how I ended up implementing my MOOS / ROS node and it worked well.
SyllogismRXS gravatar image SyllogismRXS  ( 2011-06-24 04:21:30 -0600 )edit

Hello,I run spin() in boost::thread,but it's also block my GUI?Thanks for your help.

zzzZuo gravatar image zzzZuo  ( 2015-12-30 20:45:14 -0600 )edit
4

answered 2011-06-20 15:41:24 -0600

joq gravatar image

I've mostly used boost::thread, because many other ROS components use it. Works fine. I also like the boost::mutex::scoped_lock.

edit flag offensive delete link more

Comments

I use spin() in boost::thread,but it's also block my GUI,thanks for your help.

zzzZuo gravatar image zzzZuo  ( 2015-12-30 20:43:21 -0600 )edit
0

answered 2011-06-21 20:51:46 -0600

For my last project I used qt threads and liked them. As for your problem, I also had to run the ros spinning in a seperate thread, since qt uses its own spinning for signals and slots communication (which btw can be used for calls across threads). The implementation is in the qtros class

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-06-20 02:28:08 -0600

Seen: 12,854 times

Last updated: Jun 21 '11