33
33
from tf2_msgs .srv import FrameGraph , FrameGraphResponse
34
34
import rosgraph .masterapi
35
35
36
+ DEFAULT_CAN_TRANSFORM_POLLING_SCALE = 0.01
37
+
36
38
class Buffer (tf2 .BufferCore , tf2_ros .BufferInterface ):
37
39
"""
38
40
Standard implementation of the :class:`tf2_ros.BufferInterface` abstract data type.
@@ -67,6 +69,8 @@ def __init__(self, cache_time = None, debug = True):
67
69
except (rosgraph .masterapi .Error , rosgraph .masterapi .Failure ):
68
70
self .frame_server = rospy .Service ('~tf2_frames' , FrameGraph , self .__get_frames )
69
71
72
+ self .CAN_TRANSFORM_POLLING_SCALE = DEFAULT_CAN_TRANSFORM_POLLING_SCALE
73
+
70
74
def __get_frames (self , req ):
71
75
return FrameGraphResponse (self .all_frames_as_yaml ())
72
76
@@ -116,11 +120,11 @@ def can_transform(self, target_frame, source_frame, time, timeout=rospy.Duration
116
120
"""
117
121
if timeout != rospy .Duration (0.0 ):
118
122
start_time = rospy .Time .now ()
119
- r = rospy . Rate ( 20 )
123
+ polling_interval = timeout * self . CAN_TRANSFORM_POLLING_SCALE
120
124
while (rospy .Time .now () < start_time + timeout and
121
125
not self .can_transform_core (target_frame , source_frame , time )[0 ] and
122
126
(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 )
124
128
core_result = self .can_transform_core (target_frame , source_frame , time )
125
129
if return_debug_tuple :
126
130
return core_result
@@ -146,11 +150,11 @@ def can_transform_full(self, target_frame, target_time, source_frame, source_tim
146
150
"""
147
151
if timeout != rospy .Duration (0.0 ):
148
152
start_time = rospy .Time .now ()
149
- r = rospy . Rate ( 20 )
153
+ polling_interval = timeout * self . CAN_TRANSFORM_POLLING_SCALE
150
154
while (rospy .Time .now () < start_time + timeout and
151
155
not self .can_transform_full_core (target_frame , target_time , source_frame , source_time , fixed_frame )[0 ] and
152
156
(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 )
154
158
core_result = self .can_transform_full_core (target_frame , target_time , source_frame , source_time , fixed_frame )
155
159
if return_debug_tuple :
156
160
return core_result
0 commit comments