using advertise function with SubscriberStatusCallback parameter [closed]
I have a publisher node and I would like to call a callback function when a subscriber connects.
I've the same code of @Benoit Larochelle in this post (mine is the same problem) but instead of
ros::Time maxTime(ros::Time::now()+ros::Duration(1)); // Will wait at most 1000 ms
while(ros::Time::now()<maxTime)
{
ros::spinOnce();
}
I use this piece of code to give the time to subscriber to connect (actually, i stuck in the while loop until there are no subscriber to my topic)
while(!pub.getNumSubscribers())
{ } //it doesn't work even if I put ros::spinOnce into the while loop
But in this way it doesn't work...And not even if I try with
ros::Rate loop_rate(1);
loop_rate.sleep();
Note: also if I use the above code with no ros::spinOnce in the loop:
ros::Time maxTime(ros::Time::now()+ros::Duration(1)); // Will wait at most 1000 ms
while(ros::Time::now()<maxTime)
{
/* NO ros::spinOnce() */
}
I have the same situation.
What's the problem? Can you help me to understand?
Thank you all
Closed for the following reason
question is not relevant or outdated by
tfoote
close date 2016-08-08 00:19:57.974509
add a comment