Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
7408_ТрусоваЕС_КурсоваяРабота(1).docx
Скачиваний:
75
Добавлен:
10.02.2022
Размер:
1.59 Mб
Скачать

Список использованных источников

Математическое моделирование системы управления: методич. указания к курсовому проектированию / сост.: О. Ю. Лукомская, А. Г. Шпекторов. СПб.: Изд-во СПбГЭТУ «ЛЭТИ», 2014. 40 с.

Приложение Программная реализация

classdef app12 < matlab.apps.AppBase

% Properties that correspond to app components

properties (Access = public)

UIFigure matlab.ui.Figure

ShipChoice matlab.ui.container.ButtonGroup

NVK matlab.ui.control.RadioButton

Kater matlab.ui.control.RadioButton

KPK matlab.ui.control.RadioButton

Start matlab.ui.control.Button

Exit matlab.ui.control.Button

ShipParameters matlab.ui.container.Panel

Label matlab.ui.control.Label

Label_4 matlab.ui.control.Label

Edit_V1max matlab.ui.control.NumericEditField

Label_3 matlab.ui.control.Label

Edit_Vk matlab.ui.control.NumericEditField

Label_5 matlab.ui.control.Label

Edit_Vmax matlab.ui.control.NumericEditField

EditField_2Label matlab.ui.control.Label

Edit_N matlab.ui.control.NumericEditField

EditFieldLabel matlab.ui.control.Label

Edit_W matlab.ui.control.NumericEditField

RegulatorPanel matlab.ui.container.Panel

Label_6 matlab.ui.control.Label

Label_7 matlab.ui.control.Label

Label_8 matlab.ui.control.Label

V_reg matlab.ui.control.StateButton

x0EditFieldLabel matlab.ui.control.Label

Edit_X0 matlab.ui.control.NumericEditField

v0EditFieldLabel matlab.ui.control.Label

Edit_V0 matlab.ui.control.NumericEditField

dtEditFieldLabel matlab.ui.control.Label

Edit_dt matlab.ui.control.NumericEditField

Label_10 matlab.ui.control.Label

Edit_Vdesirable matlab.ui.control.NumericEditField

Label_9 matlab.ui.control.Label

Slider matlab.ui.control.Slider

Label_11 matlab.ui.control.Label

Edit_Trazg matlab.ui.control.NumericEditField

Label_12 matlab.ui.control.Label

Edit_Ttorm matlab.ui.control.NumericEditField

Lamp matlab.ui.control.Lamp

Graph_X matlab.ui.control.UIAxes

Graph_V matlab.ui.control.UIAxes

Graph_P matlab.ui.control.UIAxes

end

% Callbacks that handle component events

methods (Access = private)

% Selection changed function: ShipChoice

function ShipChoiceSelectionChanged(app, event)

selectedButton = app.ShipChoice.SelectedObject;

if app.NVK.Value == 1

app.Kater.Value = 0;

app.KPK.Value = 0;

app.Edit_W.Value = 1552;

app.Edit_N.Value = 26000;

app.Edit_Vmax.Value = 27;

app.Edit_Vk.Visible = 'off';app.Label_3.Visible = 'off';

app.Edit_V1max.Visible = 'off';app.Label_4.Visible = 'off';

end

if app.Kater.Value == 1

app.NVK.Value = 0;

app.KPK.Value = 0;

app.Edit_W.Value = 11;

app.Edit_N.Value = 100;

app.Edit_Vmax.Value = 9.5;

app.Edit_Vk.Visible = 'off';app.Label_3.Visible = 'off';

app.Edit_V1max.Visible = 'off';app.Label_4.Visible = 'off';

end

if app.KPK.Value == 1

app.Kater.Value = 0;

app.NVK.Value = 0;

app.Edit_W.Value = 22.5;

app.Edit_N.Value = 900;

app.Edit_Vmax.Value = 30;

app.Edit_Vk.Value = 9.8;

app.Edit_V1max.Value = 11.8;

app.Edit_Vk.Visible = 'on';app.Label_3.Visible = 'on';

app.Edit_V1max.Visible = 'on';app.Label_4.Visible = 'on';

