Wait for timer to be stopped
Hi everybody, I'm working on a state_machine right now and I have the following problem: I have a ROS timer running on a timerCallback which supervises the current states and depending on the state does different things. I need this, because I'm waiting for different messages on other subscriber callbacks at the same time and this was (I think) the best possibility to manage those subscribers (Maybe an async spinner could have worked, but anyway, I now have a timer). Since this is only a single part of a larger state-machine I now need to know, when the timer has stopped since this whole system is supposed to be wrapped into one single actionserver, which returns, when the whole task is completed. So now to me actual question: Does anybody know, if there is a possibility to let the timer and all other callbacks run, while the actual execute function of the actionserver waits for the timer to be stopped?
A small example (maybe it helps):
class Foo {
void startTimer(){
timer_ = nh_->createTimer(ros::Duration(0.1), &timerCB, this);
}
void timerCB(const ros::TimerEvent& timer_event){
//Do something depending on state and stop timer if finished
}
void secondCB(const custom_msg::Msg msg){
//Change state if necessary
}
}
class Bar {
executeCB(const actionlib_msgs::ExampleGoalConstPtr& goal){
foo.startTimer();
//Wait for timer to stop
return true;
}
}