我正在编写一个代码,用MATLAB中的最小二乘法优化MIMO系统的PID增益。我正在设计PID控制器的工厂有3个输入和3个输出,对于每个输入,我正在设计一个PID控制器。整个系统看起来像这样:
% _____________________________________________________________________
% | |
% | |
% | |
% | __________________________________ |
% | e u | | y |
% r_phi,pitch,psi--|-->O--> PID array -->| ssModel |----------.-|------
% | ^ | | | |
% | | y |__________________________________| | |
% | | system | |
% | | | |
% | .---------------------------------------------------------------. |
% |_____________________________________________________________________|
% clSys
%
我的问题是优化逻辑总是返回非常接近初始值的优化增益,显然它总是落在局部最小值。
如何全局最小化9个增益?
以下是状态空间模型文件:
function [ssModel, Ts] = getSSmodel()
%% Define the parameter of our hardware
Jxx = 0.01; % appr. the inertia of a solid cube with the quad's mass (the best)
Jyy = 0.01;
Jzz = Jxx*2;
l = 0.225; % meters, the distance from the center of the propeller to the center of
% the drone
Ts = 0.0083; % the sampling time
b1 = l/Jxx;
b2 = l/Jyy;
b3 = 1/Jzz;
%% Define the continuous and discrete SS model
A = [0 1 0 0 0 0;
0 0 0 0 0 0;
0 0 0 1 0 0;
0 0 0 0 0 0;
0 0 0 0 0 1;
0 0 0 0 0 0];
B = [0 0 0;
b1 0 0;
0 0 0;
0 b2 0;
0 0 0;
0 0 b3];
C = [1 0 0 0 0 0;
0 0 1 0 0 0;
0 0 0 0 1 0];
D = zeros(size(C,1),size(B,2));
continuous_sys = ss(A,B,C,D);
discrete_sys = c2d(continuous_sys,Ts);
ssModel = discrete_sys;
end
这是我指定最小化函数和成本函数的代码:
function costFunction = closedLoopPoles(pidGains, ssModel)
if (nargin < 2)
[ssModel, Ts] = getSSmodel();
end
%Define the PID controllers array
pidTF_array = ones(3,3) * tf(0,1,Ts);
for i = 1:size(pidGains,1)
pidTF_array(i,i) = pid( pidGains(i,1), pidGains(i,2), pidGains(i,3),'IFormula','BackwardEuler','DFormula','BackwardEuler', 'Ts', Ts);
end
% Assign the signals names and the systems structure
pidTF_array.u = 'e'; pidTF_array.y = 'u';
ssModel.u = 'u'; ssModel.y = 'y';
sum1 = sumblk('e = r - y',3);
system = ssModel;
% Find the closed loop system
clSys = connect(system,pidTF_array,sum1,'r','y');
clPoles = pole( clSys );
maxAbs_clPoles = max(abs(clPoles));
sumAbs_clPoles = sum(abs(clPoles));
sumnorm_clPoles = sum(norm(clPoles));
costFunction = sumnorm_clPoles;
end
最后这里是优化功能:
function pidGains_opt = optimizePID_minPole()
clear all
clc
pidGains_ini = [180 4 20 160 4 20 150 4 10];
func = @closedLoopPoles;
[pidGains_opt, ~] = lsqnonlin(func,pidGains_ini)
end
当我运行优化代码时,我在工作区中得到了这个:
pidGains_ini =
180 4 20
160 4 20
150 4 10
Warning: Trust-region-reflective algorithm requires at least as many equations as variables; using
Levenberg-Marquardt algorithm instead.
> In lsqncommon at 77
In lsqnonlin at 235
In optimizePID_minPole at 11
Local minimum possible.
lsqnonlin stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
<stopping criteria details>
pidGains_opt =
179.8817 4.0022 3.1099
159.8839 4.0025 3.0151
149.9482 4.0022 1.5592