Rosanswers logo


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.

Originally posted by ajr_ on ROS Answers with karma: 97 on 2012-06-06

Post score: 1

Original comments

Comment by DimitriProsser on 2012-06-06:
Are you trying to call the same callback two times or to call two different callbacks?

Comment by ajr_ on 2012-06-06:
I modified the question a bit, hope it's more clear now

Comment by karthik on 2012-06-06:
Interesting questions... hope to see some answers from pros.. :)

Comment by piyushk on 2012-06-06:
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?

Comment by ajr_ on 2012-06-06:
No special reason, basically were wondering about if there are some sophisticated ways to do this with ROS. Thanks for the answers!


2 Answers 2


Rosanswers logo

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)

Originally posted by DimitriProsser with karma: 11163 on 2012-06-06

This answer was ACCEPTED on the original site

Post score: 4


you can use mutiple thread to run them. at firt, you init the two thread. when the callback is triggered, it will wake the two threads to run one time.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.