How to invoke callback functions sequentially [closed]
This is how my main looks like:
ros::init(argc,argv,"moving");
ros::NodeHandle n1;
ros::NodeHandle n2;
image_transport::ImageTransport it(n1);
image_transport::ImageTransport it1(n2);
image_transport::Subscriber sub1 = it1.subscribe("camera/rgb/image_color", 1, imageCallback);
image_transport::Subscriber sub2 = it.subscribe("camera/depth/image", 1, depthCallback);
ros::Rate r(10);
while(ros::ok()){
ros::spinOnce();
r.sleep();
}
I need to first invoke imageCallback and use data it generates in depthCallback function. But ros::spinOnce() calls them in a random order. How do I call them sequentially, in the order listed, first imageCallback then depthCallback?