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

Subscribe to a topic and trigger two Callback functions

asked 2012-06-06 06:07:52 -0600

ajr_ gravatar image

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

Hi,

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

Comments

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 -0600 )edit

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

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

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

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

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 -0600 )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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
4

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

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)
{
    function1(data);
    function2(data);
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-06-06 06:07:52 -0600

Seen: 1,714 times

Last updated: Jun 09 '12