[solved] Multiple subscriber to same topic not receiving data [closed]
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
@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.