end

end

% Value changed function: Slider

function P_Slider(app, event)

value = app.Slider.Value;

end

% Button pushed function: Start

function Start_Button(app, event)

% Надводное судно "Жаркий"

if app.NVK.Value == 1 && app.Kater.Value == 0 && app.KPK.Value == 0

% параметры заданного судна "Жаркий"

W=app.Edit_W.Value; %водоизмещение в тоннах

N=app.Edit_N.Value; %мощность ГЭУ в лс

v=app.Edit_Vmax.Value; %скорость в узлах

per=1852/3600;

% перевод в систему СИ

M=1000*W; %масса корабля

Nmax=735.5*N;

vmax=per*v;

Fmax=Nmax/vmax; %максимальная сила тяги движителя

dFmax=0.05*Fmax; %допустимое изменение силы тяги

dt=2; %время моделирования для НВК

app.Edit_dt.Value=dt;

dP=dt*(dFmax/Fmax)*100; %относительное допустимое изменение силы тяги

A=Fmax/(vmax^2);

time = []; % моменты времени

x = []; % пройденное расстояние

vv = []; % развитая скорость

p = []; % относительная сила тяги

% начальные условия

t = 0;

P = 0;

xi = 0;

x_pred = app.Edit_X0.Value;

v_sled = app.Edit_V0.Value;

PP=app.Slider.Value;

Trazg = app.Edit_Trazg.Value;

Ttorm = app.Edit_Ttorm.Value;

Tsum = Trazg+Ttorm;

vn=app.Edit_Vdesirable.Value*per;

kp=0.25;

app.Lamp.Visible = 'off';

for t= 0:dt:Tsum

x_sled=xi+(xi-x_pred)+(P*Fmax*(dt^2)/100-A*(xi-x_pred)*abs(xi-x_pred))/M;

v_sled=(x_sled-xi)/dt;

vv=[vv,v_sled];

p=[p,P];

x_pred=xi; xi=x_sled;

% Пропорциональный регулятор скорости

if app.V_reg.Value == 1

PP=100;

app.Slider.Visible = 'off';

app.Label_9.Text = '';

dP=-kp*(v_sled-vn);

if t<Trazg

P = P+dP;

if v_sled>=vn

v_sled=vn;

end

if vn>=vmax

app.Lamp.Visible = 'on';

end

end

% без регулирования скорости

else

dP=dt*(dFmax/Fmax)*100;

app.Slider.Visible = 'on';

end

if t<Trazg

P = P+dP;

if P>=PP

P=PP;

end

end

if t>=Trazg

P = P-dP;

if P<=-PP

P=-PP;

end

end

time=[time,t];

x=[x,x_sled];

t=t+dt;

end

plot(app.Graph_X,time,x,'Color','m',"LineWidth",1.5);grid on;

plot(app.Graph_V,time,vv,'Color','m',"LineWidth",1.5);grid on;

plot(app.Graph_P,time,p,'Color','m',"LineWidth",1.5);grid on;

% Большой рабочий катер

elseif app.NVK.Value == 0 && app.Kater.Value == 1 && app.KPK.Value == 0

% параметры заданного судна

W=app.Edit_W.Value; %водоизмещение в тоннах

N=app.Edit_N.Value; %мощность ГЭУ в лс

v=app.Edit_Vmax.Value;

per=1852/3600;

PP=app.Slider.Value;

% перевод в систему СИ

M=1000*W %масса катера

Nmax=735.5*N

vmax=v*per

Fmax=Nmax/vmax %максимальная сила тяги движителя

dFmax=0.2*Fmax %допустимое изменение силы тяги

dt=1;

app.Edit_dt.Value=dt;

dP=dt*(dFmax/Fmax)*100 %относительное допустимое изменение силы тяги

A=Fmax/(vmax^2)

time = []; % моменты времени

x = []; % пройденное расстояние

vv = []; % развитая скорость

p = []; % относительна сила тяги

% начальные условия

t = 0;

P = 0;

xi = 0;

x_pred = app.Edit_X0.Value;

v_sled = app.Edit_V0.Value;

