ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Is there a way to control Subscriber callback frequency while using rospy.spin() ?

asked 2020-11-06 16:19:48 -0500

updated 2020-11-06 16:21:10 -0500

let's say, we have a Subscriber node that looks like this -


import rospy
from std_msgs.msg import String 

def callback(data) :

    print "Inside callback: " , data 

if __name__ == '__main__' : 


    rate = rospy.Rate(1) 

    s1 = rospy.Subscriber('/test_topic' , String, callback, queue_size = 1)


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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-11-06 16:53:54 -0500

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.

edit flag offensive delete link more

Question Tools



Asked: 2020-11-06 16:19:48 -0500

Seen: 1,825 times

Last updated: Nov 06 '20