Skip to content

Commit aca43aa

Browse files
committed
Wait for lookup before attempting it
1 parent 1cd3ac5 commit aca43aa

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

ur_robot_driver/test/integration_test_force_mode.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,29 @@ def setUp(self):
121121
self.tf_buffer = Buffer()
122122
self.tf_listener = TransformListener(self.tf_buffer, self.node)
123123

124-
def lookup_tcp_in_base(self, tf_prefix, timepoint):
125-
trans = None
126-
while not trans:
127-
rclpy.spin_once(self.node)
124+
def wait_for_lookup(self, source, target, timepoint, timeout=5.0):
125+
"""
126+
Wait until the transform between source and target is available.
127+
128+
:param source: The source frame
129+
:param target: The target frame
130+
:param timeout: The point in time at which to make the lookup
131+
:param timeout: Timeout in seconds
132+
:return: transform between source and target at the given timepoint
133+
:raises TimeoutError: If the transform is not available within the timeout
134+
"""
135+
end_time = time.time() + timeout
136+
while time.time() < end_time:
128137
try:
129-
trans = self.tf_buffer.lookup_transform(
130-
tf_prefix + "base", tf_prefix + "tool0", timepoint
131-
)
138+
trans = self.tf_buffer.lookup_transform(source, target, timepoint)
139+
return trans
132140
except TransformException:
133-
pass
134-
return trans
141+
rclpy.spin_once(self.node)
142+
time.sleep(0.1)
143+
raise TimeoutError()
144+
145+
def lookup_tcp_in_base(self, tf_prefix, timepoint):
146+
return self.wait_for_lookup(tf_prefix + "base", tf_prefix + "tool0", timepoint)
135147

136148
# Implementation of force mode test to be reused
137149
# todo: If we move to pytest this could be done using parametrization
@@ -201,6 +213,9 @@ def run_force_mode(self, tf_prefix):
201213
),
202214
header=trans_after.header,
203215
)
216+
self.wait_for_lookup(
217+
diff.header.frame_id, tf_prefix + "tool0_controller", diff.header.stamp
218+
)
204219
diff_in_tool0_controller = self.tf_buffer.transform(
205220
diff,
206221
tf_prefix + "tool0_controller",

0 commit comments

Comments
 (0)