Beispiel #1
0
    def fn(body, pose, grasp):
        obstacles = [body] + fixed
        gripper_pose = end_effector_from_body(pose.pose, grasp.grasp_pose)
        approach_pose = approach_from_grasp(grasp.approach_pose, gripper_pose)
        draw_pose(gripper_pose, length=0.04)
        draw_pose(approach_pose, length=0.04)

        for _ in range(num_attempts):
            if USE_IKFAST:
                q_approach = sample_tool_ik(robot, approach_pose)
                if q_approach is not None:
                    set_joint_positions(robot, movable_joints, q_approach)
            else:
                set_joint_positions(robot, movable_joints, sample_fn()) # Random seed
                q_approach = inverse_kinematics(robot, grasp.link, approach_pose)
            if (q_approach is None) or any(pairwise_collision(robot, b) for b in obstacles):
                continue
            conf = BodyConf(robot, joints=movable_joints)

            if USE_IKFAST:
                q_grasp = sample_tool_ik(robot, gripper_pose, closest_only=True)
                if q_grasp is not None:
                    set_joint_positions(robot, movable_joints, q_grasp)
            else:
                q_grasp = inverse_kinematics(robot, grasp.link, gripper_pose)
            if (q_grasp is None) or any(pairwise_collision(robot, b) for b in obstacles):
                continue

            if teleport:
                path = [q_approach, q_grasp]
            else:
                conf.assign()
                #direction, _ = grasp.approach_pose
                #path = workspace_trajectory(robot, grasp.link, point_from_pose(approach_pose), -direction,
                #                                   quat_from_pose(approach_pose))
                path = plan_direct_joint_motion(robot, conf.joints, q_grasp, obstacles=obstacles, \
                                                self_collisions=self_collisions)
                if path is None:
                    if DEBUG_FAILURE: user_input('Approach motion failed')
                    continue
            command = Command([BodyPath(robot, path, joints=movable_joints),
                               Attach(body, robot, grasp.link),
                               BodyPath(robot, path[::-1], joints=movable_joints, attachments=[grasp])])
            return (conf, command)
            # TODO: holding collisions
        return None
Beispiel #2
0
    def fn(body, pose, grasp):
        obstacles = [body] + fixed
        gripper_pose = end_effector_from_body(pose.pose, grasp.grasp_pose)
        approach_pose = approach_from_grasp(grasp.approach_pose, gripper_pose)

        draw_pose(get_tool_pose(robot, ARM), length=0.04)
        draw_pose(approach_pose, length=0.04)
        draw_pose(gripper_pose, length=0.04)
        # print(movable_joints)
        # print(torso_arm)
        # wait_for_interrupt()

        # TODO: gantry_x_joint
        # TODO: proper inverse reachability
        base_link = link_from_name(robot, IK_BASE_FRAMES[ARM])
        base_pose = get_link_pose(robot, base_link)
        body_point_in_base = point_from_pose(multiply(invert(base_pose), pose.pose))
        y_joint = joint_from_name(robot, '{}_gantry_y_joint'.format(prefix_from_arm(ARM)))
        initial_y = get_joint_position(robot, y_joint)
        ik_y = initial_y + SIGN_FROM_ARM[ARM]*body_point_in_base[1]
        set_joint_position(robot, y_joint, ik_y)

        for _ in range(num_attempts):
            if USE_IKFAST:
                q_approach = sample_tool_ik(robot, ARM, approach_pose)
                if q_approach is not None:
                    set_joint_positions(robot, torso_arm, q_approach)
            else:
                set_joint_positions(robot, torso_arm, sample_fn()) # Random seed
                q_approach = inverse_kinematics(robot, grasp.link, approach_pose)
            if (q_approach is None) or any(pairwise_collision(robot, b) for b in obstacles):
                print('- ik for approaching fails!')
                continue
            conf = BodyConf(robot, joints=arm_joints)

            if USE_IKFAST:
                q_grasp = sample_tool_ik(robot, ARM, gripper_pose, closest_only=True)
                if q_grasp is not None:
                    set_joint_positions(robot, torso_arm, q_grasp)
            else:
                conf.assign()
                q_grasp = inverse_kinematics(robot, grasp.link, gripper_pose)
            if (q_grasp is None) or any(pairwise_collision(robot, b) for b in obstacles):
                print('- ik for grasp fails!')
                continue

            if teleport:
                path = [q_approach, q_grasp]
            else:
                conf.assign()
                #direction, _ = grasp.approach_pose
                #path = workspace_trajectory(robot, grasp.link, point_from_pose(approach_pose), -direction,
                #                                   quat_from_pose(approach_pose))
                path = plan_direct_joint_motion(robot, torso_arm, q_grasp, obstacles=obstacles,
                                                self_collisions=self_collisions)
                if path is None:
                    if DEBUG_FAILURE:
                        print('Approach motion failed')
                    continue
            command = Command([BodyPath(robot, path, joints=torso_arm),
                               Attach(body, robot, grasp.link),
                               BodyPath(robot, path[::-1], joints=torso_arm, attachments=[grasp])])
            return (conf, command)
            # TODO: holding collisions
        return None