Skip to content
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

Exit when objective is done befire timeout #69

Merged
merged 2 commits into from
Oct 24, 2024
Merged
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
16 changes: 12 additions & 4 deletions moveit_studio_py/examples/start_stop_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from moveit_msgs.msg import MoveItErrorCodes
from moveit_studio_py.objective_manager import ObjectiveManager

done = False


def done_cb(future: rclpy.task.Future) -> None:
"""
Expand All @@ -51,6 +53,8 @@ def done_cb(future: rclpy.task.Future) -> None:
print("Objective executed successfully!")
else:
print(f"MoveItErrorCode Value: {result.error_code.val}")
global done
done = True


def main():
Expand All @@ -74,14 +78,18 @@ def main():
objective_manager = ObjectiveManager()

print(f"Starting {args.objective_name}.")
global done
done = False
objective_manager.start_objective(
args.objective_name, blocking=False, async_callback=done_cb
)
cancel_time = time.time() + args.wait_time
while not done and time.time() < cancel_time:
time.sleep(1)

time.sleep(args.wait_time)

print(f"Stopping {args.objective_name}.")
objective_manager.stop_objective()
if not done:
print(f"Stopping {args.objective_name}.")
objective_manager.stop_objective()

rclpy.shutdown()

Expand Down
Loading