-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-Added Async_sleep via asyncnode to control time spent digging and …
…dumping via yaml config dig_time and dump_time, set to 5 seconds atm in auto dig and dumper_node - we should probably standardize this
- Loading branch information
Showing
6 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from rclpy.action.server import CancelResponse, ServerGoalHandle | ||
from rclpy.node import Node | ||
from rclpy.task import Future | ||
|
||
from std_msgs.msg import Bool | ||
|
||
|
||
class AsyncNode(Node): | ||
def __init__(self, name: str): | ||
super().__init__(name) | ||
self.sleep_goal_reached = Future() | ||
self.sleep_goal_reached.set_result(None) | ||
|
||
self.timer = None | ||
|
||
# Temporary measure to sleep for time without needlessly spinning | ||
async def async_sleep(self, seconds: float) -> None: | ||
self.sleep_goal_reached = Future() | ||
|
||
def handler(): | ||
self.sleep_goal_reached.set_result(None) | ||
|
||
self.timer = self.create_timer(seconds, handler) | ||
await self.sleep_goal_reached | ||
self.timer.cancel() | ||
self.timer.destroy() | ||
|
||
def cancel_callback(self, cancel_request: ServerGoalHandle) -> None: | ||
if not self.sleep_goal_reached.done(): | ||
self.timer.cancel() | ||
self.timer.destroy() | ||
return CancelResponse.ACCEPT | ||
return CancelResponse.REJECT |
This will be not cancellable