def run(dlc=None, dlc_noipc=None, SAVE=None):
    f = np.linspace(0, 1.5, 1000)[1:]
    C = []
    modules = ['IPC_PI', 'IPC04', 'IPC07']
    for m in modules:
        module = importlib.import_module('Controllers.' + m)
        C.append(module.make)

    Mag = []
    for c in C:
        P = BladeModel.Blade(18)
        sys = ControlDesign.Turbine(P, c())
        Mag.append(signal.bode(sys.S, w=f * (2 * np.pi))[1])

    fig, ax = ControllerEvaluation.magplotSetup(F1p=0.16)
    ax.set_xlim(0.05, 1.5)

    ax.plot(f, Mag[0], '-.', label='$S(C_{PI})$')
    ax.plot(f, Mag[1], ':', label='$S(C_{1p})$')
    ax.plot(f, Mag[2], '-r', label='$S(C_{2})$')

    ax.set_ylim(-25, 10)

    ax.legend()

    if SAVE:
        plt.savefig(SAVE, dpi=200, bbox_inches='tight')
    plt.show()
    print()
def run(dlc=None, dlc_noipc=None, SAVE=None):
    f = np.linspace(0, 1.5, 1000)[1:]

    Yol = OLResponse.Response(18)
    Ycl = Spectrum(dlc(wsp=18, controller='ipcpi')[0])
    C = make()
    P = BladeModel.Blade(18)
    sys = ControlDesign.Turbine(P, C)
    mag = signal.bode(sys.S, w=f * (2 * np.pi))[1]
    actualMag = 20 * np.log10(Ycl(f) / Yol(f))
    fig, ax = ControllerEvaluation.magplotSetup(F1p=0.16)

    ax.set_xlim(0.05, 1.5)

    ax.axhline(0, lw=1, c='0.8', ls='-')
    ax.plot(f, mag, label='$S(C_{PI})$, linear model')
    ax.plot(f, actualMag, '--', label='$S(C_{PI})$, HAWC2 model')

    ax.set_ylim(-10, 10)
    ax.legend(loc='upper left')

    if SAVE:
        plt.savefig(SAVE, dpi=200, bbox_inches='tight')
    plt.show()
    print()
def run(dlc=None, dlc_noipc=None, SAVE=None):
    wsp =  18
    C = make()
    P = BladeModel.Blade(wsp)
    sys = ControlDesign.Turbine(P, C)

    plot_nyquist(sys.L, zoom=1.5, rightticks = True, save=SAVE)
Exemplo n.º 4
0
def run( SAVE=False):
    models = BladeModel.make()
    # plot transfer function over frequency response
    WSP = [6, 12, 18, 24]
    models = [x for x in models if x.wsp in WSP]

    fig, axes = plt.subplots(2, 1, sharex=True)
    plt.subplots_adjust(hspace=0.05)
    axes[0].grid(axis='x', which='minor')
    axes[1].grid(axis='x', which='minor')
    axes[1].set_ylim([-180, 180])
    axes[0].set_xlim([0.05, 5])
    axes[0].set_xscale('log')
    axes[0].set_yscale('log')
    axes[0].set_ylim([1e-2, 1e2])
    axes[1].set_yticks(np.arange(-180, 121, 60))
    axes[0].set_ylabel('$|G(jw)|$ [dB]')
    axes[1].set_ylabel('$< G(jw)$ [deg]')
    axes[1].set_xlabel('Frequency [Hz]')
    F1p = 0.16
    axes[1].set_xticks([F1p, 2*F1p, 3*F1p, 4*F1p], minor=True)
    axes[1].set_xticklabels(['$f_{1p}$', '$f_{2p}$', '$f_{3p}$', '$f_{4p}$'], minor=True)

    for i, model in enumerate(models):
        w, h = signal.freqresp(model.tf)
        f = w/(2*np.pi)
        axes[0].plot(f, abs(h), lw=1, label=f'${WSP[i]}m/s$')
        axes[1].plot(f, np.angle(h, deg=True), '-', lw=1)

    axes[0].legend(title='Windspeed', loc='lower right', ncol=2)
    if SAVE:
        plt.savefig(SAVE, dpi=200, bbox_inches='tight')

    plt.show(); print()
