ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
You cannot control how often your subscriber callback is called. roscpp will attempt to call your callback once for every message that is received.
If you can change the publish rate, that's the most obvious way to change how often your callback is called, but it will affect every node subscribing to that topic, and how you change the publish rate depends on the node that is publishing. You don't say which node is publishing these messages, so I can't give more specific advice.
If you can't change the publisher (either it affects other nodes or the code doesn't allow it), you can use the topic_tools throttle node to subscribe to the topic and publish it at a slower rate.
Depending on what you're trying to do, you could also implement the callback throttling in your own code; I see two ways to do this:
There are additional tradeoffs between all of these approaches, but without knowing why you want to subscribe at a slower rater, I can't give more specific advice.
2 | No.2 Revision |
You cannot control how often your subscriber callback is called. roscpp will attempt to call your callback once for every message that is received.
If you can change the publish rate, that's the most obvious way to change how often your callback is called, but it will affect every node subscribing to that topic, and how you change the publish rate depends on the node that is publishing. You don't say which node is publishing these messages, so I can't give more specific advice.
If you can't change the publisher (either it affects other nodes or the code doesn't allow it), you can use the topic_tools throttlethrottle node to subscribe to the topic and publish it at a slower rate.
Depending on what you're trying to do, you could also implement the callback throttling in your own code; I see two ways to do this:
There are additional tradeoffs between all of these approaches, but without knowing why you want to subscribe at a slower rater, I can't give more specific advice.