Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-viewer', action='store_true', help='enable the viewer while planning')
    args = parser.parse_args()
    print(args)

    connect(use_gui=True)
    with LockRenderer():
        draw_pose(unit_pose(), length=1)
        floor = create_floor()
        with HideOutput():
            robot = load_pybullet(get_model_path(ROOMBA_URDF), fixed_base=True, scale=2.0)
            for link in get_all_links(robot):
                set_color(robot, link=link, color=ORANGE)
            robot_z = stable_z(robot, floor)
            set_point(robot, Point(z=robot_z))
        #set_base_conf(robot, rover_confs[i])

        data_path = add_data_path()
        shelf, = load_model(os.path.join(data_path, KIVA_SHELF_SDF), fixed_base=True) # TODO: returns a tuple
        dump_body(shelf)
        #draw_aabb(get_aabb(shelf))

    wait_for_user()
    disconnect()
Exemplo n.º 2
0
def load_world():
    # TODO: store internal world info here to be reloaded
    set_default_camera()
    draw_global_system()
    with HideOutput():
        #add_data_path()
        robot = load_model(DRAKE_IIWA_URDF, fixed_base=True) # DRAKE_IIWA_URDF | KUKA_IIWA_URDF
        floor = load_model('models/short_floor.urdf')
        sink = load_model(SINK_URDF, pose=Pose(Point(x=-0.5)))
        stove = load_model(STOVE_URDF, pose=Pose(Point(x=+0.5)))
        celery = load_model(BLOCK_URDF, fixed_base=False)
        radish = load_model(SMALL_BLOCK_URDF, fixed_base=False)
        #cup = load_model('models/dinnerware/cup/cup_small.urdf',
        # Pose(Point(x=+0.5, y=+0.5, z=0.5)), fixed_base=False)

    draw_pose(Pose(), parent=robot, parent_link=get_tool_link(robot)) # TODO: not working
    # dump_body(robot)
    # wait_for_user()

    body_names = {
        sink: 'sink',
        stove: 'stove',
        celery: 'celery',
        radish: 'radish',
    }
    movable_bodies = [celery, radish]

    set_pose(celery, Pose(Point(y=0.5, z=stable_z(celery, floor))))
    set_pose(radish, Pose(Point(y=-0.5, z=stable_z(radish, floor))))

    return robot, body_names, movable_bodies
Exemplo n.º 3
0
def test_grasps(robot, node_points, elements):
    element = elements[-1]
    [element_body] = create_elements(node_points, [element])

    phi = 0
    link = link_from_name(robot, TOOL_NAME)
    link_pose = get_link_pose(robot, link)
    draw_pose(link_pose)  #, parent=robot, parent_link=link)
    wait_for_interrupt()

    n1, n2 = element
    p1 = node_points[n1]
    p2 = node_points[n2]
    length = np.linalg.norm(p2 - p1)
    # Bottom of cylinder is p1, top is p2
    print(element, p1, p2)
    for phi in np.linspace(0, np.pi, 10, endpoint=True):
        theta = np.pi / 4
        for t in np.linspace(-length / 2, length / 2, 10):
            translation = Pose(
                point=Point(z=-t)
            )  # Want to be moving backwards because +z is out end effector
            direction = Pose(euler=Euler(roll=np.pi / 2 + theta, pitch=phi))
            angle = Pose(euler=Euler(yaw=1.2))
            grasp_pose = multiply(angle, direction, translation)
            element_pose = multiply(link_pose, grasp_pose)
            set_pose(element_body, element_pose)
            wait_for_interrupt()
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()  # Automatically includes help
    parser.add_argument('-viewer', action='store_true', help='enable viewer.')
    args = parser.parse_args()

    connect(use_gui=True)
    #ycb_path = os.path.join(DRAKE_PATH, DRAKE_YCB)
    #ycb_path = os.path.join(YCB_PATH, YCB_TEMPLATE.format('003_cracker_box'))
    #print(ycb_path)
    #load_pybullet(ycb_path)

    with LockRenderer():
        draw_pose(unit_pose(), length=1, width=1)
        floor = create_floor()
        set_point(floor, Point(z=-EPSILON))
        table = create_table(width=TABLE_WIDTH, length=TABLE_WIDTH/2, height=TABLE_WIDTH/2, top_color=TAN, cylinder=False)
        #set_euler(table, Euler(yaw=np.pi/2))
        with HideOutput(False):
            # data_path = add_data_path()
            # robot_path = os.path.join(data_path, WSG_GRIPPER)
            robot_path = get_model_path(WSG_50_URDF)  # WSG_50_URDF | PANDA_HAND_URDF
            #robot_path = get_file_path(__file__, 'mit_arch_suction_gripper/mit_arch_suction_gripper.urdf')
            robot = load_pybullet(robot_path, fixed_base=True)
            #dump_body(robot)
            #robot = create_cylinder(radius=0.5*BLOCK_SIDE, height=4*BLOCK_SIDE) # vacuum gripper

        block1 = create_box(w=BLOCK_SIDE, l=BLOCK_SIDE, h=BLOCK_SIDE, color=RED)
        block_z = stable_z(block1, table)
        set_point(block1, Point(z=block_z))

        block2 = create_box(w=BLOCK_SIDE, l=BLOCK_SIDE, h=BLOCK_SIDE, color=GREEN)
        set_point(block2, Point(x=+0.25, z=block_z))

        block3 = create_box(w=BLOCK_SIDE, l=BLOCK_SIDE, h=BLOCK_SIDE, color=BLUE)
        set_point(block3, Point(x=-0.15, z=block_z))

        blocks = [block1, block2, block3]

        add_line(Point(x=-TABLE_WIDTH/2, z=block_z - BLOCK_SIDE/2 + EPSILON),
                 Point(x=+TABLE_WIDTH/2, z=block_z - BLOCK_SIDE/2 + EPSILON), color=RED)
        set_camera_pose(camera_point=Point(y=-1, z=block_z+1), target_point=Point(z=block_z))

    wait_for_user()
    block_pose = get_pose(block1)
    open_gripper(robot)
    tool_link = link_from_name(robot, 'tool_link')
    base_from_tool = get_relative_pose(robot, tool_link)
    #draw_pose(unit_pose(), parent=robot, parent_link=tool_link)

    y_grasp, x_grasp = get_top_grasps(block1, tool_pose=unit_pose(), grasp_length=0.03, under=False)
    grasp = y_grasp # fingers won't collide
    gripper_pose = multiply(block_pose, invert(grasp))
    set_pose(robot, multiply(gripper_pose, invert(base_from_tool)))
    wait_for_user('Finish?')
    disconnect()
Exemplo n.º 5
0
    def gen(robot, body):
        link = link_from_name(robot, BASE_LINK)
        with BodySaver(robot):
            set_base_conf(robot, np.zeros(3))
            robot_pose = get_link_pose(robot, link)
            robot_aabb = get_turtle_aabb(robot)
            # _, upper = robot_aabb
            # radius = upper[0]
            extent = get_aabb_extent(robot_aabb)
            radius = max(extent[:2]) / 2.
            #draw_aabb(robot_aabb)

        center, (diameter, height) = approximate_as_cylinder(body)
        distance = radius + diameter / 2. + epsilon
        _, _, z = get_point(body)  # Assuming already placed stably

        for [scale] in unit_generator(d=1, use_halton=use_halton):
            #theta = PI # 0 | PI
            theta = random.uniform(*theta_interval)
            position = np.append(distance * unit_from_theta(theta=theta),
                                 [z])  # TODO: halton

            yaw = scale * 2 * PI - PI
            quat = quat_from_euler(Euler(yaw=yaw))
            body_pose = (position, quat)
            robot_from_body = multiply(invert(robot_pose), body_pose)
            grasp = Pose(body, robot_from_body)  # TODO: grasp instead of pose
            if draw:
                world_pose = multiply(get_link_pose(robot, link), grasp.value)
                set_pose(body, world_pose)
                handles = draw_pose(get_pose(body), length=1)
                wait_for_user()
                remove_handles(handles)
                #continue
            yield (grasp, )
