Skip to content

Commit

Permalink
Return execution status in GUI callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-bass committed Sep 8, 2024
1 parent a8f6b2a commit 2b6aa50
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions pyrobosim/pyrobosim/gui/world_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from pyrobosim.core.robot import Robot
from pyrobosim.navigation.visualization import plot_path_planner
from pyrobosim.planning.actions import ExecutionResult, ExecutionStatus
from pyrobosim.utils.motion import Path


Expand Down Expand Up @@ -515,18 +516,21 @@ def pick_object(self, robot, obj_name, grasp_pose=None):
:type obj_name: str
:param grasp_pose: A pose describing how to manipulate the object.
:type grasp_pose: :class:`pyrobosim.utils.pose.Pose`, optional
:return: True if picking succeeds, else False.
:rtype: bool
:return: An object describing the execution result.
:rtype: :class:`pyrobosim.planning.actions.ExecutionResult`
"""
if robot is None:
return False
return ExecutionResult(
status=ExecutionStatus.PRECONDITION_FAILURE,
message="Robot is not specified. Cannot pick.",
)

success = robot.pick_object(obj_name, grasp_pose)
if success:
result = robot.pick_object(obj_name, grasp_pose)
if result.is_success():
self.update_object_plot(robot.manipulated_object)
self.show_world_state(robot)
self.draw_signal.emit()
return success
return result

def place_object(self, robot, pose=None):
"""
Expand All @@ -536,24 +540,27 @@ def place_object(self, robot, pose=None):
:type robot: :class:`pyrobosim.core.robot.Robot`
:param pose: Optional placement pose, defaults to None.
:type pose: :class:`pyrobosim.utils.pose.Pose`, optional
:return: True if placing succeeds, else False.
:rtype: bool
:return: An object describing the execution result.
:rtype: :class:`pyrobosim.planning.actions.ExecutionResult`
"""
if robot is None:
return False
return ExecutionResult(
status=ExecutionStatus.PRECONDITION_FAILURE,
message="Robot is not specified. Cannot place.",
)

obj = robot.manipulated_object
if obj is None:
return
self.obj_patches.remove(obj.viz_patch)
obj.viz_patch.remove()
success = robot.place_object(pose=pose)
self.axes.add_patch(obj.viz_patch)
self.obj_patches.append(obj.viz_patch)
self.update_object_plot(obj)
if obj is not None:
self.obj_patches.remove(obj.viz_patch)
obj.viz_patch.remove()
result = robot.place_object(pose=pose)
if obj is not None:
self.axes.add_patch(obj.viz_patch)
self.obj_patches.append(obj.viz_patch)
self.update_object_plot(obj)
self.show_world_state(robot)
self.draw_signal.emit()
return success
return result

def detect_objects(self, robot, query=None):
"""
Expand All @@ -563,11 +570,14 @@ def detect_objects(self, robot, query=None):
:type robot: :class:`pyrobosim.core.robot.Robot`
:param query: Query for object detection.
:type query: str, optional
:return: True if object detection succeeds, else False.
:rtype: bool
:return: An object describing the execution result.
:rtype: :class:`pyrobosim.planning.actions.ExecutionResult`
"""
if robot is None:
return False
return ExecutionResult(
status=ExecutionStatus.PRECONDITION_FAILURE,
message="Robot is not specified. Cannot detect objects.",
)

success = robot.detect_objects(query)
self.show_objects()
Expand All @@ -580,11 +590,14 @@ def open_location(self, robot):
:param robot: Robot instance to execute action.
:type robot: :class:`pyrobosim.core.robot.Robot`
:return: True if opening the location succeeds, else False.
:rtype: bool
:return: An object describing the execution result.
:rtype: :class:`pyrobosim.planning.actions.ExecutionResult`
"""
if robot is None:
return False
return ExecutionResult(
status=ExecutionStatus.PRECONDITION_FAILURE,
message="Robot is not specified. Cannot open location.",
)

return robot.open_location()

Expand All @@ -594,10 +607,13 @@ def close_location(self, robot):
:param robot: Robot instance to execute action.
:type robot: :class:`pyrobosim.core.robot.Robot`
:return: True if closing the location succeeds, else False.
:rtype: bool
:return: An object describing the execution result.
:rtype: :class:`pyrobosim.planning.actions.ExecutionResult`
"""
if robot is None:
return False
return ExecutionResult(
status=ExecutionStatus.PRECONDITION_FAILURE,
message="Robot is not specified. Cannot close location.",
)

return robot.close_location()

0 comments on commit 2b6aa50

Please sign in to comment.