using advertise function with SubscriberStatusCallback parameter [closed]

asked 2013-10-01 10:57:29 -0500

Nicola P. gravatar image

updated 2013-10-01 11:01:33 -0500

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

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2016-08-08 00:19:57.974509