Ejemplo n.º 1
0
def page_get():
    req_data = request.json
    if req_data is not None:
        print req_data
        if req_data['method'] == "set_obs":
            obs_str = req_data['obs_grid']
            obs_grid_new = decode_grid(obs_str)
            app.arena_map.obs_grid = obs_grid_new
        elif req_data['method'] == "step":
            step_algorithm(app.arena_map)
        elif req_data['method'] == "reset":
            app.arena_map.__init__()

    return json.dumps(
        {
            "map": app.arena_map.get_encoded_map(),
            "obs": app.arena_map.get_encoded_obs(),
            "w_number_grid": app.arena_map.w_number_grid,
            "w_detail_grid": app.arena_map.w_detail_grid,
            "robot": {
                'x': app.arena_map.get_robot_coord()[0],
                'y': app.arena_map.get_robot_coord()[1],
                'degree': app.arena_map.get_robot_degree()
            },
            "state": app.arena_map.robot_state
        })
Ejemplo n.º 2
0
def run_algo():
    """
    This is the main algorithm driver that
    1. wait for physical_robot.command_now to be CM_WAIT
    2. run next command
    """
    global g
    g = g
    """:type : GlobalState"""
    if ( g.physical_robot.command_now is not CM_WAIT or     # if robot is not in waiting
            g.physical_robot.command_id != g.command_id ):  # if previously given command not executed
        return
    step_algorithm(g.arena)
    # after step_algorithm, g.command_algo may be set
    if g.command_algo is not None:
        g.command_id += 1
        g.command_id %= 256
    """
def page_get():
    req_data = request.json
    if req_data is not None:
        print req_data
        if req_data['method'] == "set_obs":
            obs_str = req_data['obs_grid']
            obs_grid_new = decode_grid(obs_str)
            app.arena.obs_grid = obs_grid_new
        elif req_data['method'] == "step":
            step_algorithm(app.arena)
        elif req_data['method'] == "reset":
            obs_preserved = app.arena.obs_grid
            app.arena.__init__()
            app.arena.obs_grid = obs_preserved
        elif req_data['method'] == "set_max_time":
            max_time = req_data['max_time']
            if max_time is None:
                max_time = 5 * 60
            app.arena.time_max = max_time
        elif req_data['method'] == "set_max_percentage":
            max_percentage = req_data['max_percentage']
            print max_percentage
            if max_percentage is None:
                max_percentage = 100
            app.arena.max_exploration_percentage = max_percentage

    return json.dumps(
        {
            "map": app.arena.get_encoded_map(),
            "obs": app.arena.get_encoded_obs(),
            "w_number_grid": app.arena.w_number_grid,
            "w_detail_grid": app.arena.w_detail_grid,
            "timing":{
                "explore": app.arena.get_time_explore(),
                "shortest": app.arena.get_time_shortest()
            },
            "robot": {
                'x': app.arena.get_robot_coord()[0],
                'y': app.arena.get_robot_coord()[1],
                'degree': app.arena.get_robot_degree()
            },
            "state": app.arena.robot_state
        })