def run(dlc=None, dlc_noipc=None, SAVE=None):
    f = np.linspace(0, 1.5, 1000)[1:]
    C = []
    modules = ['IPC_PI', 'IPC04', 'IPC09', 'IPC10', 'IPC11']
    for m in modules:
        module = importlib.import_module('Controllers.' + m)
        C.append(module.make)

    Mag = []
    for i in [0, 1, 2, 3, 4]:
        P = BladeModel.Blade(18)
        sys = ControlDesign.Turbine(P, C[i]())
        Mag.append(signal.bode(sys.S, w=f * (2 * np.pi))[1])

    fig, ax = ControllerEvaluation.magplotSetup(F1p=0.16)
    ax.set_xlim(0.05, 1.5)
    ax.axhline(0, lw=1, c='0.8', ls='-')

    colors = ['#a1dab4', '#41b6c4', '#2c7fb8', '#253494']
    ax.plot(f, Mag[0], '-.', c='tab:orange', label='$S(C_{PI})$')
    for i in [1, 2, 3, 4]:
        ax.plot(f,
                Mag[i],
                '-',
                c=colors[i - 1],
                label='$S(C_{f' + f'{i}' + 'p})$')

    ax.set_ylim(-25, 10)

    ax.legend()

    if SAVE:
        plt.savefig(SAVE, dpi=200, bbox_inches='tight')
    plt.show()
    print()
Exemplo n.º 6
0
def run(dlc=None, dlc_noipc=None, SAVE=None):
    wsp = 18
    # Load transfer functions
    C = make()
    P = BladeModel.Blade(wsp)

    Kps, Tis = np.meshgrid([0.01, 0.015, 0.02], [0.5, 1, 2])

    fig, axes = plt.subplots(3, 3, sharex=False, sharey=False, figsize=(7, 7))
    plt.subplots_adjust(wspace=0.05, hspace=0.05)
    for i in range(3):
        for j in range(3):
            C = make(Kp=Kps[i, j], Ti=Tis[i, j])
            sys = ControlDesign.Turbine(P, C)
            plot_nyquist(sys.L, axes=axes[i, j], zoom=1, margin=True)
            perf = sys.performance(0.16)[0]
            axes[i, j].text(0,
                            0,
                            '$f_{1p}$: ' + '{:2.2f}\%'.format(perf * 100),
                            transform=axes[i, j].transAxes,
                            va='bottom')

    fig.text(0.1, 0.5, 'Real', va='center', rotation='vertical')
    fig.text(0.5, 0.1, 'Imaginary', ha='center', rotation='horizontal')

    for i in range(3):
        axes[0, i].set_title(f'$K_p=${Kps[0, i]}')
        axes[i, 2].yaxis.set_label_position('right')
        axes[i, 2].set_ylabel(f'$T_i=${Tis[i, 0]}')

    if SAVE:
        plt.savefig(SAVE, dpi=200, bbox_inches='tight')
    plt.show()
    print()
def getData():
    f1p = 0.16
    fs = f1p * np.array([1, 2, 3, 4])
    X = []
    P = BladeModel.Blade(wsp=18)
    Yol = OLResponse.Response(18)

    # loop over each controller
    for i, mod_name in enumerate(Modules):
        X.append({})

        # load linear closed loop system
        module = import_module('Controllers.' + mod_name)
        C = module.make()
        sys = ControlDesign.Turbine(P, C)

        X[i]['sm'] = sys.sm
        X[i]['linear'] = list(sys.performance(f1p))

        # load HAWC2 closed loop system results
        dlc = PostProc.DLC('dlc11_1')
        Sim = dlc(wsp=18, controller=ControllerName[i])[0]
        Ycl = Spectrum(Sim)
        X[i]['HAWC2'] = [Ycl(f) / Yol(f) - 1 for f in fs]

    return X
def run(dlcs, SAVE=None):
    wsp =  18
    C1 = IPC04.make()
    C2 = IPC07.make()
    P = BladeModel.Blade(wsp)
    sys1 = ControlDesign.Turbine(P, C1)
    sys2 = ControlDesign.Turbine(P, C2)

    #ControllerEvaluation.plot_nyquist(sys.L, zoom=1.5, rightticks = True, save=SAVE)
    plot_T(sys1.T, sys2.T, SAVE=SAVE)
