Skip to content

Commit

Permalink
Removed top level pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
amessing-bdai committed Dec 6, 2023
1 parent f4b9e9d commit 160438d
Show file tree
Hide file tree
Showing 36 changed files with 581 additions and 254 deletions.
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ repos:
rev: 'v0.0.263'
hooks:
- id: ruff
args: ['--fix', '--config', 'pyproject.toml']
args: ['--fix', '--config', 'configs/ruff.toml']
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3.10
args: ['--config', 'pyproject.toml']
args: ['--config', 'configs/black.toml']
verbose: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -32,6 +32,7 @@ repos:
rev: v1.2.0
hooks:
- id: mypy
args: ['--config-file', 'configs/mypy.ini']
pass_filenames: false
additional_dependencies:
- types-protobuf
Expand Down
22 changes: 17 additions & 5 deletions bdai_ros2_wrappers/bdai_ros2_wrappers/action_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
class ActionClientWrapper(rclpy.action.ActionClient):
"""A wrapper for ros2's ActionClient for extra functionality"""

def __init__(self, action_type: Type[Action], action_name: str, node: Optional[Node] = None) -> None:
def __init__(
self, action_type: Type[Action], action_name: str, node: Optional[Node] = None
) -> None:
"""Constructor
Args:
Expand All @@ -22,7 +24,9 @@ def __init__(self, action_type: Type[Action], action_name: str, node: Optional[N
"""
node = node or scope.node()
if node is None:
raise ValueError("no ROS 2 node available (did you use bdai_ros2_wrapper.process.main?)")
raise ValueError(
"no ROS 2 node available (did you use bdai_ros2_wrapper.process.main?)"
)
self._node = node
super().__init__(self._node, action_type, action_name)
self._node.get_logger().info(f"Waiting for action server for {action_name}")
Expand Down Expand Up @@ -60,7 +64,9 @@ def _on_failure() -> None:
nonlocal failed
failed = True

handle = self.send_goal_async_handle(action_name=action_name, goal=goal, on_failure_callback=_on_failure)
handle = self.send_goal_async_handle(
action_name=action_name, goal=goal, on_failure_callback=_on_failure
)
handle.set_on_cancel_success_callback(_on_cancel_succeeded)
if not handle.wait_for_result(timeout_sec=timeout_sec):
# If the action didn't fail and wasn't canceled then it timed out and should be canceled
Expand Down Expand Up @@ -96,7 +102,11 @@ def send_goal_async_handle(
Returns:
ActionHandle: An object to manage the asynchronous lifecycle of the action request
"""
handle = ActionHandle(action_name=action_name, logger=self._node.get_logger(), context=self._node.context)
handle = ActionHandle(
action_name=action_name,
logger=self._node.get_logger(),
context=self._node.context,
)
if result_callback is not None:
handle.set_result_callback(result_callback)

Expand All @@ -107,7 +117,9 @@ def send_goal_async_handle(
send_goal_future = self.send_goal_async(goal)
else:
handle.set_feedback_callback(feedback_callback)
send_goal_future = self.send_goal_async(goal, feedback_callback=handle.get_feedback_callback)
send_goal_future = self.send_goal_async(
goal, feedback_callback=handle.get_feedback_callback
)
handle.set_send_goal_future(send_goal_future)

return handle
26 changes: 20 additions & 6 deletions bdai_ros2_wrappers/bdai_ros2_wrappers/action_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class ActionHandle(object):
as holding the various callbacks for sending an ActionGoal (cancel, failure, feedback, result)
"""

def __init__(self, action_name: str, logger: Optional[RcutilsLogger] = None, context: Optional[Context] = None):
def __init__(
self,
action_name: str,
logger: Optional[RcutilsLogger] = None,
context: Optional[Context] = None,
):
"""Constructor
Args:
Expand Down Expand Up @@ -68,7 +73,8 @@ def wait_for_result(self, timeout_sec: Optional[float] = None) -> bool:
True if successful; False if the timeout was triggered or the action was rejected, cancelled, or abort
"""
return self._wait_for_result_event.wait(timeout=timeout_sec) and (
self._result is not None and self._result.status == GoalStatus.STATUS_SUCCEEDED
self._result is not None
and self._result.status == GoalStatus.STATUS_SUCCEEDED
)

def wait_for_acceptance(self, timeout_sec: Optional[float] = None) -> bool:
Expand All @@ -91,23 +97,31 @@ def set_send_goal_future(self, send_goal_future: Future) -> None:
self._send_goal_future = send_goal_future
self._send_goal_future.add_done_callback(self._goal_response_callback)

def set_feedback_callback(self, feedback_callback: Callable[[Action.Feedback], None]) -> None:
def set_feedback_callback(
self, feedback_callback: Callable[[Action.Feedback], None]
) -> None:
"""Sets the callback used to process feedback received while an Action is being executed"""
self._feedback_callback = feedback_callback

def set_result_callback(self, result_callback: Callable[[Action.Result], None]) -> None:
def set_result_callback(
self, result_callback: Callable[[Action.Result], None]
) -> None:
"""Sets the callback for processing the result from executing an Action"""
self._result_callback = result_callback

def set_on_failure_callback(self, on_failure_callback: Callable) -> None:
"""Set the callback to execute upon failure"""
self._on_failure_callback = on_failure_callback

def set_on_cancel_success_callback(self, on_cancel_success_callback: Callable) -> None:
def set_on_cancel_success_callback(
self, on_cancel_success_callback: Callable
) -> None:
"""Set the callback to execute upon successfully canceling the action"""
self._on_cancel_success_callback = on_cancel_success_callback

def set_on_cancel_failure_callback(self, on_cancel_failure_callback: Callable) -> None:
def set_on_cancel_failure_callback(
self, on_cancel_failure_callback: Callable
) -> None:
"""Set the callback to execute upon failing to cancel the action"""
self._on_cancel_failure_callback = on_cancel_failure_callback

Expand Down
4 changes: 3 additions & 1 deletion bdai_ros2_wrappers/bdai_ros2_wrappers/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from rclpy.utilities import get_default_context


def wait_for_shutdown(*, timeout_sec: Optional[float] = None, context: Optional[Context] = None) -> bool:
def wait_for_shutdown(
*, timeout_sec: Optional[float] = None, context: Optional[Context] = None
) -> bool:
"""
Wait for context shutdown.
Expand Down
Loading

0 comments on commit 160438d

Please sign in to comment.