MATLAB 非线性系统辨识(电子节气门系统辨识)
最近筹备新的文章,主题是节气门的固定时间滑模控制。在实验的时候系统标称参数和实际系统相去甚远,做跟踪控制时总有一段稳态误差。遂重新辨识一下系统的参数。
此前从未辨识过系统参数,参考了 MATLAB 帮助文档中的例子,对节气门系统进行了辨识。
节气门(ET)系统建模
考虑节气门体的弹簧非线性、摩擦非线性可以得到一个简洁的系统模型:
J
e
q
θ
¨
t
+
B
e
q
θ
˙
t
+
F
s
sign
θ
˙
t
+
τ
L
H
sign
(
θ
t
−
θ
0
)
+
k
s
p
(
θ
t
−
θ
0
)
+
T
d
=
b
u
J_{eq} \ddot\theta_t + B_{eq} \dot\theta_t + F_s \operatorname{sign}\dot\theta_t + \tau_{LH} \operatorname{sign}(\theta_t - \theta_0) + k_{sp}(\theta_t - \theta_0) + T_d = bu
Jeqθ¨t+Beqθ˙t+Fssignθ˙t+τLHsign(θt−θ0)+ksp(θt−θ0)+Td=bu
简单整理一下,可以得到回归模型:
θ ¨ t = a 1 u − a 2 sign θ ˙ t − a 3 θ ˙ t − a 4 ( θ t − θ 0 ) − a 5 sign ( θ t − θ 0 ) − w \ddot \theta_t = a_1 u - a_2 \operatorname{sign} \dot\theta_t - a_3 \dot \theta_t - a_4 (\theta_t - \theta_0) - a_5 \operatorname{sign}(\theta_t - \theta_0) - w θ¨t=a1u−a2signθ˙t−a3θ˙t−a4(θt−θ0)−a5sign(θt−θ0)−w
输入输出数据收集
节气门电机的额定电压是
12
V
12V
12V,这里为了不让节气门过快的饱和,使用了 0 到 3V的正弦波信号,周期
T
T
T 是
1
s
1s
1s 和
0.5
s
0.5s
0.5s:
u
=
1.5
+
1.5
sin
(
2
π
/
T
⋅
t
)
u = 1.5 + 1.5\sin (2\pi / T \cdot t)
u=1.5+1.5sin(2π/T⋅t)
采集输入信号
u
u
u,以及输出信号
θ
t
\theta_t
θt(阀片的转动弧度位置)用于辨识。
MATLAB nlgrey
函数辨识非线性系统
简单列出步骤:
定义 ODE
函数
令
x
1
=
θ
t
,
x
2
=
θ
˙
t
,
w
=
0
x_1 = \theta_t, x_2 = \dot \theta_t, w = 0
x1=θt,x2=θ˙t,w=0, 将回归模型改写为状态方程形式:
{
x
˙
1
=
x
2
x
˙
2
=
a
1
u
−
a
2
sign
x
2
−
a
3
x
2
−
a
4
(
x
1
−
θ
0
)
−
a
5
sign
(
x
1
−
θ
0
)
y
=
x
1
\left\{ \begin{aligned} \dot x_1 &= x_2 \\ \dot x_2 &= a_1 u - a_2 \operatorname{sign} x_2 - a_3 x_2 - a_4 (x_1- \theta_0) - a_5 \operatorname{sign}(x_1- \theta_0) \end{aligned} \right.\\ y = x_1
{x˙1x˙2=x2=a1u−a2signx2−a3x2−a4(x1−θ0)−a5sign(x1−θ0)y=x1
新建 ET_m.m
文件,定义节气门 ODE
函数(m
文件形式)用于辨识
function [dx,y] = ET_m(t,x,u,a1,a2,a3,a4,a5,varargin)
th0 = 0;
y = x(1);
dx = [x(2)
a1 * u - a2 * sign(x(2)) - a3 * x(2) - a4 * (x(1) - th0) - a5 * sign(x(1) - th0)];
end
定义主函数
新建 ET_identification.m
文件,进行辨识
idnlgrey
函数定义一个用于回归的灰箱模型:
Note:
- 参数的初值参考自己需要辨识的系统的相关论文
- 起名字可以随意,不必按照本例
%--- System model def ---
clc,clear,close all
FileName = 'ET_m';
Order = [1 1 2]; % Order of Output, input and state, [ny nu nx];
th0 = 0;
Parameters = [1400;94;68;28;186]; % Parameters initilization
InitialStates = [th0;0]; % Initial state
Ts = 0; % Sampling time, 0 means continous system
ETsys = idnlgrey(FileName, Order, Parameters, InitialStates, Ts, ...
'Name', 'ET Model', ...
'InputName', {'Voltage'}, ...
'InputUnit', {'V'}, ...
'OutputName', {'Position'},...
'OutputUnit', {'rad'}, ...
'TimeUnit', 's');
定义系统状态
%--- System state def ---
ETsys = setinit(ETsys, 'Name', {'Position';'Velocity'});
ETsys = setinit(ETsys, 'Unit', {'rad'; 'rad/s'});
定义待辨识参数
- 如果某些参数已知,可以将其固定,参数的范围最好限定一下,本例没有做限定
%--- Identified name def ---
ETsys = setpar(ETsys, 'Name', {'a1'; 'a2'; 'a3'; 'a4';'a5'}); % give a readible name for the parameters
% ETsys.Parameters(1).Fixed = true; % If some parameters are fixed, pls declare here
ETsys.Parameters(1).Minimum = 0;
ETsys.Parameters(1).Maximum = inf;
ETsys.Parameters(2).Minimum = 0;
ETsys.Parameters(2).Maximum = inf;
ETsys.Parameters(3).Minimum = 0;
ETsys.Parameters(3).Maximum = inf;
ETsys.Parameters(4).Minimum = 0;
ETsys.Parameters(4).Maximum = inf;
ETsys.Parameters(5).Minimum = 0;
ETsys.Parameters(5).Maximum = inf;
present(ETsys) % Print system information
导入开环响应数据,建立实验数据模型
- 本例中输入量归一化不是必要的,根据自己的系统来
%---- Input experimental data ---
ETdata = csvread('ModelIdentification3.csv',3,0); % Input data, my data start from row 3, column 0
ns = 1666; % start point, my data start from 16s
nf = 2300; % end point, my data end in 23s
dataset.Input = ETdata(ns:nf,2) ./ 12; % u, normalized input value
dataset.Output = ETdata(ns:nf,4); % thetat is in row 4 in my case
th0 = 0; % LH position for ET system
SampleTime = .01; % Sampling time
z = iddata(dataset.Output, dataset.Input, SampleTime, 'Name', 'Actual Data');
z.InputName = ETsys.InputName;
z.InputUnit = ETsys.InputUnit;
z.OutputName = ETsys.OutputName;
z.OutputUnit = ETsys.OutputUnit;
z.Tstart = 0;
z.TimeUnit = 's';
present(z); % print print experimental system info
开始辨识
最主要的是 nlgreyest
函数,其他都是展示结果的语句
X0init = [th0;0]; % Initial states
ETsys = setinit(ETsys, 'Value', num2cell(X0init));
figure
compare(z, ETsys, compareOptions('InitialCondition', X0init)); % comparsion of experimental data and the model with initial parameters
ETsys = nlgreyest(ETsys, z, nlgreyestOptions('Display', 'on')); % Starting identification
figure
compare(z, ETsys, compareOptions('InitialCondition', X0init)); % comparson of experimental data with the model under identified parameters
present(ETsys) % print identified system info
辨识效果
初始参数下的数据和模型对比:
辨识过程,这个过程比较长,本例用了 5 mins 左右,cost 至少小于
0.001
0.001
0.001 才算差不多:
辨识后的系统和实验数据对比:
辨识出来的参数:
使用新的参数之后,跟踪效果大大提高。