コード例 #1
0
def execute_plan_command(plan, kitchen_params, gripperInitPos, cupInitPos,
                         cupSize, kettleInitPos, kettleSize, **kwargs):
    kitchen = Kitchen2D(planning=False, **kitchen_params)
    kitchen.enable_gui()
    gripper = Gripper(kitchen,
                      init_pos=gripperInitPos[:2],
                      init_angle=gripperInitPos[2])
    cup = ks.make_cup(kitchen, cupInitPos[:2], cupInitPos[2], *cupSize)
    kettle = ks.make_cup(kitchen, kettleInitPos[:2], kettleInitPos[2],
                         *kettleSize)

    pause = False

    def execute_command(command):
        for traj in command.trajectories:
            print traj
            if pause:
                raw_input('Execute?')
            if isinstance(traj, FreeTrajectory):
                if gripper.attached:
                    gripper.open()
                    gripper.release()
            else:
                if not gripper.attached:
                    gripper.close()
                    gripper.attach(cup)
            gripper.apply_control(traj.path, maxspeed=2.5)

    raw_input('Begin?')
    for i, (action, args) in enumerate(plan):
        print i, action, args
        if action.name == 'fill':
            pass
        elif action.name == 'place':
            execute_command(args[-1].reverse())
        elif action.name == 'pour-gp':
            kp, p2 = args[-2:]
            rel_pose = np.array(p2) - np.array(kp)
            poured, score = gripper.pour(kettle, rel_pose[:2], rel_pose[2],
                                         0.45, 200)
        else:
            execute_command(args[-1])
コード例 #2
0
def main():
    kitchen = Kitchen2D(**SETTING)
    expid_pour, expid_scoop = 0, 0

    # Try setting is_adaptive to be False. It will use the adaptive sampler that samples uniformly from
    # the feasible precondition. If is_adaptive is False, it uses the diverse sampler. If flag_lk is False,
    # and is_adaptive is False, it uses the diverse sampler with a fixed kernel. If flag_lk is True,
    # and is uniform is Ture, it uses the diverse sampler with the kernel parameters learned from plan feedbacks.
    gp_pour, c_pour = helper.process_gp_sample(expid_pour,
                                               exp='pour',
                                               is_adaptive=False,
                                               flag_lk=False)
    pour_to_w, pour_to_h, pour_from_w, pour_from_h = c_pour

    gp_scoop, c_scoop = helper.process_gp_sample(expid_scoop,
                                                 exp='scoop',
                                                 is_adaptive=True,
                                                 flag_lk=False)
    scoop_w, scoop_h = c_scoop
    holder_d = 0.5

    # Create objects
    gripper = Gripper(kitchen, (0, 8), 0)
    cup1 = ks.make_cup(kitchen, (10, 0), 0, pour_from_w, pour_from_h, holder_d)
    cup2 = ks.make_cup(kitchen, (-25, 0), 0, pour_to_w, pour_to_h, holder_d)
    block = ks.make_block(kitchen, (-9, 0), 0, 4, 4)
    large_cup = ks.make_cup(kitchen, (23, 0), 0, scoop_w, scoop_h, holder_d)

    # Move
    query_gui('MOVE', kitchen, dontask=True)
    gripper.find_path((-5., 10), 0, maxspeed=0.5)

    # Push
    query_gui('PUSH', kitchen, dontask=True)
    gripper.push(block, (1., 0.), -6, 0.5)

    # Pick
    query_gui('GRASP', kitchen, dontask=True)
    # Sample from the super level set of the GP learned for pour
    grasp, rel_x, rel_y, dangle, _, _, _, _ = gp_pour.sample(c_pour)
    dangle *= np.sign(rel_x)

    gripper.find_path((15, 10), 0)
    gripper.grasp(cup1, grasp)

    # Get water
    query_gui('GET-WATER', kitchen, dontask=True)
    gripper.get_liquid_from_faucet(5)

    # Pour
    query_gui('POUR', kitchen, dontask=True)
    print(gripper.pour(cup2, (rel_x, rel_y), dangle))

    # Place
    query_gui('PLACE', kitchen, dontask=True)
    gripper.place((10, 0), 0)

    # Scoop
    kitchen.gen_liquid_in_cup(large_cup, 1000, 'sugar')
    kitchen.gen_liquid_in_cup(cup1, 200)
    spoon = ks.make_spoon(kitchen, (23, 10), 0, 0.2, 3, 1.)

    query_gui('SCOOP', kitchen, dontask=True)
    rel_x1, rel_y1, rel_x2, rel_y2, rel_x3, rel_y3, grasp, _, _ = gp_scoop.sample(
        c_scoop)
    rel_pos1 = (rel_x1, rel_y1)
    rel_pos2 = (rel_x2, rel_y2)
    rel_pos3 = (rel_x3, rel_y3)
    gripper.set_grasped(spoon, grasp, (23, 10), 0)
    print(gripper.scoop(large_cup, rel_pos1, rel_pos2, rel_pos3))

    # Dump
    query_gui('DUMP', kitchen, dontask=True)
    gripper.dump(cup1, 0.9)

    # Place
    query_gui('PLACE', kitchen, dontask=True)
    gripper.place((26, 10.), 0)

    # Stir
    query_gui('STIR', kitchen, dontask=True)
    stirrer = ks.make_stirrer(kitchen, (0, 3.5), 0., 0.2, 5., 0.5)
    gripper.set_grasped(stirrer, 0.8, (10, 10), 0)
    gripper.stir(cup1, (0, 0.0), (1, 0.0))
    gripper.find_path(gripper.position + [0, 5], 0)