Exemplo n.º 6
0
def load_pick_and_place(extrusion_name, scale=MILLIMETER, max_bricks=6):
    assert extrusion_name == 'choreo_brick_demo'
    root_directory = os.path.dirname(os.path.abspath(__file__))
    bricks_directory = os.path.join(root_directory, PICKNPLACE_DIRECTORY,
                                    'bricks')
    print('Name: {}'.format(extrusion_name))
    with open(
            os.path.join(bricks_directory,
                         PICKNPLACE_FILENAMES[extrusion_name]), 'r') as f:
        json_data = json.loads(f.read())

    kuka_urdf = '../models/framefab_kr6_r900_support/urdf/kr6_r900_mit_suction_gripper.urdf'
    obj_directory = os.path.join(bricks_directory, 'meshes', 'collision')
    with HideOutput():
        #world = load_pybullet(os.path.join(bricks_directory, 'urdf', 'brick_demo.urdf'))
        robot = load_pybullet(os.path.join(root_directory, kuka_urdf),
                              fixed_base=True)
    #set_point(robot, (0.14, 0, 0))
    #dump_body(robot)

    pick_base_point = parse_point(json_data['pick_base_center_point'])
    draw_pose((pick_base_point, unit_quat()))
    place_base_point = parse_point(json_data['place_base_center_point'])
    draw_pose((place_base_point, unit_quat()))

    # workspace_geo_place_support_object_11 = pick_left_over_bricks_11
    obstacle_from_name = {}
    for filename in json_data['pick_support_surface_file_names']:
        obstacle_from_name[strip_extension(filename)] = \
            create_obj(os.path.join(obj_directory, filename), scale=scale, color=(0.5, 0.5, 0.5, 1))
    for filename in json_data['place_support_surface_file_names']:
        obstacle_from_name[strip_extension(filename)] = \
            create_obj(os.path.join(obj_directory, filename), scale=scale, color=(1., 0., 0., 1))

    brick_from_index = {}
    for json_element in json_data['sequenced_elements']:
        index = json_element['order_id']
        pick_body = create_obj(os.path.join(
            obj_directory, json_element['pick_element_geometry_file_name']),
                               scale=scale,
                               color=(0, 0, 1, 1))
        add_body_name(pick_body, index)
        #place_body = create_obj(os.path.join(obj_directory, json_element['place_element_geometry_file_name']),
        #                        scale=scale, color=(0, 1, 0, 1))
        #add_body_name(place_body, name)
        world_from_obj_pick = get_pose(pick_body)

        # [u'pick_grasp_plane', u'pick_grasp_retreat_plane', u'place_grasp_retreat_plane',
        #  u'pick_grasp_approach_plane', u'place_grasp_approach_plane', u'place_grasp_plane']
        ee_grasp_poses = [{
            name: pose_from_tform(parse_transform(approach))
            for name, approach in json_grasp.items()
        } for json_grasp in json_element['grasps']]

        # pick_grasp_plane is at the top of the object with z facing downwards
        grasp_index = 0
        world_from_ee_pick = ee_grasp_poses[grasp_index]['pick_grasp_plane']
        world_from_ee_place = ee_grasp_poses[grasp_index]['place_grasp_plane']
        #draw_pose(world_from_ee_pick, length=0.04)
        #draw_pose(world_from_ee_place, length=0.04)

        ee_from_obj = multiply(invert(world_from_ee_pick),
                               world_from_obj_pick)  # Using pick frame
        world_from_obj_place = multiply(world_from_ee_place, ee_from_obj)
        #set_pose(pick_body, world_from_obj_place)

        grasps = [
            Grasp(
                index, num, *[
                    multiply(invert(world_from_ee_pick[name]),
                             world_from_obj_pick) for name in GRASP_NAMES
                ]) for num, world_from_ee_pick in enumerate(ee_grasp_poses)
        ]
        brick_from_index[index] = Brick(
            index=index,
            body=pick_body,
            initial_pose=WorldPose(index, world_from_obj_pick),
            goal_pose=WorldPose(index, world_from_obj_place),
            grasps=grasps,
            goal_supports=json_element.get('place_contact_ngh_ids', []))
        # pick_contact_ngh_ids are movable element contact partial orders
        # pick_support_surface_file_names are fixed element contact partial orders

    return robot, brick_from_index, obstacle_from_name
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser()  # Automatically includes help
    parser.add_argument('-viewer', action='store_true', help='enable viewer.')
    args = parser.parse_args()

    connect(use_gui=True)

    with LockRenderer():
        draw_pose(unit_pose(), length=1, width=1)
        floor = create_floor()
        set_point(floor, Point(z=-EPSILON))

        table1 = create_table(width=TABLE_WIDTH,
                              length=TABLE_WIDTH / 2,
                              height=TABLE_WIDTH / 2,
                              top_color=TAN,
                              cylinder=False)
        set_point(table1, Point(y=+0.5))

        table2 = create_table(width=TABLE_WIDTH,
                              length=TABLE_WIDTH / 2,
                              height=TABLE_WIDTH / 2,
                              top_color=TAN,
                              cylinder=False)
        set_point(table2, Point(y=-0.5))

        tables = [table1, table2]

        #set_euler(table1, Euler(yaw=np.pi/2))
        with HideOutput():
            # data_path = add_data_path()
            # robot_path = os.path.join(data_path, WSG_GRIPPER)
            robot_path = get_model_path(
                WSG_50_URDF)  # WSG_50_URDF | PANDA_HAND_URDF
            robot = load_pybullet(robot_path, fixed_base=True)
            #dump_body(robot)

        block1 = create_box(w=BLOCK_SIDE,
                            l=BLOCK_SIDE,
                            h=BLOCK_SIDE,
                            color=RED)
        block_z = stable_z(block1, table1)
        set_point(block1, Point(y=-0.5, z=block_z))

        block2 = create_box(w=BLOCK_SIDE,
                            l=BLOCK_SIDE,
                            h=BLOCK_SIDE,
                            color=GREEN)
        set_point(block2, Point(x=-0.25, y=-0.5, z=block_z))

        block3 = create_box(w=BLOCK_SIDE,
                            l=BLOCK_SIDE,
                            h=BLOCK_SIDE,
                            color=BLUE)
        set_point(block3, Point(x=-0.15, y=+0.5, z=block_z))

        blocks = [block1, block2, block3]

        set_camera_pose(camera_point=Point(x=-1, z=block_z + 1),
                        target_point=Point(z=block_z))

    block_pose = get_pose(block1)
    open_gripper(robot)
    tool_link = link_from_name(robot, 'tool_link')
    base_from_tool = get_relative_pose(robot, tool_link)
    #draw_pose(unit_pose(), parent=robot, parent_link=tool_link)
    grasps = get_side_grasps(block1,
                             tool_pose=Pose(euler=Euler(yaw=np.pi / 2)),
                             top_offset=0.02,
                             grasp_length=0.03,
                             under=False)[1:2]
    for grasp in grasps:
        gripper_pose = multiply(block_pose, invert(grasp))
        set_pose(robot, multiply(gripper_pose, invert(base_from_tool)))
        wait_for_user()

    wait_for_user('Finish?')
    disconnect()