Ask Your Question

Subscribe to a topic and trigger two Callback functions

asked 2012-06-06 06:07:52 -0500

ajr_ gravatar image

updated 2012-06-09 12:56:57 -0500


I want to trigger two Callback functions by same message data. And to be able to execute Callbacks at the same rate as publication happens. At the moment I have it with following initialization code. What would be the correct way to do it?

ImuSubscriber = nh.subscribe ("/mikrokopter/fc_debug", 100, &MikrokopterControl::mikoImuCallback, this);

HeightSubscriber = nh.subscribe ("/mikrokopter/fc_debug", 100, &MikrokopterControl::heightCallback, this);

The goal is to call two different Callbacks as far as i understood. I want the published message data into two different functions and they to be executed when ever new data is available from publisher.

edit retag flag offensive close merge delete


Are you trying to call the same callback two times or to call two different callbacks?

DimitriProsser gravatar image DimitriProsser  ( 2012-06-06 07:39:45 -0500 )edit

I modified the question a bit, hope it's more clear now

ajr_ gravatar image ajr_  ( 2012-06-06 07:49:20 -0500 )edit

Interesting questions... hope to see some answers from pros.. :)

karthik gravatar image karthik  ( 2012-06-06 08:20:03 -0500 )edit

You still seem to be providing the same function in both callbacks. Additionally, I don't fully understand why you need multiple callbacks. Is there a reason you cannot call multiple functions with the message data from a single callback?

piyushk gravatar image piyushk  ( 2012-06-06 08:31:44 -0500 )edit

No special reason, basically were wondering about if there are some sophisticated ways to do this with ROS. Thanks for the answers!

ajr_ gravatar image ajr_  ( 2012-06-06 13:41:02 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-06-06 09:21:56 -0500

DimitriProsser gravatar image

The simplest solution to do what you're trying to do is to simply call two functions within a "generic" callback function:

ImuSubscriber = nh.subscribe ("/mikrokopter/fc_debug", 100, &MikrokopterControl::genericCallback, this);


void MikrokopterControl::genericCallback(const sensor_msgs::IMU& data)
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

1 follower


Asked: 2012-06-06 06:07:52 -0500

Seen: 1,227 times

Last updated: Jun 09 '12