示例#1
0
def test_animation():

    options = awe.Options(True)

    # basic options
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['trajectory']['lift_mode']['windings'] = 1
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['trajectory']['type'] = 'lift_mode'
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['tether_drag_model'] = 'trivial'
    options['nlp']['n_k'] = 2
    options['solver']['max_iter'] = 0

    options['visualization']['cosmetics']['trajectory']['kite_bodies'] = True
    options['visualization']['cosmetics']['interpolation']['N'] = 2

    # build trial and optimize
    trial = awe.Trial(options, 'trial1')
    trial.build()
    trial.optimize(final_homotopy_step='initial')

    trial.plot('animation')
    os.remove('trial1.mp4')
示例#2
0
def test_visualization():

    options = awe.Options(True)

    # basic options
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['trajectory']['lift_mode']['windings'] = 1
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['trajectory']['type'] = 'lift_mode'
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['tether_drag_model'] = 'trivial'
    options['nlp']['n_k'] = 2
    options['solver']['max_iter'] = 0

    # build trial and optimize
    trial = awe.Trial(options, 'trial1')
    trial.build()
    trial.optimize(final_homotopy_step='initial', debug_flags='all')

    # set flags and plot
    trial_flags = ['all']
    trial.plot(trial_flags)

    # build sweep and run
    sweep_opts = [(['user_options', 'wind', 'u_ref'], [5., 5.5])]
    sweep = awe.Sweep(name='sweep_viz_test', options=options, seed=sweep_opts)
    sweep.run(final_homotopy_step='initial', debug_flags='all')

    # set flags and plot
    sweep_flags = [
        'all', 'comp_all', 'outputs:tether_length',
        'comp_outputs:tether_length'
    ]
    sweep.plot(sweep_flags)
示例#3
0
def test_trial_serial():

    # set-up trial options
    options = awe.Options(True)  # True refers to internal access switch
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['tether_drag_model'] = 'split'
    options['user_options']['trajectory']['lift_mode']['windings'] = 1
    options['user_options']['induction_model'] = 'not_in_use'
    options['nlp']['n_k'] = 2
    options['solver']['max_iter'] = 0

    # build collocation trial
    trial = awe.Trial(name='serial_test', seed=options)
    trial.build()
    trial.optimize(final_homotopy_step='initial')
    trial.save('dict')

    # load and test collocation trial
    file_pi = open('serial_test.dict', 'rb')
    dict_test = pickle.load(file_pi)
    trial_test = awe.Trial(dict_test)
    file_pi.close()
    os.remove("serial_test.dict")

    trial_test.plot('all')

    # set-up ms trial options
    options['nlp']['discretization'] = 'multiple_shooting'
    options['nlp']['n_k'] = 10

    # build multiple shooting trial
    trialMS = awe.Trial(name='serial_test_MS', seed=options)
    trialMS.build()
    trialMS.optimize(final_homotopy_step='initial')
    trialMS.save('dict')

    # load and test multiple shooting trial
    file_pi_serial = open('serial_test_MS.dict', 'rb')
    dict_testMS = pickle.load(file_pi_serial)
    trial_testMS = awe.Trial(dict_testMS)

    file_pi_serial.close()
    os.remove("serial_test_MS.dict")

    trial_testMS.plot('all')
示例#4
0
    def __init__(self, mpc_options, ts, trial):
        """ Constructor.
        """

        awelogger.logger.info("Creating a {} periodic MPC controller with horizon length {}...".format(
            mpc_options['cost_type'], mpc_options['N']))
        awelogger.logger.info("Based on direct collocation with {} polynomials of order {}.".format(
            mpc_options['scheme'], mpc_options['d']))

        # store discretization data
        self.__N = mpc_options['N']
        self.__d = mpc_options['d']
        self.__scheme = mpc_options['scheme']
        self.__cost_type = mpc_options['cost_type']
        self.__pocp_trial = trial
        self.__ts = ts
        self.__mpc_options = mpc_options

        # store model data
        self.__nx = trial.model.variables['xd'].shape[0]
        self.__nu = trial.model.variables['u'].shape[0]
        self.__nz = trial.model.variables['xa'].shape[0]

        # create mpc trial
        options = copy.deepcopy(trial.options)
        options['user_options']['trajectory']['type'] = 'mpc'
        options['nlp']['discretization'] = 'direct_collocation'
        options['nlp']['n_k'] = self.__N
        options['nlp']['d'] = self.__d
        options['nlp']['scheme'] = self.__scheme
        options['nlp']['collocation']['u_param'] = 'poly'
        options['visualization']['cosmetics']['plot_ref'] = True
        fixed_params = {}
        for name in list(self.__pocp_trial.model.variables_dict['theta'].keys()):
            if name != 't_f':
                fixed_params[name] = self.__pocp_trial.optimization.V_final['theta',name].full()
        fixed_params['t_f'] = self.__N*self.__ts
        options['user_options']['trajectory']['fixed_params'] = fixed_params

        self.__trial = awe.Trial(seed = options)
        self.__build_trial()

        # construct mpc solver
        self.__construct_solver()

        # create time-varying reference to track
        if self.__cost_type == 'tracking':
            self.__create_reference_interpolator()

        # periodic indexing
        self.__index = 0

        # initialize
        self.__initialize_solver()

        awelogger.logger.info("Periodic MPC controller built.")

        return None
