Problem with image_transport callback
I have the next scenario,
class controller :
{
public:
controller(ros::NodeHandle node);
~controller(void);
// The callbacks are implemented correctly
void imageCallback(const sensor_msgs::ImageConstPtr& msg);
void navdataCallback(const ardrone_autonomy::Navdata& data);
void foo(){
// Do Something
std::thread foo_thread(&controller::foo2, this);
foo_thread.join();
}
void foo2(){
// Do Something
while (something){
// Do Something
std::this_thread::sleep_for(std::chrono::milliseconds(20));
ros::spinOnce();
}
}
private:
//Other Stuff
}
and the main program is
int main(int argc, char **argv)
{
ros::init(argc,argv, "main");
ros::NodeHandle n;
controller control(n);
image_transport::ImageTransport it(n);
image_transport::Subscriber sub = it.subscribe("ardrone/image_raw", 1, &controller::imageCallback, &control);
ros::Subscriber navdata = n.subscribe("ardrone/navdata", 1000, &controller::navdataCallback, &control);
while(ros::ok()){
ros::spin();
}
return 0;
}
the problem is when I process data in foo2() the navdata messages arrives fine, but stop reciving image data until the end of the thread.
How can I resolve this? Is my approach correct? May be the ros::spinOnce is not placed correctly?