PP=app.Slider.Value;

Trazg = app.Edit_Trazg.Value;

Ttorm = app.Edit_Ttorm.Value;

Tsum = Trazg+Ttorm;

vn=app.Edit_Vdesirable.Value*per;

kp=10;

app.Lamp.Visible = 'off';

for t= 0:dt:Tsum

x_sled=xi+(xi-x_pred)+(P*Fmax*(dt^2)/100-A*(xi-x_pred)*abs(xi-x_pred))/M;

v_sled=(x_sled-xi)/dt;

vv=[vv,v_sled];

p=[p,P];

x_pred=xi; xi=x_sled;

% пропорциональный регулятор скорости

if app.V_reg.Value == 1

PP=100;

app.Slider.Visible = 'off';

app.Label_9.Text = '';

dP=-kp*(v_sled-vn);

if t<Trazg

P = P+dP;

if v_sled>=vn

v_sled=vn;

end

if vn>=vmax

app.Lamp.Visible = 'on';

end

end

% без регулирования скорости

else

dP=dt*(dFmax/Fmax)*100;

app.Slider.Visible = 'on';

end

if t<Trazg

P = P+dP;

if P>=PP

P=PP;

end

end

if t>=Trazg

P = P-dP;

if P<=-PP

P=-PP;

end

end

time=[time,t];

x=[x,x_sled];

t=t+dt;

end

plot(app.Graph_X,time,x,'Color','m',"LineWidth",1.5);grid on;

plot(app.Graph_V,time,vv,'Color','m',"LineWidth",1.5);grid on;

plot(app.Graph_P,time,p,'Color','m',"LineWidth",1.5);grid on;

% Судно на подводных крыльях

elseif app.NVK.Value == 0 && app.Kater.Value == 0 && app.KPK.Value == 1

% параметры заданного судна

W=app.Edit_W.Value; %водоизмещение в тоннах

N=app.Edit_N.Value; %мощность ГЭУ в лс

v=app.Edit_Vmax.Value; %максимальная скорость

v1=app.Edit_Vk.Value; %скорость перехода в режим глиссирования

v2=app.Edit_V1max.Value; %скорость перехода на крылья

per=1852/3600;

% перевод в систему СИ

M=1000*W %масса катера

Nmax=735.5*N;

vk=per*v1; %скорость начала глиссирования

v1max=per*v2; %скорость выхода на крылья

v2max=per*v;

Fmax=Nmax/v; %максимальная сила тяги движителя

dFmax=0.1*Fmax; %допустимое изменение силы тяги

dt=1;

app.Edit_dt.Value=dt; %шаг моделирования

dP=dt*(dFmax/Fmax)*100 %относительное допустимое изменение силы тяги за время равное 1с

A1=Fmax/(v1max^2)

A2=Fmax/(v2max^2)

time = []; % моменты времени

x = []; % пройденное расстояние

vv = []; % развитая скорость

p = []; % относительна сила тяги

% начальные условия

t = 0;

P = 0;

xi = 0;

x_pred = app.Edit_X0.Value;

v_sled = app.Edit_V0.Value;

PP=app.Slider.Value;

Trazg = app.Edit_Trazg.Value;

Ttorm = app.Edit_Ttorm.Value;

Tsum = Trazg+Ttorm;

vn=app.Edit_Vdesirable.Value*per;

kp=5;

app.Lamp.Visible = 'off';

for t= 0:dt:Tsum

if v_sled<vk

x_sled=xi+(xi-x_pred)+(P*Fmax*(dt^2)/100-A1*(xi-x_pred)*abs(xi-x_pred))/M;

v_sled=(x_sled-xi)/dt;

end

if v_sled>=vk

x_sled=xi+(xi-x_pred)+(P*Fmax*(dt^2)/100-A2*(xi-x_pred)*abs(xi-x_pred))/M;

v_sled=(x_sled-xi)/dt;

end

vv=[vv,v_sled];

p=[p,P];

x_pred=xi; xi=x_sled;

% Пропорциональный регулятор скорости

if app.V_reg.Value == 1

PP=100;