def test_initial_guess_generation():
    # ===========================================
    # SET-UP DUMMY PROBLEM
    # ===========================================

    # make default options object
    options = awe.Options(True)  # True refers to internal access switch

    # choose simplest model
    options['user_options']['system_model']['architecture'] = {
        1: 0,
        2: 1,
        3: 1,
        4: 1,
        5: 4,
        6: 4
    }
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['tether_drag_model'] = 'split'
    options['user_options']['trajectory']['lift_mode']['phase_fix'] = True
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['kite_standard'] = ampyx_data.data_dict()
    options['solver']['initialization']['initialization_type'] = 'modular'
    options['model']['tether']['control_var'] = 'dddl_t'

    # make trial, build and run
    trial = awe.Trial(name='test', seed=options)
    trial.build()
    trial.optimize(final_homotopy_step='initial_guess')
    architecture = trial.model.architecture
    number_of_nodes = architecture.number_of_nodes
    parent_map = architecture.parent_map
    for node in range(1, number_of_nodes):
        parent = parent_map[node]
        c_avg = np.average(
            abs(
                np.array(
                    trial.optimization.output_vals[0]['coll_outputs', :, :,
                                                      'tether_length',
                                                      'c' + str(node) +
                                                      str(parent)])))
        dc_avg = np.average(
            abs(
                np.array(
                    trial.optimization.output_vals[0]['coll_outputs', :, :,
                                                      'tether_length',
                                                      'dc' + str(node) +
                                                      str(parent)])))
        ddc_avg = np.average(
            abs(
                np.array(
                    trial.optimization.output_vals[0]['coll_outputs', :, :,
                                                      'tether_length',
                                                      'ddc' + str(node) +
                                                      str(parent)])))
        assert (c_avg < 1e-8)
        assert (dc_avg < 1e-8)
        assert (ddc_avg < 1)
示例#6
0
def generate_kite_model_and_orbit(N):

    import point_mass_model

    # make default options object
    options = awe.Options(True)

    # single kite with point-mass model
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['kite_standard'] = point_mass_model.data_dict()

    # trajectory should be a single pumping cycle with initial number of five windings
    options['user_options']['trajectory']['type'] = 'power_cycle'
    options['user_options']['trajectory']['system_type'] = 'drag_mode'
    options['user_options']['trajectory']['lift_mode']['windings'] = 1

    # don't include induction effects, use simple tether drag
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['tether_drag_model'] = 'trivial'
    options['nlp']['n_k'] = N

    # get point mass model data
    options = point_mass_model.set_options(options)

    # initialize and optimize trial
    trial = awe.Trial(options, 'single_kite_drag_mode')
    trial.build()
    trial.optimize(final_homotopy_step='final')
    # trial.plot(['states','controls', 'constraints'])
    # plt.show()

    # extract model data
    sol = {}
    sol['model'] = trial.generate_optimal_model()
    sol['l_t'] = trial.optimization.V_opt['xd', 0, 'l_t']

    # initial guess
    w_init = []
    for k in range(N):
        w_init.append(trial.optimization.V_opt['xd', k][:-3])
        w_init.append(trial.optimization.V_opt['u', k][3:6])
    sol['w0'] = ca.vertcat(*w_init)

    return sol
示例#7
0
        #options['model']['ground_station']['ddl_t_max'] = 95.04

    options['user_options']['wind']['u_ref'] = w
    options['nlp']['n_k'] = n_k
        #options['model']['system_bounds']['u']['dkappa'] = [-1.0, 1.0]

        #options['model']['system_bounds']['xd']['l_t'] = [1.0e-2, 1.0e3]
        #options['solver']['initialization']['xd']['l_t'] = 1.0e3 # initial guess

        # don't include induction effects, use simple tether drag
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['tether_drag_model'] = 'split'
        # initial tether length guess
        #options['solver']['initialization']['xd']['l_t'] = 200.0 # initial guess



        ##################
        # OPTIMIZE TRIAL #
        ##################

    options['solver']['linear_solver'] = 'ma57'

        # initialize and optimize trial
    trial = awe.Trial(options, name)
    trial.build()
    trial.optimize()
    quality_print_results = trial.quality.return_results()
    solve_succed(quality_print_results, name)
    trial.write_to_csv()
