I have a ROS Node where i subscribe to a Topic and then publish to another topic on the following way :
#include ...
//Ros Nodehandle + Publisher
//Callback Function definition
int main (int argc, char** argv){
//Initialisation
// Pub
pub = nh->advertise<Messagetype>("Topic2", 1);
//Sub
ros::Subscriber sub = nh->subscribe("Topic1", 1, sub_cb);
ros::spin();
return 0;
}
void sub_cb(){
//Write the msg i want to publish
pub.publish(msg);
}
I wanted to publish the message for 15 seconds for example. I tried a solution with Ros::Time and Ros::Duration . But the fact that i have a publisher in my callback function didn't allow me to do that.
Is there a way to do it even is my publish event is in my callback function ? If not, any solution would work, the main thing that my subscriber and my publisher are on the same node.
Like I said in the comments, I think this is just a logic question, nothing really specific to ROS. Here is one of several possible solutions: