31 from moveit_msgs.msg
import MoveItErrorCodes
32 from moveit_msgs.msg
import PickupAction, PickupGoal, PlaceAction, PlaceGoal
50 rospy.loginfo(
"Connecting to pickup action...")
53 self._pick_action.wait_for_server()
55 rospy.loginfo(
"...connected")
56 rospy.loginfo(
"Connecting to place action...")
59 self._place_action.wait_for_server()
61 rospy.loginfo(
"...connected")
77 def pickup(self, name, grasps, wait=True, **kwargs):
79 supported_args = (
"allow_gripper_support_collision",
80 "allowed_touch_objects",
83 "planning_scene_diff",
86 for arg
in kwargs.keys():
87 if not arg
in supported_args:
88 rospy.loginfo(
"pickup: unsupported argument: %s", arg)
103 g.possible_grasps = grasps
107 g.support_surface_name = kwargs[
"support_name"]
109 g.support_surface_name =
"" 113 g.allow_gripper_support_collision = kwargs[
"allow_gripper_support_collision"]
115 g.allow_gripper_support_collision =
True 119 g.attached_object_touch_links = kwargs[
"attached_object_touch_links"]
121 g.attached_object_touch_links = list()
129 g.planner_id = kwargs[
"planner_id"]
136 g.allowed_touch_objects = kwargs[
"allowed_touch_objects"]
138 g.allowed_touch_objects = list()
142 g.allowed_planning_time = kwargs[
"planning_time"]
148 g.planning_options.planning_scene_diff = kwargs[
"planning_scene_diff"]
150 g.planning_options.planning_scene_diff.is_diff =
True 151 g.planning_options.planning_scene_diff.robot_state.is_diff =
True 152 g.planning_options.plan_only = self.
_plan_only 154 self._pick_action.send_goal(g)
156 self._pick_action.wait_for_result()
157 return self._pick_action.get_result()
168 def place(self, name, locations, wait=True, **kwargs):
170 supported_args = (
"allow_gripper_support_collision",
171 "allowed_touch_objects",
175 "planning_scene_diff",
178 for arg
in kwargs.keys():
179 if not arg
in supported_args:
180 rospy.loginfo(
"place: unsupported argument: %s", arg)
186 g.group_name = self.
_group 189 g.attached_object_name = name
192 g.place_locations = locations
196 g.place_eef = kwargs[
"goal_is_eef"]
202 g.support_surface_name = kwargs[
"support_name"]
204 g.support_surface_name =
"" 208 g.allow_gripper_support_collision = kwargs[
"allow_gripper_support_collision"]
210 g.allow_gripper_support_collision =
True 216 g.planner_id = kwargs[
"planner_id"]
223 g.allowed_touch_objects = kwargs[
"allowed_touch_objects"]
225 g.allowed_touch_objects = list()
229 g.allowed_planning_time = kwargs[
"planning_time"]
235 g.planning_options.planning_scene_diff = kwargs[
"planning_scene_diff"]
237 g.planning_options.planning_scene_diff.is_diff =
True 238 g.planning_options.planning_scene_diff.robot_state.is_diff =
True 239 g.planning_options.plan_only = self.
_plan_only 241 self._place_action.send_goal(g)
243 self._place_action.wait_for_result()
244 return self._place_action.get_result()
252 rospy.loginfo(
"Beginning to pick.")
255 pick_result = self.
pickup(name, grasps, **kwargs)
256 if pick_result.error_code.val == MoveItErrorCodes.SUCCESS:
257 rospy.loginfo(
"Pick succeeded")
258 return [
True, pick_result]
259 elif pick_result.error_code.val == MoveItErrorCodes.PLANNING_FAILED:
260 rospy.logerr(
"Pick failed in the planning stage, try again...")
264 pick_result.error_code.val == MoveItErrorCodes.CONTROL_FAILED
or \
265 pick_result.error_code.val == MoveItErrorCodes.MOTION_PLAN_INVALIDATED_BY_ENVIRONMENT_CHANGE
or \
266 pick_result.error_code.val == MoveItErrorCodes.TIMED_OUT:
267 rospy.logerr(
"Pick failed during execution, attempting to cleanup.")
268 if name
in scene.getKnownAttachedObjects():
269 rospy.loginfo(
"Pick managed to grab object, retreat must have failed, continuing anyways")
270 return [
True, pick_result]
272 rospy.loginfo(
"Pick did not grab object, try again...")
275 rospy.logerr(
"Pick failed with error code: %d. Will retry...",
276 pick_result.error_code.val)
278 rospy.logerr(
"Pick failed, and all retries are used")
279 return [
False, pick_result]
290 rospy.loginfo(
"Beginning to place.")
293 place_result = self.
place(name, locations, **kwargs)
294 if place_result.error_code.val == MoveItErrorCodes.SUCCESS:
295 rospy.loginfo(
"Place succeeded")
296 return [
True, place_result]
297 elif place_result.error_code.val == MoveItErrorCodes.PLANNING_FAILED:
298 rospy.logerr(
"Place failed in planning stage, try again...")
302 place_result.error_code.val == MoveItErrorCodes.CONTROL_FAILED
or \
303 place_result.error_code.val == MoveItErrorCodes.MOTION_PLAN_INVALIDATED_BY_ENVIRONMENT_CHANGE
or \
304 place_result.error_code.val == MoveItErrorCodes.TIMED_OUT:
305 rospy.logerr(
"Place failed during execution, attempting to cleanup.")
306 if name
in scene.getKnownAttachedObjects():
307 rospy.loginfo(
"Place did not place object, approach must have failed, will retry...")
310 rospy.loginfo(
"Object no longer in gripper, must be placed, continuing...")
311 return [
True, place_result]
313 rospy.logerr(
"Place failed with error code: %d. Will retry...",
314 place_result.error_code.val)
316 rospy.logerr(
"Place failed, and all retries are used")
317 return [
False, place_result]
def pickup(self, name, grasps, wait=True, kwargs)
Plan and grasp something.
def place_with_retry(self, name, locations, retries=5, scene=None, kwargs)
Common usage pattern TODO document.
def pick_with_retry(self, name, grasps, retries=5, scene=None, kwargs)
Common usage pattern TODO document.
def get_place_action(self)
def place(self, name, locations, wait=True, kwargs)
Plan and grasp something.
def get_pick_action(self)
def __init__(self, group="arm", ee_group="gripper", plan_only=False, verbose=False)
Create a grasp manager, connect actions.
Simple interface to pick and place actions.