Skip to content

Commit

Permalink
Make toggle collision object asynch
Browse files Browse the repository at this point in the history
  • Loading branch information
amalnanavati committed Sep 15, 2023
1 parent 7ec8a91 commit 1ae3d73
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions ada_feeding/ada_feeding/behaviors/toggle_collision_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ def __init__(
callback_group=callback_group,
)

# pylint: disable=attribute-defined-outside-init
# For attributes that are only used during the execution of the tree
# and get reset before the next execution, it is reasonable to define
# them in `initialise`.
def initialise(self) -> None:
"""
Reset the service_future.
"""
self.logger.info(f"{self.name} [ToggleCollisionObject::initialise()]")

self.service_future = None

def update(self) -> py_trees.common.Status:
"""
(Dis)allow collisions between the robot and a collision
Expand All @@ -79,9 +91,22 @@ def update(self) -> py_trees.common.Status:
"""
self.logger.info(f"{self.name} [ToggleCollisionObject::update()]")
# (Dis)allow collisions between the robot and the collision object
succ = self.moveit2.allow_collisions(self.collision_object_id, self.allow)
if self.service_future is None:
service_future = self.moveit2.allow_collisions(
self.collision_object_id, self.allow
)
if service_future is None: # service not available
return py_trees.common.Status.FAILURE
self.service_future = service_future
return py_trees.common.Status.RUNNING

# Check if the service future is done
if self.service_future.done():
succ = self.moveit2.process_allow_collision_future(self.service_future)
# Return success/failure
if succ:
return py_trees.common.Status.SUCCESS
return py_trees.common.Status.FAILURE

# Return success
if succ:
return py_trees.common.Status.SUCCESS
return py_trees.common.Status.FAILURE
# Return running
return py_trees.common.Status.RUNNING

0 comments on commit 1ae3d73

Please sign in to comment.