publisher and subscriber in single node
Consider node 'x' publishes topic 'a' and 'b'. Now, I should create a node 'y' to subscribe a topic 'a'. Then the subscribed topic should be edited and published again in the name 'c'.
I tried,
// some part of the codes
void chattercallback(const .... )
{
.........
// edit or process the subscribed value<
//to publish the edited data
ros::Publisher d =......;
d.publish(..) ;
....}
int main (int argc, char **argv){
ros::init (..);
ros::Subscriber sub = .....(.. , .. , chattercallback);
....
}
But, the data is not published continuously. This node publishes data only when the topic 'a' is available i.e) only when the data is subscricbed. I need to change this codes such that data is to be published continuously i.e) even if the subscriber does not subscribe any data, it should publish the data according to the last subscribed one.
Is there any ideas for this problem?
I cannot find the option 'post a comment' below the answers. So I will post it here.
But the problem is how to access the value in topic 'a' for storing it to a variable?
I cannot find the option 'post a comment' below the answers. So I will post it here.
But the problem is how to access the value in topic 'a' for storing it to a variable?
Normally,publishers, subscribers and callbacks are implemented as class members. If you need to store a value, you just put it into a member variable so that e.g. a publisher can access it.