Esempio n. 1
0
def speed_test(args):
    import roombasim.pittras.config
    cfg.load(roombasim.pittras.config)

    n = args.frames

    print('Starting speed test [{} frames]'.format(n))

    e = Environment()
    e.reset()

    d = cfg.AGENT([13,10], 0)
    e.agent = d

    start = time.time()

    i = 0
    el = 0
    while i < n:
        el += 1/60.
        e.update(1/60., el)
        i += 1

    end = time.time()

    dur = end - start
    mul = n / dur

    print('Processing {} frames took {} seconds'.format(n, dur))
    print('Speed of {} fps'.format(mul))
Esempio n. 2
0
def keyboard_demo(args):
    import roombasim.pittras.config
    from roombasim.ai import KeyboardController, KeyboardTask

    cfg.load(roombasim.pittras.config)

    # setup mission
    environment = Environment()
    environment.reset()

    # setup agent
    agent = cfg.AGENT([1.5,1.5], 0)
    environment.agent = agent

    # create window so the keyboard can access it
    window = Display(environment)

    # setup controller
    controller = KeyboardController(window=window)

    def update_func(delta, elapsed):
        environment.update(delta, elapsed)
        controller.frame_update(delta, elapsed, environment)

    window.set_update_func(update_func)
    config = pyglet.gl.Config(sample_buffers=1, samples=4)

    pyglet.app.run()
Esempio n. 3
0
def nographics_test(args):
    import roombasim.pittras.config
    cfg.load(roombasim.pittras.config)

    n = args.rounds

    print('Starting {} rounds'.format(n))

    e = Environment()

    good_exits = []
    bad_exits = []
    scores = []

    for i in range(n):
        e.reset()

        print('Round {}'.format(i))

        for elapsed in np.arange(0, 10 * 60, 1 / 60.):
            e.update(1 / 60., 1000 * elapsed)

        good_exits.append(e.good_exits)
        bad_exits.append(e.bad_exits)
        scores.append(e.score)

    with open(args.stats_file, 'w') as f:
        f.write(', '.join(map(str, good_exits)) + '\n')
        f.write(', '.join(map(str, bad_exits)) + '\n')
        f.write(', '.join(map(str, scores)) + '\n')

    print('Done')
Esempio n. 4
0
def run_controller(args):
    config, err = _load_class(args.config)

    if (config is None):
        print("Couldn't load config path: " + str(args.config))
        print('See the following error:\n')
        print(err)
        return
    else:
        cfg.load(config)

    controller_p, err = _load_class(args.controller)

    if (controller_p is None):
        print("Couldn't load class: " + str(args.controller))
        print('See the following error:\n')
        print(err)
        return
    else:
        print("Loaded Controller: " + str(controller_p))
    
    # initialize controller
    controller = controller_p()

    # setup mission
    environment = Environment()
    environment.reset()

    # setup agent
    location = args.start_location
    agent = cfg.AGENT([location[0],location[1]], 0, location[2])
    environment.agent = agent

    # create window so the keyboard can access it
    if args.timescale:
        window = Display(environment, args.timescale)
    else:
        window = Display(environment)

    def update_func(delta, elapsed):
        environment.update(delta, elapsed)
        controller.frame_update(delta, elapsed, environment)

    window.set_update_func(update_func)
    config = pyglet.gl.Config(sample_buffers=1, samples=4)

    pyglet.app.run()
Esempio n. 5
0
def human_player(args):
    '''
    Run the environment, letting a human control the drone
    '''
    if args.num_targets != None:
        cfg.MISSION_NUM_TARGETS = args.num_targets

    if args.num_obstacles != None:
        cfg.MISSION_NUM_OBSTACLES = args.num_obstacles

    if args.target_spawn_radius != None:
        cfg.MISSION_TARGET_SPAWN_RADIUS = args.target_spawn_radius

    if args.obstacle_spawn_radius != None:
        cfg.MISSION_OBSTACLE_SPAWN_RADIUS = args.obstacle_spawn_radius


    import roombasim.pittras.config
    cfg.load(roombasim.pittras.config)

    # setup mission
    environment = Environment()
    environment.reset()

    # setup agent
    agent = cfg.AGENT([1.5,1.5], 0)
    environment.agent = agent

    config = pyglet.gl.Config(sample_buffers=1, samples=4)
    if args.timescale:
        window = Display(environment, args.timescale)
    else:
        window = Display(environment)

    from roombasim.pittras.ai import MouseController
    mouse_controller = MouseController()
    window.set_click_callback(mouse_controller.mouse_callback)

    def update_func(delta, elapsed):
        environment.update(delta, elapsed)
        mouse_controller.frame_update(delta, elapsed, environment)

    window.set_update_func(update_func)

    pyglet.app.run()
Esempio n. 6
0
def run_demo(args):
    '''
    Runs a visual demo of roomba movement
    '''
    if args.num_targets != None:
        cfg.MISSION_NUM_TARGETS = args.num_targets

    if args.num_obstacles != None:
        cfg.MISSION_NUM_OBSTACLES = args.num_obstacles

    if args.target_spawn_radius != None:
        cfg.MISSION_TARGET_SPAWN_RADIUS = args.target_spawn_radius

    if args.obstacle_spawn_radius != None:
        cfg.MISSION_OBSTACLE_SPAWN_RADIUS = args.obstacle_spawn_radius


    import roombasim.pittras.config
    cfg.load(roombasim.pittras.config)

    # setup mission
    environment = Environment()
    environment.reset()

    # setup agent
    agent = cfg.AGENT([13,10], 0)
    environment.agent = agent

    config = pyglet.gl.Config(sample_buffers=1, samples=4)
    if args.timescale:
        window = Display(environment, args.timescale)
    else:
        window = Display(environment)

    def update_func(delta, elapsed):
        environment.update(delta, elapsed)

    window.set_update_func(update_func)

    pyglet.app.run()