Skip to content

Commit 5d17166

Browse files
authored
tf2_ros polling interval proportional to timeout (#492)
* polling interval proportional to timeout * CAN_TRANSFORM_POLLING_SCALE as global * add DEFAULT_CAN_TRANSFORM_POLLING_SCALE
1 parent 4f47bf4 commit 5d17166

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tf2_ros/src/tf2_ros/buffer.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
from tf2_msgs.srv import FrameGraph, FrameGraphResponse
3434
import rosgraph.masterapi
3535

36+
DEFAULT_CAN_TRANSFORM_POLLING_SCALE = 0.01
37+
3638
class Buffer(tf2.BufferCore, tf2_ros.BufferInterface):
3739
"""
3840
Standard implementation of the :class:`tf2_ros.BufferInterface` abstract data type.
@@ -67,6 +69,8 @@ def __init__(self, cache_time = None, debug = True):
6769
except (rosgraph.masterapi.Error, rosgraph.masterapi.Failure):
6870
self.frame_server = rospy.Service('~tf2_frames', FrameGraph, self.__get_frames)
6971

72+
self.CAN_TRANSFORM_POLLING_SCALE = DEFAULT_CAN_TRANSFORM_POLLING_SCALE
73+
7074
def __get_frames(self, req):
7175
return FrameGraphResponse(self.all_frames_as_yaml())
7276

@@ -116,11 +120,11 @@ def can_transform(self, target_frame, source_frame, time, timeout=rospy.Duration
116120
"""
117121
if timeout != rospy.Duration(0.0):
118122
start_time = rospy.Time.now()
119-
r= rospy.Rate(20)
123+
polling_interval = timeout * self.CAN_TRANSFORM_POLLING_SCALE
120124
while (rospy.Time.now() < start_time + timeout and
121125
not self.can_transform_core(target_frame, source_frame, time)[0] and
122126
(rospy.Time.now()+rospy.Duration(3.0)) >= start_time): # big jumps in time are likely bag loops, so break for them
123-
r.sleep()
127+
rospy.sleep(polling_interval)
124128
core_result = self.can_transform_core(target_frame, source_frame, time)
125129
if return_debug_tuple:
126130
return core_result
@@ -146,11 +150,11 @@ def can_transform_full(self, target_frame, target_time, source_frame, source_tim
146150
"""
147151
if timeout != rospy.Duration(0.0):
148152
start_time = rospy.Time.now()
149-
r= rospy.Rate(20)
153+
polling_interval = timeout * self.CAN_TRANSFORM_POLLING_SCALE
150154
while (rospy.Time.now() < start_time + timeout and
151155
not self.can_transform_full_core(target_frame, target_time, source_frame, source_time, fixed_frame)[0] and
152156
(rospy.Time.now()+rospy.Duration(3.0)) >= start_time): # big jumps in time are likely bag loops, so break for them
153-
r.sleep()
157+
rospy.sleep(polling_interval)
154158
core_result = self.can_transform_full_core(target_frame, target_time, source_frame, source_time, fixed_frame)
155159
if return_debug_tuple:
156160
return core_result

0 commit comments

Comments
 (0)