Exemplo n.º 1
0
def test_obj_adder_single():

    ground_plane = GroundPlaneHook()

    duck = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, 1]),
    )

    sim = BulletSimulator(
        mode=CONNECT_MODE,
        max_time=2.,
        hooks=[
            ground_plane,
            duck,
        ],
    )

    for _ in range(2):
        sim.reset()
        while sim.running:
            sim.step()
    sim.close()
    assert len(sim.objects) == 1
Exemplo n.º 2
0
def test_r2d2():

    ground_plane = GroundPlaneHook()
    r2d2 = R2D2CreatorHook()

    sim = BulletSimulator(
        mode=CONNECT_MODE,
        max_time=2,
        hooks=[
            ground_plane,
            r2d2,
        ],
    )

    sim.reset()
    while not sim.terminated:
        output = sim.step()
Exemplo n.º 3
0
def test_obj_adder_multiple_in_sequence():

    ground_plane = GroundPlaneHook()

    height = 3.

    duck_1 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=0.,
    )

    duck_2 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=.5,
    )

    duck_3 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=1.,
    )

    sim = BulletSimulator(
        mode=CONNECT_MODE,
        max_time=3.,
        hooks=[
            ground_plane,
            duck_1,
            duck_2,
            duck_3,
        ],
    )

    out = sim.reset()
    assert len(sim.objects) == 1
    for _ in range(2):
        while sim.running:
            out = sim.step()
    sim.close()
    assert len(sim.objects) == 3
Exemplo n.º 4
0
def test_obj_adder_multiple_simultaneous():

    ground_plane = GroundPlaneHook()

    time_to_create = 1.

    duck_1 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([-1, -1, 2]),
        time_to_create=time_to_create,
    )

    duck_2 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, 4]),
        time_to_create=time_to_create,
    )

    duck_3 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([1, 1, 6]),
        time_to_create=time_to_create,
    )

    sim = BulletSimulator(
        mode=CONNECT_MODE,
        max_time=3.,
        hooks=[
            ground_plane,
            duck_1,
            duck_2,
            duck_3,
        ],
    )

    for _ in range(2):
        out = sim.reset()
        while sim.running:
            out = sim.step()
    sim.close()
    assert len(sim.objects) == 3
Exemplo n.º 5
0
def test_random_static_cameras_one_shot_at_2s():
    '''
    Identical to above, but take only one pictures at t=2s
    '''

    ground_plane = GroundPlaneHook()

    height = 3.

    duck_1 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=0.,
    )

    duck_2 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=1.,
    )

    duck_3 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=2.,
    )

    camera_1 = RandomStaticCameraHook(
        K=[
            1075.65091572, 0.0, 210.06888344, 0.0, 1073.90347929, 174.72159802,
            0.0, 0.0, 1.0
        ],
        img_shape=(400, 400),
        # position = np.array([10., 10., 7.]),
        # lookat = np.array([0., 0., 0.]),
        position=[(-10., 10.), (-10., 10.), 7],
        lookat=[(-0.2, 0.2), (-0.2, 0.2), (0, 0.1)],
        up='up',
        start=2.,
        light_src=[(-1, 1), (-1, 1), 1],
    )

    camera_2 = RandomStaticCameraHook(
        K=[
            1075.65091572, 0.0, 210.06888344, 0.0, 1073.90347929, 174.72159802,
            0.0, 0.0, 1.0
        ],
        img_shape=(400, 400),
        position=[(-10., 10.), (-10., 10.), 6],
        lookat=[(-0.2, 0.2), (-0.2, 0.2), (0, 0.1)],
        up='up',
        start=2.,
    )

    sim = BulletSimulator(
        mode=CONNECT_MODE,
        max_time=5.,
        hooks=[
            ground_plane,
            duck_1,
            duck_2,
            duck_3,
            camera_1,
            camera_2,
        ],
    )

    images_in_all_rollouts = []
    for _ in range(2):

        out = sim.reset()

        images = maybe_collect_images(out)
        assert len(images) == 0

        # num_images = 0
        images_in_rollout = []

        while sim.running:
            out = sim.step()

            images = maybe_collect_images(out)
            if len(images) > 0:
                images_in_rollout.extend(images)
        images_in_all_rollouts.append(images_in_rollout)

    sim.close()

    # images across different rollout should be different.
    assert not np.allclose(images_in_all_rollouts[0][0],
                           images_in_all_rollouts[1][0])
    assert not np.allclose(images_in_all_rollouts[0][1],
                           images_in_all_rollouts[1][1])