示例#8
0
options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()

# trajectory should be a single pumping cycle with initial number of five windings
options['user_options']['trajectory']['type'] = 'power_cycle'
options['user_options']['trajectory']['system_type'] = 'lift_mode'
options['user_options']['trajectory']['lift_mode']['windings'] = 6

# don't include induction effects, use simple tether drag
options['user_options']['induction_model'] = 'not_in_use'
options['user_options']['tether_drag_model'] = 'split'

options['nlp']['n_k'] = 80
options['nlp']['collocation']['u_param'] = 'poly'

# initialize and optimize trial
trial = awe.Trial(options, 'single_kite_lift_mode')
trial.build()
trial.optimize()

# set-up closed-loop simulation
N_mpc = 10 # MPC horizon
N_sim = 2000  # closed-loop simulation steps
ts = 0.1 # sampling time

# MPC options
options['mpc']['scheme'] = 'radau'
options['mpc']['d'] = 4
options['mpc']['jit'] = True
options['mpc']['cost_type'] = 'tracking'
options['mpc']['expand'] = True
options['mpc']['linear_solver'] = 'ma57'
示例#9
0
# single kite with point-mass model
options['user_options']['system_model']['architecture'] = {1:0, 2:1, 3:1}
options['user_options']['system_model']['kite_dof'] = 3
options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
# trajectory should be a single pumping cycle with initial number of three windings
options['user_options']['trajectory']['type'] = 'power_cycle'
options['user_options']['trajectory']['system_type'] = 'lift_mode'
options['user_options']['trajectory']['lift_mode']['windings'] = 2

# don't include induction effects, use simple tether drag
options['user_options']['wind']['u_ref'] = 5.0 # m/s
options['user_options']['induction_model'] = 'not_in_use'
options['user_options']['tether_drag_model'] = 'split'

trial = awe.Trial(seed = options, name = 'opt_design')
trial.build()
trial.optimize()

# fix params for wind speed sweep
fixed_params = {}
for name in list(trial.model.variables_dict['theta'].keys()):
    if ('diam' in name) or (name == 'l_s'):
        fixed_params[name] = trial.optimization.V_final['theta',name].full()

options['user_options']['trajectory']['fixed_params'] = fixed_params

########################
# SET-UP SWEEP OPTIONS #
########################
sweep_opts = [(['user_options', 'wind', 'u_ref'], np.linspace(3,15,5, endpoint=True))]
示例#10
0
# single kite with point-mass model
options['user_options']['system_model']['architecture'] = {1:0, 2:1, 3:1}
options['user_options']['system_model']['kite_dof'] = 3
options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()

# pick drag-mode trajectory
options['user_options']['trajectory']['type'] = 'power_cycle'
options['user_options']['trajectory']['system_type'] = 'drag_mode'

# bounds on dkappa: be aware to check if these values make sense
# from a physical point of view your specific system
options['model']['system_bounds']['u']['dkappa'] = [-1.0, 1.0]

# don't include induction effects, use trivial tether drag
options['user_options']['induction_model'] = 'not_in_use'
options['user_options']['tether_drag_model'] = 'split'

# bounds on tether length
options['model']['system_bounds']['xd']['l_t'] = [1.0e-2, 1.0e3]

# choose coarser grid (single-loop trajectory)
# options['nlp']['n_k'] = 20

# initialize and optimize trial
trial = awe.Trial(options, 'dual_kite_drag_mode')
trial.build()
trial.optimize()
trial.plot(['isometric','states','controls','constraints'])
plt.show()
示例#11
0
options['user_options']['wind']['u_ref'] = 5

options['solver']['max_iter'] = 40000
options['solver']['max_cpu_time'] = 2.e4

options['nlp']['n_k'] = 60
options['solver']['max_iter'] = 2

##################
# OPTIMIZE TRIAL #
##################
options['solver']['linear_solver'] = 'mumps'

