![]() | 1 | initial version |
Based on your comments, I guess this is the situation (correct me if I'm wrong):
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();
}
}