Exemplo n.º 9
0
def run(dlc, dlc_noipc, c, C, SAVE=False):

    WSP = [6, 12, 18, 24]
    fnp = 0.16 * np.array([1, 2, 3, 4])
    for wsp in WSP:
        # Load transfer functions
        P = BladeModel.Blade(wsp)
        Yol = OLResponse.Response(wsp)
        # Calculate predicted output spectrum
        system = ControlDesign.Turbine(P, C)
        w, H = signal.freqresp(system.S)
        f = w / (2 * np.pi)
        Ycl_pred = abs(H) * Yol(f)
        # Load close loop output spectrum
        Sim = dlc(yaw=0, wsp=wsp, controller=c, Kp=-1)[0]
        Ycl = Spectrum(Sim)

        fig, ax = magplotSetup(F1p=0.16)
        ax.set_ylabel('Magnitude [m]')
        ax.plot(f, Yol(f), label='$Y_{OL}$')
        ax.plot(f, Ycl_pred, '--k', label='$Y_{CL}$ (predicted)')
        ax.plot(f, Ycl(f), 'r', label='$Y_{CL}$ (actual)')
        ax.set_xlim(f.min(), 1.5)
        ax.set_title('wsp = {}m/s'.format(wsp))
        ax.legend()

        if SAVE:
            plt.savefig(
                '../Figures/{}/{}_TipDeflection_Spectrum_{}.png'.format(
                    c, c, wsp),
                dpi=200)
        plt.show()
        print()

        for f in fnp:
            pred = abs(signal.freqresp(system.S,
                                       f * 2 * np.pi)[1][0]) * 100 - 100
            act = Ycl(f) / Yol(f) * 100 - 100
            print('{:2.2f}%, {:2.2f}%'.format(pred, act))
def run(dlc=None, dlc_noipc=None, SAVE=None):
    f = np.linspace(0, 1.5, 1000)[1:]

    Yol = OLResponse.Response(18)
    Ycl = Spectrum(dlc(wsp=18, controller='ipcpi')[0])
    C = make()
    P = BladeModel.Blade(18)
    sys = ControlDesign.Turbine(P, C)
    mag = signal.bode(sys.S, w=f * (2 * np.pi))[1]
    #actualMag = 20*np.log10(Ycl(f)/Yol(f))

    w, H = signal.freqresp(sys.S, n=100000)
    f = w / (2 * np.pi)
    Ycl_pred = abs(H) * Yol(f)

    fig, ax = ControllerEvaluation.magplotSetup(F1p=0.16)
    ax.set_xlim(0.05, 1.5)

    ax.axhline(0, lw=1, c='0.8', ls='-')

    ax.plot(f, Yol(f), label='Open loop')
    ax.plot(f, Ycl_pred, '--k', label='Closed loop (linear)')
    ax.plot(f, Ycl(f), 'r', label='Closed loop (HAWC2)')

    #ax.plot(f, mag, label='$S(C_{PI})$, linear model')
    #ax.plot(f, actualMag, '--', label='$S(C_{PI})$, HAWC2 model')

    ax.set_ylabel('Magnitude [m]')
    ax.set_xlim(0.05, 1.5)
    ax.set_ylim(0.01, 0.4)
    ax.set_yscale('log')
    ax.legend(loc='upper right')

    if SAVE:
        plt.savefig(SAVE, dpi=200, bbox_inches='tight')
    plt.show()
    print()
# -*- coding: utf-8 -*-
"""
Created on Sat Jun  9 15:36:45 2018

@author: J
"""

import numpy as np
from Modelling import BladeModel

BS = ['b_1', 'b_2', 'b_3', 'b_4']
AS = ['a_2', 'a_3', 'a_4', 'a_5']

temp = ''' \\rule{0pt}{4ex}  wsp & \\( \\frac{b_1s^3 + b_2s^2 + b_3s + b_4}{s^4 + a_2s^3 + a_3s^2 + a_4s + a_5} \\)  \\\\ \\hline'''
WSP = np.arange(4, 27, 2)
models = BladeModel.make()

for m in models:
    s = temp
    toreplace = dict(zip(BS, [f'{x:2.4f}' for x in m.b]))

    s = s.replace('wsp', str(m.wsp))
    for x, y in toreplace.items():
        s = s.replace(x, y)

    toreplace = dict(zip(AS, [f'{x:2.4f}' for x in m.a[1:]]))
    for x, y in toreplace.items():
        s = s.replace(x, y)
    print(s)
