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

Is different subscriber working like different thread?

asked 2017-05-25 16:28:32 -0500

Bill5785 gravatar image

For example, I want to subscribe to 2 topics ("/scan" and "/odometry")

the "/scan" frequency is 10Hz, while the "/odometry" frequency is 50Hz.

But in my program, the scanCallBack function is computational heavy, so it cannot process as fast as the "/scan".

the odomCallBack function is not that heavy, so it has the potential to process like 50Hz.

I expected them to work separately, but when I try print out time, I found the odomCallBack function now has the same frequency as the scanCallBack function, at 6Hz.

So does it mean the subscribers can affect each other, instead of working separately like different threads?

By the way, how can I fix this problem?

edit retag flag offensive close merge delete

Comments

Why not use two nodes?

jayess gravatar image jayess  ( 2017-05-25 19:59:15 -0500 )edit

@jayess I need to do sensor fusion. So I need to put them in one program.

Bill5785 gravatar image Bill5785  ( 2017-05-26 12:16:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
7

answered 2017-05-25 17:25:12 -0500

ahendrix gravatar image

By default roscpp executes your subscriber callbacks single-threaded, which is what you're observing.

You can process callbacks on multiple threads, or assign specific threads to callbacks by using a MultiThreadedSpinner, AsyncSpinner, CallbackQueue or various combinations of these as described in http://wiki.ros.org/roscpp/Overview/C...

edit flag offensive delete link more

Comments

Thanks, it works!

Bill5785 gravatar image Bill5785  ( 2017-05-26 12:16:18 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-05-25 16:28:32 -0500

Seen: 2,793 times

Last updated: May 25 '17