Gain scheduling controller tuning via tunableSurface, setBlockParam and systune

I am following this Tutorial to build a gain schedule controller
This is the diagram:
I schedule the controller using variable alpha and a exogenious signal Mach number.
I have already divided the system into muiltiple linear parts variable G in the code below. And have set up the tunableSurface for the gains of the two PID controller see:Kp,Kt,Ki,a,b. The problem occurs when I am trying to tune these parameters. Following the turtorial I set up the 2d lookup tables in each of my controller, i.e Kp,Ki,Kt,a and b
And use setBlockParam and systune to tune the gains. In the lookup table block I set the parameters as follow(a random table data). According to the discription of setBlockParam, it should help me override these value and find the optimal ones in the end. However, the tuning only last for 1 iter(Final: Soft = 1e+03, Hard = 0.41421, Iterations = 1) and it doesn't change the value that I set.
Weirdly enough, the controllers are tuned exact the same way as I am. But they use a variable called Kp_vec. Which only exist in the model workspace. and I can't not find out where they generate it! Their implementation does work and this Kp_vec does change.
So I am trying to figure out what is this Kp_vec and I found out something even more creepy that even if I change the lookup table value of the tutorial model(after tuned), The behavior of the controller will still be the same.
I have been struggling with this for a full day. Maybe my controller architecture ain't right, Maybe the pid controllers are not good enough for this plant?
Anyway, I would appreciated if someone familiar with this field can point out my mistake. Or to provide a different approach to turn the pid controllers. I'm just a newbie in simulink and control theory, but I find it pretty fun. Tell me if you need more codes or anything to specify the problem.😊
My code below:
clear
open_system('aerodynamic')
EQp=3
opspec=operspec('aerodynamic',[3,3])
MachEQ=linspace(1,3,EQp)'
alphaEQ=linspace(0,20,EQp)'
qEQ = zeros(EQp,EQp);
etaEQ = zeros(EQp,EQp);
deltaEQ = zeros(EQp,EQp);
i=0
for k=1:EQp
for j=1:EQp
i=i+1
opspec(k,j).Outputs(1).y=alphaEQ(j)
opspec(k,j).Outputs(1).Known=true
opspec(k,j).Inputs(2).u=MachEQ(k)
opspec(k,j).Inputs(2).Known=true
end
end
[op,report] = findop('aerodynamic',opspec,...
findopOptions('DisplayReport','off'));
i=0
for k=1:EQp
for j=1:EQp
i=i+1
etaEQ (k,j) = report(k,j).Outputs(2).y;
qEQ (k,j) = report(k,j).Outputs(3).y;
deltaEQ (k,j) = report(k,j).Outputs(4).y;
delta_cEQ(k,j) = op(k,j).Inputs.u;
end
end
G = linearize('aerodynamic', 'aerodynamic/plant1', op);
G.InputName = {'mach','delta_c'};
G.OutputName = {'alpha','eta','q','delta'};
%Controllers=pidtune(G,'pidf',150)
isstable(G,'elem')
R1 = TuningGoal.Tracking('eta_c','eta',0.001);
MinDecay = 0.02;
MinDamping = 0.05;
% Constrain closed-loop poles of inner loop with the outer loop open
R2 = TuningGoal.Poles('q',MinDecay,MinDamping);
R2.Openings = 'qSP';
R4 = TuningGoal.Margins('q',7,45);
[alpha,M] = ndgrid(alphaEQ,MachEQ)
%
TuningGrid = struct('alpha',alpha,'Mach',M);
ShapeFcn = @(a,M) [a ,M, a*M ];
Kp = tunableSurface('Kp', 0, TuningGrid, ShapeFcn);
Ki = tunableSurface('Ki', -2, TuningGrid, ShapeFcn);
Kt = tunableSurface('Kt', 0, TuningGrid, ShapeFcn);
a = tunableSurface('a', 0, TuningGrid, ShapeFcn);
b = tunableSurface('b', 0, TuningGrid, ShapeFcn);
Ts=0.01
Gd = c2d(G,Ts)
BlockSubs = struct('Name','pidmat/plant','Value',Gd);
ST0 = slTuner('pidmat',{'Kp','Ki','Kt','a','b'},BlockSubs);
ST0.Ts = Ts; % sample time for tuning
% Register points of interest
ST0.addPoint({'eta_c','eta','qSP','q','du'})
lookup_M=linspace(1,3,5)'
lookup_a=linspace(0,20,5)
lookup_Ma=lookup_M*lookup_a
m0=ones(5,5)
m1=lookup_M*ones(1,5)
m2=ones(5,1)*lookup_a
m3=lookup_Ma
% Parameterize look-up table blocks
ST0.setBlockParam('Kp',Kp);
ST0.setBlockParam('Ki',Ki);
ST0.setBlockParam('Kt',Kt);
ST0.setBlockParam('a',a);
ST0.setBlockParam('b',b);
ST = systune(ST0,[R1 R2],R4);

Answers (0)

Products

Release

R2022b

Asked:

on 30 Dec 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!