% Beregner state-spacemodell for system innlagt Pi-regulatorer

% Initialiserer PI-regulatorene
Kp1=-.5;             %Gain for Reg1(Stripper liq flow <=>Stripper level)
Kp2=-10;             %Gain for Reg2(Reaktor kjølevann flow <=>RKs uttemperatur)
Kp3=-2.5;            %Gain for Reg3(Separator liq flow <=>Separator level)
Kp4=-.25;
Kp5=-.1;

taui1=300/60;        %Integraltid for Reg1
taui2=1/60;          %Integraltid for Reg2
taui3=200/60;        %Integraltid for Reg3
taui4=3;
taui5=200/60;

c1=ss(0,1,Kp1/taui1,Kp1);
c2=ss(0,1,Kp2/taui2,Kp2);
c3=ss(0,1,Kp3/taui3,Kp3);

Cs=inv(Skal_Y)*C;           % Beregner de skalerte matrisene
Ds=inv(Skal_Y)*D*(Skal_U);
Bs=B*(Skal_U);        
As=A;    

csys=[c1 0 0;0 c2 0;0 0 c3];    % state-spacemodell for regulatorene
tesys=ss(As,Bs,Cs,Ds);              % state-spacemodell for prosessen

% state-spacemodell for prosesse:
totsys=feedback(tesys,csys,[8 10 7],[15 21 12],-1);

'totsys'
size(totsys)
[a,b,c,d]=ssdata(totsys);
[AA,BB,CC,DD]=ssdata(csys);
'ss-modellen finner matrisene a,b,c og d'