app.Slider.Visible = 'off';

app.Label_9.Text = '';

dP=-kp*(v_sled-vn);

if t<Trazg

P = P+dP;

if v_sled>=vn

v_sled=vn;

end

if vn>=v2max

app.Lamp.Visible = 'on';

end

end

% без регулирования скорости

else

dP=dt*(dFmax/Fmax)*100;

app.Slider.Visible = 'on';

end

if t<Trazg

P = P+dP;

if P>=PP

P=PP;

end

end

if t>=Trazg

P = P-dP;

if P<=-PP

P=-PP;

end

end

time=[time,t];

x=[x,x_sled];

t=t+dt;

end

end

plot(app.Graph_X,time,x,'Color','m',"LineWidth",1.5);grid on;

plot(app.Graph_V,time,vv,'Color','m',"LineWidth",1.5);grid on;

plot(app.Graph_P,time,p,'Color','m',"LineWidth",1.5);grid on;

end

% Button pushed function: Exit

function Exit_Button(app, event)

close(app.UIFigure)

end

% Value changed function: V_reg

function V_reg_Value(app, event)

value = app.V_reg.Value;

end

end

% Component initialization

methods (Access = private)

% Create UIFigure and components

function createComponents(app)

% Create UIFigure and hide until all components are created

app.UIFigure = uifigure('Visible', 'off');

app.UIFigure.Position = [100 100 926 657];

app.UIFigure.Name = 'UI Figure';

% Create ShipChoice

app.ShipChoice = uibuttongroup(app.UIFigure);

app.ShipChoice.SelectionChangedFcn = createCallbackFcn(app, @ShipChoiceSelectionChanged, true);

app.ShipChoice.TitlePosition = 'centertop';

app.ShipChoice.Title = 'Выбор судна';

app.ShipChoice.Position = [21 490 122 98];

% Create NVK

app.NVK = uiradiobutton(app.ShipChoice);

app.NVK.Text = 'НВК';

app.NVK.Position = [11 52 58 22];

app.NVK.Value = true;

% Create Kater

app.Kater = uiradiobutton(app.ShipChoice);

app.Kater.Text = 'Катер';

app.Kater.Position = [11 30 65 22];

% Create KPK

app.KPK = uiradiobutton(app.ShipChoice);

app.KPK.Text = 'КПК';

app.KPK.Position = [11 8 65 22];

% Create Start

app.Start = uibutton(app.UIFigure, 'push');

app.Start.ButtonPushedFcn = createCallbackFcn(app, @Start_Button, true);

app.Start.BackgroundColor = [0.9608 0.5176 0.6];

app.Start.FontSize = 16;

app.Start.FontWeight = 'bold';

app.Start.Position = [171 598 110 40];

app.Start.Text = 'Старт';

% Create Exit

app.Exit = uibutton(app.UIFigure, 'push');

app.Exit.ButtonPushedFcn = createCallbackFcn(app, @Exit_Button, true);

app.Exit.BackgroundColor = [0.9804 0.5961 0.5961];

app.Exit.FontSize = 16;

app.Exit.FontWeight = 'bold';

app.Exit.Position = [171 28 110 40];

app.Exit.Text = 'Выход';

% Create ShipParameters

app.ShipParameters = uipanel(app.UIFigure);

app.ShipParameters.Position = [161 368 252 220];

% Create Label

app.Label = uilabel(app.ShipParameters);

app.Label.FontSize = 14;

app.Label.FontWeight = 'bold';

app.Label.Position = [80 187 129 22];

app.Label.Text = 'Параметры судна';

% Create Label_4

app.Label_4 = uilabel(app.ShipParameters);

app.Label_4.Position = [21 11 190 28];

app.Label_4.Text = {'Скорость перехода'; 'на крылья, уз'};

% Create Edit_V1max

app.Edit_V1max = uieditfield(app.ShipParameters, 'numeric');

app.Edit_V1max.Editable = 'off';

app.Edit_V1max.Position = [169 7 65 22];

% Create Label_3

app.Label_3 = uilabel(app.ShipParameters);

app.Label_3.Position = [21 46 190 28];