# initialize and optimize trial
trial = awe.Trial(options, 'rachel_awebox_generator')
trial.build()
trial.optimize(final_homotopy_step='initial')
#options 1 oder 2
V_final = trial.optimization.V_final
V_solution_scaled = trial.nlp.V(trial.optimization.solution['x'])
V_final['coll_var', :, :, 'xd', 'xd_i_s_0']  #V_final['xd', :, 'q21']
V_solution_scaled['coll_var', :, :, 'xd', 'xd_i_s_0']
print(options['user_options'])
trial.plot('level_3')

#!/usr/bin/python3

import awebox as awe
import matplotlib.pyplot as plt
示例#12
0
# don't include induction effects, use simple tether drag
options['user_options']['induction_model'] = 'not_in_use'
options['user_options']['tether_drag_model'] = 'split'

# initial tether length guess
#options['solver']['initialization']['xd']['l_t'] = 200.0 # initial guess

##################
# OPTIMIZE TRIAL #
##################

options['solver']['linear_solver'] = 'mumps'
#options['solver']['initialization']['fix_tether_length'] = True

# initialize and optimize trial
trial = awe.Trial(options, name[0])
trial.build()
trial.optimize()
trial.quality.print_results()
trial.plot('level_3')
trial.write_to_csv()

#!/usr/bin/python3

import awebox as awe
import matplotlib.pyplot as plt

########################
# SET-UP TRIAL OPTIONS #
########################
nominal_landing_options = copy.deepcopy(pumping_options)

# change options to landing trajectory
nominal_landing_options['user_options']['trajectory'][
    'type'] = 'nominal_landing'

# change initial guess generation to modular
nominal_landing_options['solver']['initialization'][
    'initialization_type'] = 'modular'

###################
# OPTIMIZE TRIALS #
###################

# initialize and optimize pumping trial
pumping_trial = awe.Trial(pumping_options, 'dual_kite_lift_mode')
pumping_trial.build()
pumping_trial.optimize()

# set optimized pumping trial as prameterized initial condition for landing
nominal_landing_options['user_options']['trajectory']['transition'][
    'initial_trajectory'] = pumping_trial

# intialize and optimize nominal landing trial
nominal_landing_trial = awe.Trial(nominal_landing_options,
                                  'dual_kite_nominal_landing')
nominal_landing_trial.build()
nominal_landing_trial.optimize()

################
# PLOT RESULTS #
示例#14
0
# ddual kite with 6 DOF model
options['user_options']['system_model']['architecture'] = {1: 0, 2: 1, 3: 1}
options['user_options']['system_model']['kite_dof'] = 6
options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()

# trajectory should be a single looping
options['user_options']['trajectory']['type'] = 'tracking'
options['user_options']['trajectory']['system_type'] = 'lift_mode'
options['user_options']['trajectory']['lift_mode']['windings'] = 1

# don't include induction effects, use simple tether drag
options['user_options']['induction_model'] = 'not_in_use'
options['user_options']['tether_drag_model'] = 'split'

# keep main tether length constant
options['user_options']['trajectory']['tracking']['fix_tether_length'] = True

# less discretization points necessary because only one winding
options['nlp']['n_k'] = 10

##################
# OPTIMIZE TRIAL #
##################

# initialize and optimize trial
trial = awe.Trial(options, 'dual_kite_tracking')
trial.build()
trial.optimize()
trial.plot('level_3')
plt.show()
options['user_options']['trajectory']['lift_mode']['windings'] = 1
options['user_options']['induction_model'] = 'not_in_use'

# direct collocation options
options['nlp']['n_k'] = 40
options['nlp']['collocation']['d'] = 4
options['nlp']['discretization'] = 'direct_collocation'
options['nlp']['parallelization']['overwrite'] = True
options['nlp']['cost']['output_quadrature'] = False

# solver options
options['solver']['mu_hippo'] = 1e-4
options['solver']['tol_hippo'] = 1e-4

# make trial, run and save
trial = awe.Trial(name='direct_coll', seed=options)
trial.build()
trial.optimize(final_homotopy_step=final_step)

# set integrator
options_ms = copy.deepcopy(options)
options_ms['nlp']['discretization'] = 'multiple_shooting'
options_ms['nlp']['integrator']['type'] = integrator

# update solver options
if final_step == 'final':
    options_ms['solver']['mu_hippo'] = 1e-9

