%%
%
% Design of Traction Control System with H inf
%
% (c)
%
clc
%clear all
close all
%%
% Design of nominal plant of Motor and Gear
%
% open_system('Design_of_nominal_plant_for_Motor_and_Gear')
% I_O = getlinio(gcs);
% NP_sys=linearize(gcs,I_O);
% save NPMGsys NP_sys
% close_system('Design_of_nominal_plant_for_Motor_and_Gear')
%
load NPMGsys
%%
% Frequency width
%
w = logspace(-1, 4, 1000);
%%
% Define of plant of Motor and Gear
%
Ap = NP_sys.a;
Bp = NP_sys.b;
Cp = NP_sys.c;
Dp = NP_sys.d;
Gnpl= pck(Ap, Bp, Cp, Dp);
%
% Calculation of complex frequency response
%
%Gs_pl= frsp(Gnpl, w);
%
% Checking for frequency response of plant
%
%figure
%vplot('bode', Gs_pl)
%%
% Define Weight
%
%
% Define of Ws
%
NUM_Ws = [0.1 10];
DEN_Ws = [10 1];
%
Ws_gain = 10;
%
Ws = nd2sys(NUM_Ws, DEN_Ws, Ws_gain);
%
% Define of Wt
%
NUM_Wt = [1 0.1];
DEN_Wt = [1 10000];
%
Wt_gain = 1;
%
Wt = nd2sys(NUM_Wt, DEN_Wt, Wt_gain);
%
% Define of Wn
%
%Wn = 1.0;
%
% Calculation of complex frequency response
%
Gs_Ws = frsp(Ws, w);
Gs_Wt = frsp(Wt, w);
%
% Checking for frequency response of weight
%
figure
vplot('liv,lm', Gs_Ws,'-', Gs_Wt, '--');
xlabel('Freqency [rad/s]')
ylabel('Gain')
legend('Ws','Wt')
%%
% Define General Plant
%
systemnames = 'Gnpl Ws Wt';
inputvar = '[dist; control]';
outputvar = '[Wt; Ws; Gnpl + dist]';
input_to_Gnpl = '[control]';
input_to_Ws = '[Gnpl + dist]';
input_to_Wt = '[control]';
sysoutname = 'G';
cleanupsysic = 'yes';
sysic;
%
% Extension
%
% systemnames = 'Gnpl Ws Wt Wn';
% inputvar = '[noise; dist; control]';
% outputvar = '[Wt; Ws; Gnpl + Wn]';
% input_to_Gnpl = '[control + dist]';
% input_to_Ws = '[Gnpl + Wn]';
% input_to_Wt = '[control]';
% input_to_Wn = '[noise]';
% sysoutname = 'G';
% cleanupsysic = 'yes';
% sysic;
%
%%
% Calculation of H inf controller gain
%
K = hinfsyn(G, 1, 1, 0, 100, 0.01, 2);
%
% Calculation of complex frequency response
%
% Gs_K = frsp(K, w);
%
% Checking for frequency response of controller
%
% figure
% vplot('liv,lm', Gs_K)
% xlabel('Freqency [rad/s]')
% ylabel('Gain')
%
% figure
% vplot('liv,p', Gs_K)
% xlabel('Freqency [rad/s]')
% ylabel('Phase [deg]')
%
% figure
% vplot('liv,lm', Gs_K,'-', Gs_pl, '--');
% xlabel('Freqency [rad/s]')
% ylabel('Gain')
% legend('K','Pr')
%
%%
% Conversion to discrete Nominal plant and H inf controller gain
%
ts = 0.01;
%
% Conversion to discrete Nominal plant
%
syscPL = ss(Ap, Bp, Cp, Dp);
sysdPL = c2d(syscPL, ts);
[AdPL, BdPL, CdPL, DdPL]=ssdata(sysdPL);
%
% Conversion to discrete H inf controller gain
%
[AcHic, BcHic, CcHic, DcHic]=unpck(K);
syscHic=ss(AcHic, BcHic, CcHic, DcHic);
sysdHic=c2d(syscHic, ts);
[tcs2HiA, tcs2HiB, tcs2HiC, tcs2HiD] = ssdata(sysdHic);
% save('../../nxtGTHi_1_Environment/tcs2FB',...
% 'tcs2HiA','tcs2HiB', 'tcs2HiC', 'tcs2HiD')
%%
%
% Checking on the Simulink model.
%
open_system('TCS2')
sim('TCS2')
%%
% EOF