Is there a method to make ros::spinOnce() call a specific number of callbacks from the callback queue?

asked 2017-01-12 09:57:15 -0600

Ros User gravatar image

I am writing a program in ROS that should perform certain computations after each callback function. My callback function basically subscribes to a topic and sets the value of a variable which is used to perform a specific computation. The topic that I am subscribing to has a frequency of 30 Hz. So, I have a while loop in my program that runs at the rate of 30 Hz. The loop is somewhat similar to the following code: while (ros::ok()) { ros::spinOnce(); //this should set a certain variable "a" perform_computation(); //this performs computation on the variable 'a' looprate.sleep(); //this runs at 30 Hz } The variable 'a' is a private variable of a class and the loop runs inside the constructor of the same class. I want to perform computation after each callback function is called. But ros::spinOnce() seems to call all the callback functions present in the queue. Is it possible to make it call only 1 or 2 callback functions from the queue?

edit retag flag offensive close merge delete