# build and solve
trial2 = awe.Trial(name='multiple_shooting', seed=options_ms)
trial2.build()
示例#16
0
def test_integrators():

    # ===========================================
    # SET-UP DIRECT COLLOCATION PROBLEM AND SOLVE
    # ===========================================

    # make default options object
    base_options = awe.Options(True) # True refers to internal access switch

    # choose simplest model
    base_options['user_options']['system_model']['architecture'] = {1:0}
    base_options['user_options']['system_model']['kite_dof'] = 3
    base_options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    base_options['user_options']['tether_drag_model'] = 'split'
    base_options['user_options']['induction_model'] = 'not_in_use'
    
    # specify direct collocation options
    base_options['nlp']['n_k'] = 40
    base_options['nlp']['discretization'] = 'direct_collocation'
    base_options['nlp']['collocation']['u_param'] = 'zoh'
    base_options['nlp']['collocation']['scheme'] = 'radau'
    base_options['nlp']['collocation']['d'] = 4

    base_options['model']['tether']['control_var'] = 'dddl_t'

     # homotopy tuning
    base_options['solver']['mu_hippo'] = 1e-4
    base_options['solver']['tol_hippo'] = 1e-4

    # make trial, build and run
    trial = awe.Trial(name = 'test', seed = base_options)
    trial.build()
    trial.optimize()

    # extract solution data
    V_final = trial.optimization.V_opt
    P       = trial.optimization.p_fix_num
    Int_outputs = trial.optimization.integral_output_vals[1]
    model   = trial.model
    dae     = model.get_dae()

    # build dae variables for t = 0 within first shooting interval
    variables0 = struct_op.get_variables_at_time(base_options['nlp'], V_final, None, model.variables, 0)
    parameters = model.parameters(vertcat(P['theta0'], V_final['phi']))
    x0, z0, p  = dae.fill_in_dae_variables(variables0, parameters)

    # ===================================
    # TEST COLLOCATION INTEGRATOR
    # ===================================

    # set discretization to multiple shooting
    base_options['nlp']['discretization'] = 'multiple_shooting'
    base_options['nlp']['integrator']['type'] = 'collocation'
    base_options['nlp']['integrator']['collocation_scheme'] = base_options['nlp']['collocation']['scheme']
    base_options['nlp']['integrator']['interpolation_order'] = base_options['nlp']['collocation']['d']
    base_options['nlp']['integrator']['num_steps'] = 1

    # switch off expand to allow for use of integrator in NLP
    base_options['solver']['expand_overwrite'] = False

    # build MS trial
    trialColl = awe.Trial(name = 'testColl', seed = base_options)
    trialColl.build()

    # multiple shooting dae integrator
    F = trialColl.nlp.Multiple_shooting.F

    # integrate over one interval
    Ff = F(x0 = x0, z0 = z0, p = p)
    xf = Ff['xf']
    zf = Ff['zf']
    qf = Ff['qf']

    # evaluate integration error
    err_coll_x = np.max(np.abs(np.divide((xf - V_final['xd',1]), V_final['xd',1]).full()))
    xa = dae.z(zf)['xa']
    err_coll_z = np.max(np.abs(np.divide(dae.z(zf)['xa'] - V_final['coll_var',0, -1, 'xa'], V_final['coll_var',0, -1, 'xa']).full()))
    err_coll_q = np.max(np.abs(np.divide((qf - Int_outputs['int_out',1]), Int_outputs['int_out',1]).full()))

    tolerance = 1e-8

    # values should match up to nlp solver accuracy
    assert(err_coll_x < tolerance)
    assert(err_coll_z < tolerance)
    assert(err_coll_q < tolerance)

    # ===================================
    # TEST RK4-ROOT INTEGRATOR
    # ===================================

    # set discretization to multiple shooting
    base_options['nlp']['integrator']['type'] = 'rk4root'
    base_options['nlp']['integrator']['num_steps'] = 20

    # build MS trial
    trialRK = awe.Trial(name = 'testRK', seed = base_options)
    trialRK.build()

    # multiple shooting dae integrator
    F = trialRK.nlp.Multiple_shooting.F

    # integrate over one interval
    Ff = F(x0 = x0, z0 = z0, p = p)
    xf = Ff['xf']
    zf = Ff['zf']
    qf = Ff['qf']

    # evaluate 
    err_rk_x = np.max(np.abs(np.divide((xf - V_final['xd',1]), V_final['xd',1]).full()))
    xa = dae.z(zf)['xa']
    err_rk_z = np.max(np.abs(np.divide(dae.z(zf)['xa'] - V_final['coll_var',0, -1, 'xa'], V_final['coll_var',0, -1, 'xa']).full()))
    err_rk_q = np.max(np.abs(np.divide((qf - Int_outputs['int_out',1]), Int_outputs['int_out',1]).full()))

    # error should be below 1%
    assert(err_rk_x < 1e-2)
    assert(err_rk_z < 1e-2)
    assert(err_rk_q < 2e-2)