ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
From rospy
Time wiki entry,
rospy.Rate(hz)
rospy provides a rospy.Rate convenience class which makes a best effort at maintaining a particular rate for a loop. For example:
r = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): pub.publish("hello") r.sleep()
In the above example, the
Rate
instance will attempt to keep the loop at 10hz by accounting for the time used by any operations during the loop.Rate.sleep()
can throw arospy.ROSInterruptException
if the sleep is interrupted by shutdown.
Basically, it allows your loops to run at (nearly) the exact rate (in Hz) that you specify. It's a pretty standard way of looping with ROS
. Check out the source code that's linked to in the documentation that you were looking at:
87 - def sleep(self):
88 """
89 Attempt sleep at the specified rate. sleep() takes into
90 account the time elapsed since the last successful
91 sleep().
92
93 @raise ROSInterruptException: if ROS shutdown occurs before
94 sleep completes
95 @raise ROSTimeMovedBackwardsException: if ROS time is set
96 backwards
97 """
98 curr_time = rospy.rostime.get_rostime()
99 sleep(self._remaining(curr_time))
100 self.last_time = self.last_time + self.sleep_dur
101
102 # detect time jumping forwards, as well as loops that are
103 # inherently too slow
104 if curr_time - self.last_time > self.sleep_dur * 2:
105 self.last_time = curr_time
Go through the rospy
tutorials if you haven't already. From the writing a publisher and subscriber tutorial:
`rate = rospy.Rate(10) # 10hz`
This line creates a Rate object rate. With the help of its method sleep(), it offers a convenient way for looping at the desired rate. With its argument of 10, we should expect to go through the loop 10 times per second (as long as our processing time does not exceed 1/10th of a second!)
2 | No.2 Revision |
From rospy
Time wiki entry,
rospy.Rate(hz)
rospy provides a rospy.Rate convenience class which makes a best effort at maintaining a particular rate for a loop. For example:
r = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): pub.publish("hello") r.sleep()
In the above example, the
Rate
instance will attempt to keep the loop at 10hz by accounting for the time used by any operations during the loop.Rate.sleep()
can throw arospy.ROSInterruptException
if the sleep is interrupted by shutdown.
Basically, it allows your loops to run at (nearly) the exact rate (in Hz) that you specify. It's a pretty standard way of looping with ROS
. Check out the source code that's linked to in the documentation that you were looking at:
87 - def sleep(self):
88 """
89 Attempt sleep at the specified rate. sleep() takes into
90 account the time elapsed since the last successful
91 sleep().
92
93 @raise ROSInterruptException: if ROS shutdown occurs before
94 sleep completes
95 @raise ROSTimeMovedBackwardsException: if ROS time is set
96 backwards
97 """
98 curr_time = rospy.rostime.get_rostime()
99 sleep(self._remaining(curr_time))
100 self.last_time = self.last_time + self.sleep_dur
101
102 # detect time jumping forwards, as well as loops that are
103 # inherently too slow
104 if curr_time - self.last_time > self.sleep_dur * 2:
105 self.last_time = curr_time
Go through the rospy
tutorials if you haven't already. From the writing a publisher and subscriber tutorial:
`raterate = rospy.Rate(10) #10hz`10hzThis line creates a Rate object rate. With the help of its method sleep(), it offers a convenient way for looping at the desired rate. With its argument of 10, we should expect to go through the loop 10 times per second (as long as our processing time does not exceed 1/10th of a second!)
3 | No.3 Revision |
From rospy
Time wiki entry,
rospy.Rate(hz)
rospy provides a rospy.Rate convenience class which makes a best effort at maintaining a particular rate for a loop. For example:
r = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): pub.publish("hello") r.sleep()
In the above example, the
Rate
instance will attempt to keep the loop at 10hz by accounting for the time used by any operations during the loop.Rate.sleep()
can throw arospy.ROSInterruptException
if the sleep is interrupted by shutdown.
Basically, it allows your loops to run at (nearly) the exact rate (in Hz) that you specify. It's a pretty standard way of looping with ROS
. Check out the source code that's linked to in the documentation that you were looking at:
87 - def sleep(self):
88 """
89 Attempt sleep at the specified rate. sleep() takes into
90 account the time elapsed since the last successful
91 sleep().
92
93 @raise ROSInterruptException: if ROS shutdown occurs before
94 sleep completes
95 @raise ROSTimeMovedBackwardsException: if ROS time is set
96 backwards
97 """
98 curr_time = rospy.rostime.get_rostime()
99 sleep(self._remaining(curr_time))
100 self.last_time = self.last_time + self.sleep_dur
101
102 # detect time jumping forwards, as well as loops that are
103 # inherently too slow
104 if curr_time - self.last_time > self.sleep_dur * 2:
105 self.last_time = curr_time
Go through the rospy
tutorials if you haven't already. From the writing a publisher and subscriber tutorial:
rate = rospy.Rate(10) # 10hz
This line creates a
RateRate
objectrate.rate
. With the help of its methodsleep(),sleep()
, it offers a convenient way for looping at the desired rate. With its argument of10,10
, we should expect to go through the loop 10 times per second (as long as our processing time does not exceed 1/10th of a second!)
4 | No.4 Revision |
From rospy
Time wiki entry,
rospy.Rate(hz)
rospy provides a rospy.Rate convenience class which makes a best effort at maintaining a particular rate for a loop. For example:
r = rospy.Rate(10) # 10hz whilenotnot rospy.is_shutdown():pub.publish("hello")r.sleep()r.sleep()In the above example, the
Rate
instance will attempt to keep the loop at 10hz by accounting for the time used by any operations during the loop.Rate.sleep()
can throw arospy.ROSInterruptException
if the sleep is interrupted by shutdown.
Basically, it allows your loops to run at (nearly) the exact rate (in Hz) that you specify. It's a pretty standard way of looping with ROS
. Check out the source code that's linked to in the documentation that you were looking at:
87 - def sleep(self):
88 """
89 Attempt sleep at the specified rate. sleep() takes into
90 account the time elapsed since the last successful
91 sleep().
92
93 @raise ROSInterruptException: if ROS shutdown occurs before
94 sleep completes
95 @raise ROSTimeMovedBackwardsException: if ROS time is set
96 backwards
97 """
98 curr_time = rospy.rostime.get_rostime()
99 sleep(self._remaining(curr_time))
100 self.last_time = self.last_time + self.sleep_dur
101
102 # detect time jumping forwards, as well as loops that are
103 # inherently too slow
104 if curr_time - self.last_time > self.sleep_dur * 2:
105 self.last_time = curr_time
Go through the rospy
tutorials if you haven't already. From the writing a publisher and subscriber tutorial:
rate = rospy.Rate(10) # 10hz
This line creates a
Rate
objectrate
. With the help of its methodsleep()
, it offers a convenient way for looping at the desired rate. With its argument of10
, we should expect to go through the loop 10 times per second (as long as our processing time does not exceed 1/10th of a second!)
5 | No.5 Revision |
From rospy
Time wiki entry,
rospy.Rate(hz)
rospy provides a rospy.Rate convenience class which makes a best effort at maintaining a particular rate for a loop. For example:
r = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): pub.publish("hello") r.sleep()
In the above example, the
Rate
instance will attempt to keep the loop at 10hz by accounting for the time used by any operations during the loop.Rate.sleep()
can throw arospy.ROSInterruptException
if the sleep is interrupted by shutdown.
Basically, it allows your loops to run at (nearly) the exact rate (in Hz) that you specify. It's a pretty standard way of looping with ROS
. Check out the source code that's linked to in the documentation that you were looking at:
87 - def sleep(self):
88 """
89 Attempt sleep at the specified rate. sleep() takes into
90 account the time elapsed since the last successful
91 sleep().
92
93 @raise ROSInterruptException: if ROS shutdown occurs before
94 sleep completes
95 @raise ROSTimeMovedBackwardsException: if ROS time is set
96 backwards
97 """
98 curr_time = rospy.rostime.get_rostime()
99 sleep(self._remaining(curr_time))
100 self.last_time = self.last_time + self.sleep_dur
101
102 # detect time jumping forwards, as well as loops that are
103 # inherently too slow
104 if curr_time - self.last_time > self.sleep_dur * 2:
105 self.last_time = curr_time
Go through the rospy
tutorials if you haven't already. From the writing a publisher and subscriber tutorial:
rate = rospy.Rate(10) # 10hz
This line creates a
Rate
objectrate
. With the help of its methodsleep()
, it offers a convenient way for looping at the desired rate. With its argument of10
, we should expect to go through the loop 10 times per second (as long as our processing time does not exceed 1/10th of a second!)
6 | No.6 Revision |
From rospy
Time wiki entry,
rospy.Rate(hz)
rospy provides a rospy.Rate convenience class which makes a best effort at maintaining a particular rate for a loop. For example:
r = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): pub.publish("hello") r.sleep()
In the above example, the
Rate
instance will attempt to keep the loop at 10hz by accounting for the time used by any operations during the loop.Rate.sleep()
can throw arospy.ROSInterruptException
if the sleep is interrupted by shutdown.
Basically, it allows your loops to run at (nearly) the exact rate (in Hz) that you specify. It's a pretty standard way of looping with ROS
. Check out the source code that's linked to in the documentation that you were looking at:
87 - def sleep(self):
88 """
89 Attempt sleep at the specified rate. sleep() takes into
90 account the time elapsed since the last successful
91 sleep().
92
93 @raise ROSInterruptException: if ROS shutdown occurs before
94 sleep completes
95 @raise ROSTimeMovedBackwardsException: if ROS time is set
96 backwards
97 """
98 curr_time = rospy.rostime.get_rostime()
99 sleep(self._remaining(curr_time))
100 self.last_time = self.last_time + self.sleep_dur
101
102 # detect time jumping forwards, as well as loops that are
103 # inherently too slow
104 if curr_time - self.last_time > self.sleep_dur * 2:
105 self.last_time = curr_time
Go through the rospy
tutorials if you haven't already. From the writing a publisher and subscriber tutorial:
rate = rospy.Rate(10) # 10hz
This line creates a
Rate
objectrate
. With the help of its methodsleep()
, it offers a convenient way for looping at the desired rate. With its argument of10
, we should expect to go through the loop 10 times per second (as long as our processing time does not exceed 1/10th of a second!)