예제 #1
0
def fly_quadrotor(params=None, fly=True):
    gen = MultiFlipParams()
    quad = Quadcopter()
    if not params:
        params = gen.get_initial_parameters()
    sections = gen.get_sections(params)
    state = quad.update_state(sections)
    if fly:
        PlotFlight(state, 0.17).show()
    return state
예제 #2
0
def cmaes_evaluate(params):
    """5 dimensional variables[p0 ..... p5]"""
    gen = MultiFlipParams()
    quad = Quadcopter(False)
    # print("cmaes_evaluate")
    # Restrict duration of generated params to below 2 seconds
    if (params[1] > 2.5) or (params[2] > 2.5) or (params[4] > 2.5):
        return tuple([1000000] * 9)
    sections = gen.get_sections(params)
    for sect in sections:
        if sect[2] < 0:
            # print('Error sect:', sect)
            return tuple([1000000] * 9)

    quad.update_state(sections)
    final_state = np.array([quad.state['position'],
                            quad.state['velocity'],
                            quad.state['orientation']]).flatten()
    fitness = abs(ideal_final_state - final_state)
    # print("[", params, "] -> [", fitness, "]")
    return tuple(fitness)