How to pull a message from queue with time interval?
When I subscribe my node, I set messages queue size and callback function:
int main(int argc, char **argv) {
ros::init(argc, argv, "scs_drive");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("scs", 1000, writePosCallback);
ros::spin();
return 0;
}
The incoming messages are being processed as soon as previous callback function operations are finished. But I want to process incoming messages from queue not ASAP but each millisecond.
So maybe it is possible to pull messages here:
int main(int argc, char **argv) {
ros::init(argc, argv, "scs_drive");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("scs", 1000, writePosCallback);
ros::Rate loop_rate(1000);
while (ros::ok()) {
//some code here that pulls message from queue and process incoming data
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
Or I need to set pause in callback function and it is the one choice to process messages with a certain time interval?