Is there a way to control Subscriber callback frequency while using rospy.spin() ?
let's say, we have a Subscriber node that looks like this -
#!/usr/bin/python
import rospy
from std_msgs.msg import String
def callback(data) :
print "Inside callback: " , data
if __name__ == '__main__' :
rospy.init_node('test_subone')
rate = rospy.Rate(1)
s1 = rospy.Subscriber('/test_topic' , String, callback, queue_size = 1)
rospy.spin()
I have set rate = rospy.Rate(1).
Does this influence the rate at which the Subscriber s1
calls its callback function ?
Is there a way we can make rospy.spin()
to achieve this?
Is the rate at which the callback function is called only dependent on the rate at which /test_topic
is being published?
What happens when there are more than one Publishers publishing on /test_topic at different frequencies?
Are things different in case of rospy and roscpp?
Asked by skpro19 on 2020-11-06 17:19:48 UTC
Answers
You are not using the rate
variable, so it has no impact.
The callback will be called for each message published on the topic, no matter from whom and at what frequency (as long as the network/kernel can deliver). As far as I know this is the same in all implementations (roscpp, rospy, rosnodejs, etc.).
If you want to reduce the number of times you react to these messages, then you will need to do that using your own logic. In many languages there is a throttle function that takes another function as argument and produces a new one that will never be called more often than a specified frequency. So you could use that.
Asked by chfritz on 2020-11-06 17:53:54 UTC
Comments