Full state feedback controller with I servomechanism
6 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to calculate the gain matrix K for a full state feedback controller with an I servomechanism. The problem in my calculation is, that with the calculated K the steady state error is really big. But the ss-error should be 0 due to the I servomechanism. I also calculated the K with the place() function but this yields to the same result.
Do anybody know any possible reasons for that?
A = [0 1;
-0.05 0.4];
B = [0;
5.886];
C = [1 0];
D = [0];
sys_shifted = ss(A,B,C,D);
%% Transform the System from Continous to Discrete
Ts = 10e-3; % Samplingtime in s
sysd_ol = c2d(sys_shifted,Ts);
%% Define Discrete Poles
% poles for the desired damping ratio and natural frequenzy
p(1) = exp((Realpart + Imagpart*1i)*Ts);
p(2) = exp((Realpart - Imagpart*1i)*Ts);
% pole for the servomechanism
p(3) = exp(-800*Ts); % place somewhere far left on the left half plane
%% Adopte System for Controller and Servomechanism Desgin
A_ol = [sysd_ol.A(1,1) sysd_ol.A(1,2) 0;
sysd_ol.A(2,1) sysd_ol.A(2,2) 0;
-sysd_ol.C(1,1) sysd_ol.C(1,2) 0];
B_ol = [sysd_ol.B(1,1) 0;
sysd_ol.B(2,1) 0;
0 1];
C_ol = [sysd_ol.C(1,1) sysd_ol.C(1,2) 0];
D_ol = [0];
%% Calculate Transform Matrix and calculate the control canonical form
%Determine the system characteristic polynomial
CharPoly = poly(A_ol);
% Extract the a0,a1,a2
a0 = CharPoly(4);
a1 = CharPoly(3);
a2 = CharPoly(2);
% Creat inverse Controllability matrix
Pinv_ccf = [a1 a2 1;
a2 1 0;
1 0 0];
% Calculate Transform Matrix
P = [B_ol(:,1) A_ol*B_ol(:,1) A_ol^2*B_ol(:,1)];
Tccf = P * Pinv_ccf;
% Calculate Accf, Bccf, Cccf, Dccf
Accf = inv(Tccf)*A_ol*Tccf;
Bccf = inv(Tccf)*B_ol;
Cccf = C_ol * Tccf;
Dccf = D_ol;
%% Calculate The Alphas
ppoly = poly(p);
alpha0 = ppoly(4);
alpha1 = ppoly(3);
alpha2 = ppoly(2);
%% Calculate Kccf and K
Kccf = [alpha0-a0 alpha1-a1 alpha2-a2];
K_all = Kccf*inv(Tccf);
%% System for Full State Feedback with Servomechanism
A_cl = A_ol - B_ol(:,1) * K_all;
sysc_fsf = ss(A_cl,B_ol(:,2),C_ol,D_ol,Ts);
0 件のコメント
回答 (1 件)
Pavl M.
2024 年 12 月 5 日
編集済み: Pavl M.
2024 年 12 月 6 日
% Answer, full results - stable, minimum phase, proper closed loop system created
clc
clear all
close all
A = [0 1;
-0.05 0.4];
B = [0;
5.886];
C = [1 0];
D = [0];
sys_shifted = ss(A,B,C,D);
%% Transform the System from Continous to Discrete
Ts = 10e-3; % Samplingtime in s
sysd_ol = c2d(sys_shifted,Ts);
%% Define Discrete Poles
Realpart = 1000;
Imagpart = 2000;
% poles for the desired damping ratio and natural frequenzy
p(1) = exp((Realpart + Imagpart*1i)*Ts);
p(2) = exp((Realpart - Imagpart*1i)*Ts);
% pole for the servomechanism
p(3) = exp(-800*Ts); % place somewhere far left on the left half plane
%% Adopte System for Controller and Servomechanism Desgin
A_ol = [sysd_ol.A(1,1) sysd_ol.A(1,2) 0;
sysd_ol.A(2,1) sysd_ol.A(2,2) 0;
-sysd_ol.C(1,1) sysd_ol.C(1,2) 0];
B_ol = [sysd_ol.B(1,1) 0;
sysd_ol.B(2,1) 0;
0 1];
C_ol = [sysd_ol.C(1,1) sysd_ol.C(1,2) 0];
D_ol = [0];
%% Calculate Transform Matrix and calculate the control canonical form
%Determine the system characteristic polynomial
CharPoly = poly(A_ol);
% Extract the a0,a1,a2
a0 = CharPoly(4);
a1 = CharPoly(3);
a2 = CharPoly(2);
% Creat inverse Controllability matrix
Pinv_ccf = [a1 a2 1;
a2 1 0;
1 0 0];
% Calculate Transform Matrix
P = [B_ol(:,1) A_ol*B_ol(:,1) A_ol^2*B_ol(:,1)];
Tccf = P * Pinv_ccf;
% Calculate Accf, Bccf, Cccf, Dccf
Accf = inv(Tccf)*A_ol*Tccf;
Bccf = inv(Tccf)*B_ol;
Cccf = C_ol * Tccf;
Dccf = D_ol;
%% Calculate The Alphas
ppoly = poly(p);
alpha0 = ppoly(4);
alpha1 = ppoly(3);
alpha2 = ppoly(2);
%% Calculate Kccf and K
Kccf = [alpha0-a0 alpha1-a1 alpha2-a2];
K_all = Kccf*inv(Tccf);
%% System for Full State Feedback with Servomechanism
A_cl = A_ol - B_ol(:,1) * K_all;
sysc_fsf = ss(A_cl,B_ol(:,2),C_ol,D_ol,Ts);
figure
step(sysc_fsf,[0 5])
title('System in question before treatment')
res_agent = sysc_fsf
figure
w = logspace(2,6,1000);
bode(res_agent,w),grid
figure
rlocus(res_agent)
figure
nyquist(res_agent)
figure
nichols(res_agent)
Gcc = minreal(res_agent)
ms = minreal(Gcc);
zms = zero(ms) % closed-loop zeros
pms = pole(ms) % closed-loop poles
tsim = 1;
setpointamp = 1; %
setpointapptime = 0.001; %
defaultsetpointpos = 0; %
Conf = RespConfig(Bias=defaultsetpointpos,Amplitude=setpointamp,Delay=setpointapptime)
[wngcc,zetagcc,pgcc] = damp(Gcc)
sigma(Gcc)
margin(Gcc)
diskmargin(Gcc)
stepinfo(Gcc)
disp('Whether the system is stable, minimum phase and proper:')
isstable(Gcc)
isminphase(tfdata(tf(Gcc),'v'))
isproper(Gcc)
Qc= ctrb(A,B)
controllab = rank(Qc)
hasdelay(Gcc)
tdc3 = totaldelay(Gcc)
sysndc3 = absorbDelay(Gcc)
isallpass(tfdata(tf(Gcc),'v'))
% Stabilizing:
asys = ss(A,B,C,D)
opt2 = c2dOptions('Method','tustin','ThiranOrder',3,'DelayModeling','state');
dsys=c2d(asys,Ts,opt2)
nstates = 2
% observer model
%poles_obsv = exp(Ts*[-700 -310 -100 -90]);
poles_obsv = [-700 -310];
L=place(asys.a',asys.c',poles_obsv);
L=L';
Ah = asys.A;
bh = [asys.B L];
%cTh = eye(nstates);
%dh = [0 0;0 0;0 0;0 0];
%asysh=ss(Ah,bh,cTh,dh);
%figure
%step(asysh)
%add a state variable for the integral of the output error. This has the effect of adding an integral term to our controller which is known to reduce steady-state error.
%model for integral action
Ai = [[asys.A zeros(nstates,1)];-asys.C 0];
bi = [asys.B;0];
br = [zeros(nstates,1);1];
ci = [asys.C 0];
di = [0];
asysi=ss(Ai,bi,ci,di);
%Other augmentation scheme:
% Plant augmentation
Aaug=[asys.A zeros(nstates,1); zeros(1,nstates+1)];
Aaug(nstates+1,nstates)=1;
Baug=[asys.B;0];
Caug=eye(nstates+1);
Daug=zeros(nstates+1,1);
Plantcs=ss(Aaug,Baug,Caug,Daug);
% feedback controller
p1 = -800 + 800i;
p2 = -800 - 800i;
p3 = -400 - 400i;
%p1 = -110;
%p2 = -310;
%p3 = -500;
p4 = -400 + 400i;
p5 = -90;
%poles_k = exp(Ts*[p1 p2 p3 p4 p5]);
poles_k = [p1 p2 500];
K = place(asysi.a,asysi.b,poles_k)
Ko = place(asys.A,asys.B,[p1 p2])
s4 = size(asys.A,1);
Z = [zeros([1,s4]) 1];
N = (1\([asys.A,asys.B;asys.C,asys.D]))*Z';
Nx = N(1:s4);
Nu = N(s4+1);
Nbar=Nu + Ko*Nx
%observer design:
At = [ asys.A-asys.B*Ko asys.B*Ko
zeros(size(asys.A)) asys.A-L*asys.C ];
Bt = [ asys.B*Nbar
zeros(size(asys.B)) ];
Ct = [ asys.C zeros(size(asys.C)) ];
%If you'd like to eliminate steady state error as much use Nbar:
% compute Nbar
%poles_k_d = exp(Ts.*poles_k)
%K_d = place(dsysi.a,dsysi.b,poles_k_d)
Ki=K(nstates+1);
K=K(1:nstates);
s4 = size(asys.A,1);
Z = [zeros([1,s4]) 1];
N = (1\([asys.A,asys.B;asys.C,asys.D]))*Z';
Nx = N(1:s4);
Nu = N(s4+1);
Nbarq=Nu + K*Nx
%Well performing (adjusted) system:
syso = ss(At,Bt,Ct,0);
isstable(syso)
syso2 = minreal(syso)
%isminphase(syso)
f = 3;
t = 0:Ts:f;
figure
step(syso2,[0 f])
title('Continuous after treatment With observer flat(cold) start')
sysod = c2d(syso2,Ts,opt2)
Ge = minreal(sysod)
[b3, a3] = ss2tf(Ge.A,Ge.B,Ge.C,Ge.D)
Gest33 = tf(b3,a3,Ts) %discrete model
G = Ge
DM = diskmargin(G)
%[MS, WS] = sensitivity(G)
% L2 = ... your control system
figure
diskmarginplot(G)
title('After control')
figure
clf, nyquist(G), hold all;
diskmarginplot(DM.GainMargin,'nyquist')
hold off
%figure
%diskmarginplot(DM.DiskMargin,'disk')
isstable(sysod)
u = 0.001*ones(size(t));
x0 = [0.01 0];
figure
lsim(sysod,zeros(size(t)),t,[x0]);
title('Discrete sampled after treatment with observer and conditions hot start')
xlabel('Time (sec)')
ylabel('Output')
res_agent = sysod;
figure
w = logspace(2,6,1000);
bode(res_agent,w),grid
figure
rlocus(res_agent)
figure
nyquist(res_agent)
ms = minreal(res_agent);
Gcc = ms;
zms = zero(ms) % closed-loop zeros
pms = pole(ms)
tsim = 1;
setpointamp = 1; %
setpointapptime = 0.001; %
defaultsetpointpos = 0; %
Conf = RespConfig(Bias=defaultsetpointpos,Amplitude=setpointamp,Delay=setpointapptime)
%figure
%step(Gcc,[0 tsim], Conf)
%title('Plant+Controller Closed Loop system step response')
[wngcc,zetagcc,pgcc] = damp(Gcc)
wngcc
zetagcc
pgcc
sigma(Gcc)
margin(Gcc)
diskmargin(Gcc)
stepinfo(Gcc)
disp('Whether the system is stable, minimum phase and proper:')
isstable(sysod)
isminphase(tfdata(tf(sysod),'v'))
isproper(sysod)
Qc= ctrb(A,B)
controllab = rank(Qc)
hasdelay(sysod)
%tdc3 = totaldelay(sysod)
%sysndc3 = absorbDelay(sysod)
isallpass(tfdata(tf(sysod),'v'))
%Less important:
%sys_cl = ss(Ai-bi*[K Ki],br,ci,di)
%[a,b] = ss2tf(sys_cl.A,sys_cl.B,sys_cl.C,sys_cl.D)
%[A,B,C,D] = tf2ss(Nbar*a,b)
%sys_cl = ss(A,B,C,D)
%figure
%step(sys_cl)
%discrete system
%hold on
%sys_cld = c2d(sys_cl,Ts)
%figure
%step(sys_cld)
%title('Discrete after treatment 2 sampled System')
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!