app.Label_3.Text = {'Скорость перехода в'; 'режим глиссирования, уз'};

% Create Edit_Vk

app.Edit_Vk = uieditfield(app.ShipParameters, 'numeric');

app.Edit_Vk.Editable = 'off';

app.Edit_Vk.Position = [169 44 65 22];

% Create Label_5

app.Label_5 = uilabel(app.ShipParameters);

app.Label_5.Position = [21 81 190 28];

app.Label_5.Text = {'Максимальная'; 'скорость, уз'};

% Create Edit_Vmax

app.Edit_Vmax = uieditfield(app.ShipParameters, 'numeric');

app.Edit_Vmax.Editable = 'off';

app.Edit_Vmax.Position = [169 81 65 22];

% Create EditField_2Label

app.EditField_2Label = uilabel(app.ShipParameters);

app.EditField_2Label.Position = [21 116 190 28];

app.EditField_2Label.Text = 'Мощность ГЭУ, л.с.';

% Create Edit_N

app.Edit_N = uieditfield(app.ShipParameters, 'numeric');

app.Edit_N.ValueDisplayFormat = '%.0f';

app.Edit_N.Editable = 'off';

app.Edit_N.Position = [169 119 65 22];

% Create EditFieldLabel

app.EditFieldLabel = uilabel(app.ShipParameters);

app.EditFieldLabel.Position = [21 151 190 28];

app.EditFieldLabel.Text = 'Водоизмещение, т';

% Create Edit_W

app.Edit_W = uieditfield(app.ShipParameters, 'numeric');

app.Edit_W.Editable = 'off';

app.Edit_W.Position = [169 154 65 22];

% Create RegulatorPanel

app.RegulatorPanel = uipanel(app.UIFigure);

app.RegulatorPanel.Position = [21 78 392 291];

% Create Label_6

app.Label_6 = uilabel(app.RegulatorPanel);

app.Label_6.HorizontalAlignment = 'center';

app.Label_6.FontSize = 14;

app.Label_6.FontWeight = 'bold';

app.Label_6.Position = [131 260 144 22];

app.Label_6.Text = 'Панель управления';

% Create Label_7

app.Label_7 = uilabel(app.RegulatorPanel);

app.Label_7.Position = [61 230 117 22];

app.Label_7.Text = 'Начальные условия';

% Create Label_8

app.Label_8 = uilabel(app.RegulatorPanel);

app.Label_8.Position = [61 140 122 22];

app.Label_8.Text = 'Шаг моделирования';

% Create V_reg

app.V_reg = uibutton(app.RegulatorPanel, 'state');

app.V_reg.ValueChangedFcn = createCallbackFcn(app, @V_reg_Value, true);

app.V_reg.Text = 'Регулирование скорости';

app.V_reg.BackgroundColor = [0.4275 0.9294 0.4275];

app.V_reg.Position = [211 222 153 30];

% Create x0EditFieldLabel

app.x0EditFieldLabel = uilabel(app.RegulatorPanel);

app.x0EditFieldLabel.Position = [61 200 33 22];

app.x0EditFieldLabel.Text = 'x0, м';

% Create Edit_X0

app.Edit_X0 = uieditfield(app.RegulatorPanel, 'numeric');

app.Edit_X0.Position = [109 200 72 22];

% Create v0EditFieldLabel

app.v0EditFieldLabel = uilabel(app.RegulatorPanel);

app.v0EditFieldLabel.Position = [61 170 36 22];

app.v0EditFieldLabel.Text = 'v0, уз';

% Create Edit_V0

app.Edit_V0 = uieditfield(app.RegulatorPanel, 'numeric');

app.Edit_V0.Position = [109 170 72 22];

% Create dtEditFieldLabel

app.dtEditFieldLabel = uilabel(app.RegulatorPanel);

app.dtEditFieldLabel.Position = [61 110 28 22];

app.dtEditFieldLabel.Text = 'dt, с';

% Create Edit_dt

app.Edit_dt = uieditfield(app.RegulatorPanel, 'numeric');

app.Edit_dt.Editable = 'off';

