echo on;
%KASKADE_struc000 - application of Kaskade.m to example plant struc000.m
%i.e.: three cascaded control loops: BOD/BOD/BOD;
T=1;    %sampling time
SZ=300; %simulation time = number of sampling periods T

% A: >>>definitions for inner control loop (e.g: current control)<<<
%coupling and measuring: zero order sample and hold / mean value
IWS1=2;
%plant: gain / two first-order time delay elements
SP1=tf(1,conv([1.5 1],[8 1]),'Variable','p'),
%controller: BOD PI-type / undelayed input signals / no pole compensation
%for variant "pole compensation": SV=[0 1 0 1 0 0] <--> no: SV=[0 0 0 0 1 0]
s='bod'; SV=[0 1 0 1 0 0]; TV=[T,0,IWS1];
SM1=struct('Optimization',s,'ControlVector',SV,'ControlLoop',TV);
pause %press any key please

% B: >>>definitions for middle control loop (e.g: speed control)<<<
%coupling and measuring: zero order sample and hold / mean value
IWS2=2;
%plant: gain / one first-order time delay element (friction!)
SP2=tf(2/0.01,[20/0.01 1],'Variable','p'),
%controller: BOD PI-type / delayed input signals / no pole compensation
s='bod'; SV=[1 0 0 0 1 0]; TV=[T,0,IWS2];
SM2=struct('Optimization',s,'ControlVector',SV,'ControlLoop',TV);
pause %press any key please

% C: >>>definitions for outer control loop (e.g: positioning)<<<
%coupling and measuring: zero order sample and hold / instantaneous value
IWS3=1;
%plant: one integrator
SP3=tf(1,[50 0],'Variable','p'),
%controller: BOD P-type / undelayed input signals
s='bod'; SV=[0 0 1 0 0 0]; TV=[T,0,IWS3];
SM3=struct('Optimization',s,'ControlVector',SV,'ControlLoop',TV);
pause %press any key please

%calculation of prefilters and controllers:
TOL=sqrt(1e-08);  %Control of minreal.m inside kaskade
                  %result evaluation necessary
[FI11,RE11,FI21,RE21,FI31,RE31]=kaskade(SM1,SP1,SM2,SP2,SM3,SP3,TOL),
FI1=FI11;RE1=RE11;FI2=FI21;RE2=RE21;FI3=FI31;RE3=RE31;
SWA=1; %setpoint step response
SGA=1; SSZ=150; %disturbance variable step response, point in time
KASKADE_struc000s; sim('KASKADE_struc000s',T*SZ);
