-
Notifications
You must be signed in to change notification settings - Fork 229
[WIP]: WaitForTransform Python (#194) #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| 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. | ||
|
|
@@ -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): | ||
| """ | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to say it would be nice if
fut.result()returned the transform that was being waited for instead ofTrue.