Exemplo n.º 12
0
def run(dlc, dlc_noipc, SAVE=False):

    F1p = 0.16
    wsp = 18
    C_names = ['ipc04', 'ipc09', 'ipc10', 'ipc11']
    C_labels = [
        '$f_{1p}$ Control', '$f_{2p}$ Control', '$f_{3p}$ Control',
        '$f_{4p}$ Control'
    ]
    C_generators = [IPC04.make, IPC09.make, IPC10.make, IPC11.make]

    fig, axes = plt.subplots(2, 2, sharey=True, figsize=[7, 5])
    plt.subplots_adjust(wspace=0.05, hspace=0.05)
    for c, c_func, ax, label in zip(C_names, C_generators, axes.ravel(),
                                    C_labels):
        # Load transfer functions
        C = c_func()
        P = BladeModel.Blade(wsp)
        Yol = OLResponse.Response(wsp)

        # Calculate predicted output spectrum
        system = ControlDesign.Turbine(P, C)
        w, H = signal.freqresp(system.S)
        f = w / (2 * np.pi)
        Ycl_pred = abs(H) * Yol(f)

        # Load close loop output spectrum
        Sim = dlc(yaw=0, wsp=wsp, controller=c, Kp=-1)[0]
        Ycl = Spectrum(Sim)

        ax.plot(f, Yol(f), label='OL')
        ax.plot(f, Ycl_pred, '--k', label='CL (linear)')
        ax.plot(f, Ycl(f), 'r', label='CL (HAWC2)')

        # axis
        ax.set_xscale('log')
        ax.set_xlim(0.05, 1.5)
        ax.set_ylim(0.01, 1)

        # ticks
        ax.set_xticks([F1p, 2 * F1p, 3 * F1p, 4 * F1p], minor=True)
        ax.grid(axis='x', which='minor')

        # annotate
        ax.annotate(label,
                    xy=(0.05, 0.96),
                    xycoords='axes fraction',
                    size=12,
                    ha='left',
                    va='top',
                    bbox=dict(boxstyle='round', fc='w', alpha=0.0))
    # axis
    ax.set_yscale('log')
    ax.set_ylim(0.01, 1)

    # ticks
    axes[0, 0].set_xticklabels([])
    axes[0, 1].set_xticklabels([])
    axes[1,
         0].set_xticklabels(['$f_{1p}$', '$f_{2p}$', '$f_{3p}$', '$f_{4p}$'],
                            minor=True)
    axes[1,
         1].set_xticklabels(['$f_{1p}$', '$f_{2p}$', '$f_{3p}$', '$f_{4p}$'],
                            minor=True)

    # labels
    fig.text(0.05, 0.5, 'Magnitude [m]', va='center', rotation='vertical')
    fig.text(0.5, 0.05, 'Frequency [Hz]', ha='center', rotation='horizontal')

    #axes[1, 1].legend(loc='lower left')
    axes[1, 1].legend()
    if SAVE:
        plt.savefig(SAVE, dpi=200, bbox_inches='tight')
    plt.show()
    print()

    # print some results
    fnp = 0.16 * np.array([1, 2, 3, 4])
    for f in fnp:
        pred = abs(signal.freqresp(system.S, f * 2 * np.pi)[1][0]) * 100 - 100
        act = Ycl(f) / Yol(f) * 100 - 100
        print('{:2.2f}%, {:2.2f}%'.format(pred, act))
Exemplo n.º 13
0
from Modelling import BladeModel

#from Controllers import ControllerEvaluation


def make(Kp=0.015, Ti=1):

    controller = ControlDesign.Controller2(Ts=0.01)

    controller.addZero(-1 / Ti)
    controller.addPole(0)
    controller.K = Kp

    return controller.tf


if __name__ == '__main__':
    wsp = 18
    f1p = 0.16  # hz

    P = BladeModel.Blade(wsp)
    C = make(0.0142, 1.0)  # Todo. make this controller sm >= 0.6
    sys = ControlDesign.Turbine(P, C)

    # stability margin
    print('Sm: {:2.3f}\n'.format(sys.sm))

    # performance at f1p to f4p
    for i, perf in enumerate(sys.performance(f1p)):
        print('f{}p: {:+.2f}%'.format(i + 1, perf * 100))