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
}