Skip to content

Commit

Permalink
cleaning up rclpy types
Browse files Browse the repository at this point in the history
  • Loading branch information
EzraBrooks committed Apr 24, 2024
1 parent b137efd commit 324b3da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 9 additions & 7 deletions moveit_studio_py/examples/start_stop_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@

import argparse
import rclpy
from rclpy.task import Future
import time

from moveit_msgs.msg import MoveItErrorCodes
from moveit_studio_py.objective_manager import ObjectiveManager


def done_cb(future: rclpy.task.Future) -> None:
def done_cb(future: Future) -> None:
"""
Callback that is triggered when an Objective that was started asynchronously is done executing.
Args:
future: the Objective's future, which contains info about the completion status of the Objective.
"""
result = future.result()
if result.error_code.val == MoveItErrorCodes.SUCCESS:
print("Objective executed successfully!")
elif result.error_message:
print(result.error_message)
else:
print(f"MoveItErrorCode Value: {result.error_code.val}")
if result is not None:
if result.error_code.val == MoveItErrorCodes.SUCCESS:
print("Objective executed successfully!")
elif result.error_message:
print(result.error_message)
else:
print(f"MoveItErrorCode Value: {result.error_code.val}")


def main():
Expand Down
9 changes: 6 additions & 3 deletions moveit_studio_py/moveit_studio_py/objective_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

import threading
import rclpy
from rclpy.executors import MultiThreadedExecutor
from rclpy.task import Future

from collections.abc import Callable
from typing import Optional
from moveit_msgs.msg import MoveItErrorCodes
from moveit_studio_sdk_msgs.msg import BehaviorParameter
from moveit_studio_sdk_msgs.srv import CancelObjective, ExecuteObjective
Expand All @@ -48,7 +51,7 @@ def __init__(self):
"""
Constructor.
"""
self._node = rclpy.create_node("moveit_studio_objective_manager")
self._node = rclpy.create_node("moveit_studio_objective_manager") # type: ignore

self._execute_objective_client = self._node.create_client(
ExecuteObjective, self.__EXECUTE_OBJECTIVE_SERVICE
Expand All @@ -66,7 +69,7 @@ def __init__(self):
f"{self.__CANCEL_OBJECTIVE_SERVICE} service not available."
)

self._executor = rclpy.executors.MultiThreadedExecutor()
self._executor = MultiThreadedExecutor()
self._executor.add_node(self._node)
self._executor_thread = threading.Thread(
target=self._executor.spin, daemon=True
Expand All @@ -87,7 +90,7 @@ def start_objective(
objective_name: str,
parameter_overrides: list[BehaviorParameter] = [],
blocking: bool = True,
async_callback: Callable[[rclpy.task.Future], None] = None,
async_callback: Optional[Callable[[Future], None]] = None,
) -> tuple[bool, str]:
"""
Run an Objective.
Expand Down

0 comments on commit 324b3da

Please sign in to comment.