Exemplo n.º 1
0
def main():
    config = parse_config('../configs/turtlebot_demo.yaml')
    settings = MeshRendererSettings(enable_shadow=False, msaa=False)
    s = Simulator(mode='gui',
                  image_width=256,
                  image_height=256,
                  rendering_settings=settings)

    scene = StaticIndoorScene('Rs',
                              build_graph=True,
                              pybullet_load_texture=True)
    s.import_scene(scene)
    turtlebot = Turtlebot(config)
    s.import_robot(turtlebot)

    for _ in range(10):
        obj = YCBObject('003_cracker_box')
        s.import_object(obj)
        obj.set_position_orientation(np.random.uniform(low=0, high=2, size=3),
                                     [0, 0, 0, 1])

    print(s.renderer.instances)

    for i in range(10000):
        with Profiler('Simulator step'):
            turtlebot.apply_action([0.1, 0.1])
            s.step()
            rgb = s.renderer.render_robot_cameras(modes=('rgb'))
    s.disconnect()
Exemplo n.º 2
0
def test_import_object():
    s = Simulator(mode='headless')
    scene = StadiumScene()
    s.import_scene(scene)

    obj = YCBObject('003_cracker_box')
    s.import_object(obj)
    objs = s.objects
    s.disconnect()
    assert objs == list(range(5))
Exemplo n.º 3
0
def test_import_many_object():
    s = Simulator(mode='headless')
    scene = StadiumScene()
    s.import_scene(scene)

    for i in range(30):
        obj = YCBObject('003_cracker_box')
        s.import_object(obj)

    for j in range(1000):
        s.step()
    last_obj = s.objects[-1]
    s.disconnect()
    assert (last_obj == 33)
Exemplo n.º 4
0
def test_import_box():
    s = Simulator(mode='headless')
    scene = StadiumScene()
    s.import_scene(scene)
    print(s.objects)
    # wall = [pos, dim]
    wall = [[[0, 7, 1.01], [10, 0.2, 1]], [[0, -7, 1.01], [6.89, 0.1, 1]],
            [[7, -1.5, 1.01], [0.1, 5.5, 1]], [[-7, -1, 1.01], [0.1, 6, 1]],
            [[-8.55, 5, 1.01], [1.44, 0.1, 1]],
            [[8.55, 4, 1.01], [1.44, 0.1, 1]]]

    obstacles = [[[-0.5, 2, 1.01], [3.5, 0.1, 1]],
                 [[4.5, -1, 1.01], [1.5, 0.1, 1]], [[-4, -2, 1.01],
                                                    [0.1, 2, 1]],
                 [[2.5, -4, 1.01], [1.5, 0.1, 1]]]

    for i in range(len(wall)):
        curr = wall[i]
        obj = Cube(curr[0], curr[1])
        s.import_object(obj)

    for i in range(len(obstacles)):
        curr = obstacles[i]
        obj = Cube(curr[0], curr[1])
        s.import_object(obj)

    config = parse_config(os.path.join(gibson2.root_path, '../test/test.yaml'))
    turtlebot1 = Turtlebot(config)
    turtlebot2 = Turtlebot(config)
    s.import_robot(turtlebot1)
    s.import_robot(turtlebot2)
    turtlebot1.set_position([6., -6., 0.])
    turtlebot2.set_position([-3., 4., 0.])

    for i in range(100):
        s.step()
    s.disconnect()
Exemplo n.º 5
0
def test_import_rbo_object():
    s = Simulator(mode='headless')
    try:
        scene = StadiumScene()
        s.import_scene(scene)

        obj = RBOObject('book')
        s.import_object(obj)

        obj2 = RBOObject('microwave')
        s.import_object(obj2)

        obj.set_position([0, 0, 2])
        obj2.set_position([0, 1, 2])

        obj3 = ArticulatedObject(
            os.path.join(gibson2.assets_path, 'models', 'scene_components',
                         'door.urdf'))
        s.import_object(obj3)

        for i in range(100):
            s.step()
    finally:
        s.disconnect()
def benchmark(render_to_tensor=False, resolution=512):
    config = parse_config(os.path.join(gibson2.root_path, '../test/test.yaml'))
    s = Simulator(mode='headless',
                  image_width=resolution,
                  image_height=resolution,
                  render_to_tensor=render_to_tensor)
    scene = StaticIndoorScene('Rs',
                              build_graph=True,
                              pybullet_load_texture=True)
    s.import_scene(scene)
    turtlebot = Turtlebot(config)
    s.import_robot(turtlebot)

    n_frame = 500
    start = time.time()
    for i in range(n_frame):
        turtlebot.apply_action([0.1, 0.1])
        s.step()
        rgb = s.renderer.render_robot_cameras(modes=('rgb'))

    physics_render_elapsed = time.time() - start
    physics_render_fps = n_frame / physics_render_elapsed
    print(
        "physics simulation + rendering rgb, resolution {}, render_to_tensor {}: {} fps"
        .format(resolution, render_to_tensor, physics_render_fps))

    start = time.time()
    for i in range(n_frame):
        rgb = s.renderer.render_robot_cameras(modes=('rgb'))

    render_elapsed = time.time() - start
    rgb_fps = n_frame / render_elapsed
    print("Rendering rgb, resolution {}, render_to_tensor {}: {} fps".format(
        resolution, render_to_tensor, n_frame / render_elapsed))

    start = time.time()
    for i in range(n_frame):
        rgb = s.renderer.render_robot_cameras(modes=('3d'))

    render_elapsed = time.time() - start
    pc_fps = n_frame / render_elapsed
    print("Rendering 3d, resolution {}, render_to_tensor {}: {} fps".format(
        resolution, render_to_tensor, n_frame / render_elapsed))

    start = time.time()
    for i in range(n_frame):
        rgb = s.renderer.render_robot_cameras(modes=('normal'))

    normal_fps = n_frame / render_elapsed
    render_elapsed = time.time() - start
    print(
        "Rendering normal, resolution {}, render_to_tensor {}: {} fps".format(
            resolution, render_to_tensor, n_frame / render_elapsed))
    plt.figure()
    plt.bar([0, 1, 2, 3], [physics_render_fps, rgb_fps, pc_fps, normal_fps],
            color='g')
    plt.xticks([0, 1, 2, 3], ['sim+render', 'rgb', '3d', 'normal'])
    plt.ylabel('fps')
    plt.xlabel('mode')
    plt.title('Static Scene Benchmark, resolution {}, to_tensor {}'.format(
        resolution, render_to_tensor))
    plt.savefig('static_scene_benchmark_res{}_tensor{}.pdf'.format(
        resolution, render_to_tensor))

    s.disconnect()