Esempio n. 1
0
def test_import_building_viewing():
    download_assets()
    download_demo_data()
    config = parse_config(os.path.join(gibson2.root_path, '../test/test.yaml'))

    s = Simulator(mode='headless')
    scene = StaticIndoorScene('Rs')
    s.import_scene(scene)
    assert s.objects == list(range(2))

    turtlebot1 = Turtlebot(config)
    turtlebot2 = Turtlebot(config)
    turtlebot3 = Turtlebot(config)

    s.import_robot(turtlebot1)
    s.import_robot(turtlebot2)
    s.import_robot(turtlebot3)

    turtlebot1.set_position([0.5, 0, 0.5])
    turtlebot2.set_position([0, 0, 0.5])
    turtlebot3.set_position([-0.5, 0, 0.5])

    for i in range(10):
        s.step()
        #turtlebot1.apply_action(np.random.randint(4))
        #turtlebot2.apply_action(np.random.randint(4))
        #turtlebot3.apply_action(np.random.randint(4))

    s.disconnect()
Esempio n. 2
0
def test_env_reset():
    download_assets()
    download_demo_data()
    config_filename = os.path.join(gibson2.root_path,
                                   '../test/test_house.yaml')
    env = iGibsonEnv(config_file=config_filename, mode='headless')

    class DummyTask(object):
        def __init__(self):
            self.reset_scene_called = False
            self.reset_agent_called = False
            self.get_task_obs_called = False

        def get_task_obs(self, env):
            self.get_task_obs_called = True

        def reset_scene(self, env):
            self.reset_scene_called = True

        def reset_agent(self, env):
            self.reset_agent_called = True

    env.task = DummyTask()
    env.reset()
    assert env.task.reset_scene_called
    assert env.task.reset_agent_called
    assert env.task.get_task_obs_called
Esempio n. 3
0
def test_vision_sensor():
    download_assets()
    download_demo_data()
    config_filename = os.path.join(gibson2.root_path,
                                   '../test/test_house.yaml')
    env = iGibsonEnv(config_file=config_filename, mode='headless')
    vision_modalities = ['rgb', 'depth', 'pc', 'normal', 'seg']
    vision_sensor = VisionSensor(env, vision_modalities)
    vision_obs = vision_sensor.get_obs(env)

    assert vision_obs['rgb'].shape == (env.image_height, env.image_width, 3)
    assert np.all(0 <= vision_obs['rgb']) and np.all(vision_obs['rgb'] <= 1.0)

    assert vision_obs['depth'].shape == (env.image_height, env.image_width, 1)
    assert np.all(0 <= vision_obs['depth']) and np.all(
        vision_obs['depth'] <= 1.0)

    assert vision_obs['pc'].shape == (env.image_height, env.image_width, 3)

    assert vision_obs['normal'].shape == (env.image_height, env.image_width, 3)
    normal_norm = np.linalg.norm(vision_obs['normal'] * 2 - 1, axis=2)
    assert np.sum(np.abs(normal_norm - 1) > 0.1) / \
        (env.image_height * env.image_width) < 0.05

    assert vision_obs['seg'].shape == (env.image_height, env.image_width, 1)
    assert np.all(0 <= vision_obs['seg']) and np.all(vision_obs['seg'] <= 1.0)
Esempio n. 4
0
def test_import_building_big():
    download_assets()
    download_demo_data()

    s = Simulator(mode='headless')
    scene = StaticIndoorScene('Rs')
    s.import_scene(scene, texture_scale=1)
    assert s.objects == list(range(2))
    s.disconnect()
Esempio n. 5
0
def test_velodyne():
    download_assets()
    download_demo_data()
    config_filename = os.path.join(gibson2.root_path,
                                   '../test/test_house.yaml')
    env = iGibsonEnv(config_file=config_filename, mode='headless')
    velodyne_sensor = VelodyneSensor(env)
    velodyne_obs = velodyne_sensor.get_obs(env)
    assert (velodyne_obs.shape[1] == 3)
Esempio n. 6
0
def test_import_stadium():
    download_assets()
    download_demo_data()

    s = Simulator(mode='headless')
    scene = StadiumScene()
    s.import_scene(scene)
    print(s.objects)
    assert s.objects == list(range(4))
    s.disconnect()