Exemplo n.º 6
0
def test_static_opengl_cameras():
    '''
    Based on test_obj_adder.test_obj_adder_multiple_in_sequence().

    Take the first picture upon reset (start=0.), 
    and then take pictures every 0.1 seconds until time is up.
    '''

    # copy-and-paste
    ground_plane = GroundPlaneHook()

    height = 3.

    duck_1 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=0.,
    )

    duck_2 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=1.,
    )

    duck_3 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=2.,
    )

    camera_1 = StaticOGLCameraHook(
        K=[
            1075.65091572, 0.0, 210.06888344, 0.0, 1073.90347929, 174.72159802,
            0.0, 0.0, 1.0
        ],
        img_shape=(400, 400),
        position=np.array([10., 10., 7.]),
        lookat=np.array([0., 0., 0.]),
        up='up',
        start=0.,
        # interval = .5,
        interval=.1,
    )

    camera_2 = StaticOGLCameraHook(
        K=[
            1075.65091572, 0.0, 210.06888344, 0.0, 1073.90347929, 174.72159802,
            0.0, 0.0, 1.0
        ],
        img_shape=(400, 400),
        position=np.array([-10., -10., 6.]),
        lookat=np.array([0., 0., 0.]),
        up='up',
        start=0.,
        # interval = .5,
        interval=.1,
    )

    sim = BulletSimulator(
        mode=CONNECT_MODE,
        max_time=5.,
        hooks=[
            ground_plane,
            duck_1,
            duck_2,
            duck_3,
            camera_1,
            camera_2,
        ],
    )

    for _ in range(2):
        out = sim.reset()
        num_images = 0

        images = maybe_collect_images(out)
        for I in images:
            assert I.shape == (400, 400, 4)
        num_images += len(images)

        while sim.running:
            out = sim.step()

            images = maybe_collect_images(out)
            for I in images:
                assert I.shape == (400, 400, 4)
            num_images += len(images)

        assert num_images == 100

    sim.close()
Exemplo n.º 7
0
def test_static_opengl_cameras_one_final_shot():
    '''
    Identical to above, but take only one pictures before simulation terminates (start=np.inf).
    '''

    ground_plane = GroundPlaneHook()

    height = 3.

    duck_1 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=0.,
    )

    duck_2 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=1.,
    )

    duck_3 = BasicOBJHook(
        category_name='rubber_duck',
        path_to_obj=DUCK_OBJ_PATH,
        position=np.array([0, 0, height]),
        time_to_create=2.,
    )

    camera_1 = StaticOGLCameraHook(
        K=[
            1075.65091572, 0.0, 210.06888344, 0.0, 1073.90347929, 174.72159802,
            0.0, 0.0, 1.0
        ],
        img_shape=(400, 400),
        position=np.array([10., 10., 7.]),
        lookat=np.array([0., 0., 0.]),
        up='up',
        start=np.inf,
    )

    camera_2 = StaticOGLCameraHook(
        K=[
            1075.65091572, 0.0, 210.06888344, 0.0, 1073.90347929, 174.72159802,
            0.0, 0.0, 1.0
        ],
        img_shape=(400, 400),
        position=np.array([-10., -10., 6.]),
        lookat=np.array([0., 0., 0.]),
        up='up',
        start=np.inf,
    )

    sim = BulletSimulator(
        mode=CONNECT_MODE,
        max_time=5.,
        hooks=[
            ground_plane,
            duck_1,
            duck_2,
            duck_3,
            camera_1,
            camera_2,
        ],
    )

    for _ in range(2):
        out = sim.reset()
        num_images = 0

        images = maybe_collect_images(out)
        assert len(images) == 0

        while sim.running:
            out = sim.step()

            images = maybe_collect_images(out)
            if len(images) > 0:
                assert len(images) == 2
                assert sim.terminated
                for I in images:
                    assert I.shape == (400, 400, 4)

    sim.close()