app.Edit_dt.Position = [109 110 72 22];

% Create Label_10

app.Label_10 = uilabel(app.RegulatorPanel);

app.Label_10.Position = [220 182 73 28];

app.Label_10.Text = {'Желаемая '; 'скорость, уз'};

% Create Edit_Vdesirable

app.Edit_Vdesirable = uieditfield(app.RegulatorPanel, 'numeric');

app.Edit_Vdesirable.Position = [307 188 67 22];

% Create Label_9

app.Label_9 = uilabel(app.RegulatorPanel);

app.Label_9.HorizontalAlignment = 'right';

app.Label_9.Position = [125 70 147 22];

app.Label_9.Text = 'Относительная сила тяги';

% Create Slider

app.Slider = uislider(app.RegulatorPanel);

app.Slider.ValueChangedFcn = createCallbackFcn(app, @P_Slider, true);

app.Slider.Position = [56 59 285 3];

% Create Label_11

app.Label_11 = uilabel(app.RegulatorPanel);

app.Label_11.Position = [220 141 61 28];

app.Label_11.Text = {'Время '; 'разгона, с'};

% Create Edit_Trazg

app.Edit_Trazg = uieditfield(app.RegulatorPanel, 'numeric');

app.Edit_Trazg.Position = [307 147 67 22];

% Create Label_12

app.Label_12 = uilabel(app.RegulatorPanel);

app.Label_12.Position = [220 105 86 28];

app.Label_12.Text = {'Время'; 'торможения, с'};

% Create Edit_Ttorm

app.Edit_Ttorm = uieditfield(app.RegulatorPanel, 'numeric');

app.Edit_Ttorm.Position = [307 111 67 22];

% Create Lamp

app.Lamp = uilamp(app.RegulatorPanel);

app.Lamp.Position = [351 72 23 23];

app.Lamp.Color = [1 0 0];

% Create Graph_X

app.Graph_X = uiaxes(app.UIFigure);

title(app.Graph_X, 'Расстояние')

xlabel(app.Graph_X, 't, с')

ylabel(app.Graph_X, 'x, м')

app.Graph_X.PlotBoxAspectRatio = [2.28387096774194 1 1];

app.Graph_X.GridLineStyle = '--';

app.Graph_X.XGrid = 'on';

app.Graph_X.XMinorGrid = 'on';

app.Graph_X.YGrid = 'on';

app.Graph_X.YMinorGrid = 'on';

app.Graph_X.Position = [517 433 401 209];

% Create Graph_V

app.Graph_V = uiaxes(app.UIFigure);

title(app.Graph_V, 'Скорость')

xlabel(app.Graph_V, 't, с')

ylabel(app.Graph_V, 'v, м/с')

app.Graph_V.PlotBoxAspectRatio = [2.28387096774194 1 1];

app.Graph_V.XGrid = 'on';

app.Graph_V.XMinorGrid = 'on';

app.Graph_V.YGrid = 'on';

app.Graph_V.YMinorGrid = 'on';

app.Graph_V.Position = [517 228 401 210];

% Create Graph_P

app.Graph_P = uiaxes(app.UIFigure);

title(app.Graph_P, 'Сила тяги')

xlabel(app.Graph_P, 't, с')

ylabel(app.Graph_P, 'P, %')

app.Graph_P.PlotBoxAspectRatio = [2.17177914110429 1 1];

app.Graph_P.XGrid = 'on';

app.Graph_P.XMinorGrid = 'on';

app.Graph_P.YGrid = 'on';

app.Graph_P.YMinorGrid = 'on';

app.Graph_P.Position = [517 3 401 218];

% Show the figure after all components are created

app.UIFigure.Visible = 'on';

end

end

% App creation and deletion

methods (Access = public)

% Construct app

function app = app12

% Create UIFigure and components

createComponents(app)

% Register the app with App Designer

registerApp(app, app.UIFigure)

if nargout == 0

clear app

end

end

% Code that executes before app deletion

function delete(app)

% Delete UIFigure when app is deleted

delete(app.UIFigure)

end

end

end

Соседние файлы в предмете Математическое моделирование объектов и систем управления