[solved] Multiple subscriber to same topic not receiving data [closed]

asked 2017-12-20 03:59:05 -0500

prince gravatar image

updated 2017-12-20 04:59:42 -0500

Greetings

I am using Ubuntu 16.04, ROS Lunar.

My understanding of ROS message publish-subscribe library is that every ros subscriber receives the data that gets published on the intened topic. It works for the subscribes which are created at same level, but this is not working for a case where a subscription is done in an encapsulated object. Let me explain with an example

class B
{
public: 
B() { ... 
subscribe_b=node_handle.subscribe<std_msgs::String>("T",10, &B::callback,this); 
}
...
};

class A
{ 
 A() 
{... 
subscribe_a1=node_handle.subscribe<std_msgs::String>("T",10, &A::callback1,this); 
subscribe_a1=node_handle.subscribe<std_msgs::String>("T",10, &A::callback2,this); 
b = new B();
}
private:
ros::Subscriber subscribe_a1;
ros::Subscriber subscribe_a2;
B *b;
};

In the above pusedo code, class A encapsulates pointer to B and creates an object. All three subscribers, subscribe_a1, subscribe_a2 and subscribe_b subscribe to the topic T. In my code, subscribe_a1 and subscribes_a2 gets data and respective callbacks are called. But callback is not being called for subscribe_b . The object of B has been created and subscriber is also not throwing any kind of exception as well. I am not sure why this liking of topic with callback is not happening. I am not sure, if I have missed something.

SOLVED: Subscriber object was going out of scope.

rgds Nitin

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by tfoote
close date 2017-12-20 20:03:53.850678

Comments

@prince FYI I closed this, but if you find your own answer you can also answer your own question and accept it so it's clear to others that it's been resolved.

tfoote gravatar image tfoote  ( 2017-12-20 20:04:55 -0500 )edit