Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions tf2_ros/src/tf2_ros/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ def can_transform_full(self, target_frame, target_time, source_frame, source_tim
return core_result
return core_result[0]

def _wait_for_transform_async(self, target_Frame, source_frame, time, callback):
fut = rclpy.task.Future()
if self.can_transform_core(target_frame, source_frame, time)[0]:
# Short cut, the transform is available
fut.set_result(True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On #194 you wrote:

the result on future doesn't contain any info about the transform. It should probably have that.

Can you please clarify what information you're hoping to propagate up?

I was trying to say it would be nice if fut.result() returned the transform that was being waited for instead of True.

return fut

self._new_data_callbacks.append(callback)
fut.add_done_callback(lambda _: self._remove_callback(callback))

return fut

def wait_for_transform_async(self, target_frame, source_frame, time):
"""
Wait for a transform from the source frame to the target frame to become possible.
Expand All @@ -228,23 +240,15 @@ def wait_for_transform_async(self, target_frame, source_frame, time):
:return: A future that becomes true when the transform is available
:rtype: rclpy.task.Future
"""
fut = rclpy.task.Future()
if self.can_transform_core(target_frame, source_frame, time)[0]:
# Short cut, the transform is available
fut.set_result(True)
return fut

def _on_new_data():
try:
if self.can_transform_core(target_frame, source_frame, time)[0]:
fut.set_result(True)
except BaseException as e:
fut.set_exception(e)

self._new_data_callbacks.append(_on_new_data)
fut.add_done_callback(lambda _: self._remove_callback(_on_new_data))
return _wait_for_transform_async(self, target_frame, source_frame, time, _on_new_data)

return fut

def wait_for_transform_full_async(self, target_frame, target_time, source_frame, source_time, fixed_frame):
"""
Expand Down Expand Up @@ -275,3 +279,6 @@ def _on_new_data():
fut.add_done_callback(lambda _: self._remove_callback(_on_new_data))

return fut

def wait_for_transform(target_frame, source_frame, time, callback):
return _wait_for_transform_async(target_frame, source_frame, time, callback)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding wait_for_transform(..., callback), with ros2/rclpy#460 merged I think the utility #194 is asking for can be had by making the result on the future returned by wait_for_transform_async() contain the transform data. The interface someone would use is fut = wait_for_transform_async(...); fut.add_done_callback(my_tf_callback).