How can we wait until subscriber has received a massage
My goal is something like the following due to need for synchronization.
_sub = nh_.subscribe("topic1", 1000, &func1);
void ROBOT::func1() {
}
void ROBOT::func2(){
_sub.wait_until_recieves_a_msg();
}
a hack would for example be:
_sub = nh_.subscribe("topic1", 1000, &func1);
void ROBOT::func1() {
called = True;
}
void ROBOT::func2(){
while(called==False){
}
called = False
}
I know my c++ syntax from above is not correct most likely, but you get the idea.
Yes you can.
@Orhan how
If I understand your question, and I may not, you would spin. http://wiki.ros.org/roscpp/Overview/C...
If I'm getting it correctly, you need to wait for the first message of something to arrive to start running a code block (...) in another subscriber.
void ROBOT::myAnotherSubscriber(MyMessage &msg) { if (!this->my_received_condition) {return;} ... }
and the other one,void ROBOT::myStarterSubscriber(MyMessage &msg) { this->my_received_condition = true; }
Or if the another one isn't also a subscriber, just make it a timer and start the timer when the condition(s) are met: http://wiki.ros.org/roscpp/Overview/T...