Example #1
0
def main(args):
    NOISE = 0.00005

    # get a bunch of random blocks
    blocks = get_adversarial_blocks(num_blocks=args.num_blocks)

    if args.agent == 'teleport':
        agent = TeleportAgent(blocks, NOISE)
    elif args.agent == 'panda':
        agent = PandaAgent(blocks, NOISE, use_platform=True, teleport=False)
    else:
        raise NotImplementedError()

    # construct a world containing those blocks
    beliefs = [
        ParticleBelief(block, N=200, plot=True, vis_sim=False, noise=NOISE)
        for block in blocks
    ]
    agent._add_text('Ready?')
    input('Start?')

    # Gain information about the CoM of each block.
    for b_ix, (block, belief) in enumerate(zip(blocks, beliefs)):
        print('Running filter for', block.name)
        for interaction_num in range(5):
            print("Interaction number: ", interaction_num)
            agent._add_text('Planning action.')
            action = plan_action(belief,
                                 exp_type='reduce_var',
                                 action_type='place')
            observation = agent.simulate_action(action, b_ix, T=50)
            agent._add_text('Updating particle belief.')
            belief.update(observation)
            block.com_filter = belief.particles

        print(belief.estimated_coms[-1], block.com)

    # Find the tallest tower
    print('Finding tallest tower.')
    # agent._add_text('Planning tallest tower')
    tp = TowerPlanner(plan_mode='expectation')
    tallest_tower = tp.plan(blocks)

    # and execute the resulting plan.
    agent.simulate_tower(tallest_tower,
                         vis=True,
                         T=2500,
                         save_tower=args.save_tower)
Example #2
0
def test_tower_simulation(blocks):
    agent = PandaAgent(blocks, NOISE)

    for b_ix, block in enumerate(blocks):
        belief = ParticleBelief(block,
                                N=200,
                                plot=False,
                                vis_sim=False,
                                noise=NOISE)
        block.com_filter = belief.particles

    tp = TowerPlanner()
    tallest_tower = tp.plan(blocks, num_samples=10)

    # and visualize the result
    agent.simulate_tower(tallest_tower, vis=True, T=2500)