Acquiring new data/message from a subscribed topic
I have subscribed to the following topic
/camera/depth_registered/points
I have a callback function defined as the following in a c++ file :
ros::Subscriber sub = nh.subscribe ( "/camera/depth_registered/points", 1, process_cloud );
1) I want to obtain the latest data from the above topic when I want it. Is there a way to acquire the latest data from the topic whenever I want inside my callback function ?
I also tried a workaround using the ros::spinOnce() function. But sometimes my callback function does not get called.
2) When and why will this happen ? - the callback function not being called.
3) Is there a way to check if the callback got called when using the ros::spinOnce() ?
- proccess_cloud is the only callback function i have in my program
- I am using ros - groovy on a Ubuntu-12.04 machine
I appreciate any help anyone can provide. Please post if you require anymore information.
___ UPDATE ____
Essentially this is what I am trying to do :
1) I have a UDP communication setup in the above program, between the computer that runs the above code that I am having an issue with, I will call this PC 1
2) PC2 sends a request to PC1 over UDP communication - at which time i want to acquire latest data from my Prime Sense Carmine 1.09 sensor.
3) Thus in my above code, in PC1, I want to wait for this UDP request and then acquire a data from the prime Sense sensor and process the data.
I have tried two versions of code to accomplish the above problem
a) 1st version - I use the UDP - recvfrom function inside the callback function : thus the code essentially gets held at this line waiting to request from PC2(which how the recvfrom function works). And when it recieves the request from PC2 rest of the processing occurs - thus working on old data. Which led to my question here as to how to obtain new data in my callback function.
b) To work around the above problem I came up with the 2nd version : Here I use the spinOnce function , thus in my main function I wait for the request from PC2 using the recvfrom function. And then I use spinOnce function - to run my callback function. All this essentially inside a while loop. - But in this case sometimes the callback does not get called sometime. - Also in this case is it ensured that the latest available data from my topic used ?
And my 1st line in the callback function a print to the command line saying I was called ( using std::cout ). Which is how I figure out that the callback does not get called( in my 2nd case).
I am using the following command to obtain data from the prime sense sensor.
roslaunch openni_launch openni.launch
Also is this the best way to obtain data from the prime sense sensor