# Purpose of rate.sleep()

**URL:** <https://get-help.theconstruct.ai/t/purpose-of-rate-sleep/24830>\
**Category:** ROS Basics In 5 Days (Python)\
**Created:** [June 9, 2023, 7:56pm UTC](https://get-help.theconstruct.ai/t/purpose-of-rate-sleep/24830 "2023-06-09T19:56:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haadiakhter](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/h/a698b9/32.png) [@haadiakhter](https://get-help.theconstruct.ai/u/haadiakhter)\
**Post date:** [June 9, 2023, 7:56pm UTC](https://get-help.theconstruct.ai/t/purpose-of-rate-sleep/24830/1 "2023-06-09T19:56:37Z")

</div>

def publish\_once\_in\_cmd\_vel(self):  
“”"  
This is because publishing in topics sometimes fails the first time you publish.  
In continuous publishing systems, this is no big deal, but in systems that publish only  
once, it IS very important.  
“”"  
while not self.ctrl\_c:  
connections = self.bb8\_vel\_publisher.get\_num\_connections()  
if connections \> 0:  
self.bb8\_vel\_publisher.publish(self.cmd)  
rospy.loginfo(“Cmd Published”)  
break  
else:  
self.rate.sleep()

What is the purpose of rate.sleep() function here?

---

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/10684_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [June 12, 2023, 10:52am UTC](https://get-help.theconstruct.ai/t/purpose-of-rate-sleep/24830/2 "2023-06-12T10:52:58Z")

</div>

Please see:

- [Proper use of rospy.Rate or ros::Rate](https://get-help.robotigniteacademy.com/t/proper-use-of-rospy-rate-or-ros-rate/59)

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [June 17, 2023, 10:53am UTC](https://get-help.theconstruct.ai/t/purpose-of-rate-sleep/24830/3 "2023-06-17T10:53:00Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
