Revision history [back]

Based on your comments, I guess this is the situation (correct me if I'm wrong):

• You're implementing a control system in your ROS node that you want to run at 100 Hz.
• The input messages arrive at 5 Hz.
• Your control logic happens in the callback method; since the messages only arrive at 5 Hz, the control logic also runs at 5 Hz instead of 100 Hz.

The solution is not to increase the input frequency to 100 Hz by repeating each message 20 times. The solution is to move your control logic out of the callback method.

Your code probably looks something like this:

callback(input_msg) {
runControlSystem(input_msg);
}

main() {
subscribe(..., callback);
ros::spin();
}


Instead, it should look like this:

last_input_;

callback(input_msg) {
last_input_ = input_msg;
}

main() {
subscribe(..., callback);

ros::Rate r(100); // 100 hz
while (ros::ok()) {
ros::spinOnce();    // this will process all incoming messages and call your callback function.
// The difference to spin() is that spin() blocks, but spinOnce() returns
// so your code can continue.
runControlSystem(last_input_);
r.sleep();
}
}