Esempio n. 7
0
def test_scan_sensor():
    download_assets()
    download_demo_data()
    config_filename = os.path.join(gibson2.root_path,
                                   '../test/test_house.yaml')
    env = iGibsonEnv(config_file=config_filename, mode='headless')
    scan_sensor = ScanSensor(env, ['scan'])
    scan_obs = scan_sensor.get_obs(env)['scan']

    assert scan_obs.shape == (scan_sensor.n_horizontal_rays,
                              scan_sensor.n_vertical_beams)
    assert np.all(0 <= scan_obs) and np.all(scan_obs <= 1.0)
Esempio n. 8
0
def test_env():
    download_assets()
    download_demo_data()
    config_filename = os.path.join(gibson2.root_path,
                                   '../test/test_house.yaml')
    env = iGibsonEnv(config_file=config_filename, mode='headless')
    try:
        for j in range(2):
            env.reset()
            for i in range(300):  # 300 steps, 30s world time
                s = time()
                action = env.action_space.sample()
                ts = env.step(action)
                print('ts', 1 / (time() - s))
                if ts[2]:
                    print("Episode finished after {} timesteps".format(i + 1))
                    break
    finally:
        env.close()
Esempio n. 9
0
def test_occupancy_grid():
    print("Test env")
    download_assets()
    download_demo_data()
    config_filename = os.path.join(gibson2.root_path,
                                   '../test/test_house_occupancy_grid.yaml')

    nav_env = iGibsonEnv(config_file=config_filename, mode='headless')
    nav_env.reset()
    nav_env.robots[0].set_position_orientation([0, 0, 0], [0, 0, 0, 1])
    nav_env.simulator.step()

    action = nav_env.action_space.sample()
    ts = nav_env.step(action)
    assert np.sum(ts[0]['occupancy_grid'] == 0) > 0
    assert np.sum(ts[0]['occupancy_grid'] == 1) > 0
    plt.imshow(ts[0]['occupancy_grid'][:, :, 0])
    plt.colorbar()
    plt.savefig('occupancy_grid.png')
    nav_env.clean()
Esempio n. 10
0
def test_base_planning():
    print("Test env")
    download_assets()
    download_demo_data()
    config_filename = os.path.join(gibson2.root_path,
                                   '../test/test_house_occupancy_grid.yaml')

    nav_env = iGibsonEnv(config_file=config_filename, mode='headless')
    motion_planner = MotionPlanningWrapper(nav_env)
    state = nav_env.reset()
    nav_env.robots[0].set_position_orientation([0, 0, 0], [0, 0, 0, 1])
    nav_env.simulator.step()
    plan = None
    itr = 0
    while plan is None and itr < 10:
        plan = motion_planner.plan_base_motion([0.5, 0, 0])
        print(plan)
        itr += 1
    motion_planner.dry_run_base_plan(plan)

    assert len(plan) > 0
    nav_env.clean()
Esempio n. 11
0
 def __init__(self):
     download_assets()
     download_demo_data()
Esempio n. 12
0
from gibson2.core.simulator import Simulator
from gibson2.core.physics.scene import BuildingScene, StadiumScene
from gibson2.core.physics.robot_locomotors import Turtlebot, Husky, Ant, Humanoid, JR2, JR2_Kinova
import yaml
from gibson2.utils.utils import parse_config
import os
import gibson2

from gibson2.utils.assets_utils import download_assets, download_demo_data

download_assets()
download_demo_data()
config = parse_config(os.path.join(gibson2.root_path, '../test/test.yaml'))


def test_import_building():
    s = Simulator(mode='headless')
    scene = BuildingScene('Rs')
    s.import_scene(scene, texture_scale=0.4)
    for i in range(15):
        s.step()
    assert s.objects == list(range(2))
    s.disconnect()


def test_import_building_big():
    s = Simulator(mode='headless')
    scene = BuildingScene('Rs')
    s.import_scene(scene, texture_scale=1)
    assert s.objects == list(range(2))
    s.disconnect()