目录
- 一、弹簧-质量-阻尼系统
- 1. 系统状态空间方程
- 2. 观测器状态空间方程
- 二、仿真(Simulink s-function函数)
- 1. 搭建Simulink仿真模型
- 2. s-function函数代码
- 3. 仿真效果
控制理论–观测器设计
一、弹簧-质量-阻尼系统
- 系统参数: m = 1 , K = 1 , B = 0.5 m = 1\,, K = 1\,, B = 0.5 m=1,K=1,B=0.5
- 状态变量: z 1 = x (位置) ; z 2 = x ˙ (速度,不可测) z_1 = x \, \text{(位置)};\quad z_2 = \dot{x}\text{ (速度,不可测)} z1=x(位置);z2=x˙ (速度,不可测)
- 输入: u = F (外力) u = F \quad \text{(外力)} u=F(外力)
1. 系统状态空间方程
[ z ˙ 1 z ˙ 2 ] = [ 0 1 − 1 − 0.5 ] [ z 1 z 2 ] + [ 0 1 ] u y = [ 1 0 ] [ z 1 z 2 ] = z 1 \begin{aligned} \begin{bmatrix} \dot{z}_1 \\ \dot{z}_2 \end{bmatrix} &= \begin{bmatrix} 0 & 1 \\ -1 & -0.5 \end{bmatrix} \begin{bmatrix} z_1 \\ z_2 \end{bmatrix} + \begin{bmatrix} 0 \\ 1 \end{bmatrix} u \\ y =& \begin{bmatrix} 1 & 0 \end{bmatrix} \begin{bmatrix} z_1 \\ z_2 \end{bmatrix} = z_1 \end{aligned} [z˙1z˙2]y==[0−11−0.5][z1z2]+[01]u[10][z1z2]=z1
2. 观测器状态空间方程
[ z ^ ˙ 1 z ^ ˙ 2 ] = [ − 2.5 1 0.25 − 0.5 ] [ z ^ 1 z ^ 2 ] + [ 0 1 ] u + [ 2.5 − 1.25 ] y \begin{aligned} \begin{bmatrix} \dot{\hat{z}}_1 \\ \dot{\hat{z}}_2 \end{bmatrix} &= \begin{bmatrix} -2.5 & 1 \\ 0.25 & -0.5 \end{bmatrix} \begin{bmatrix} \hat{z}_1 \\ \hat{z}_2 \end{bmatrix} + \begin{bmatrix} 0 \\ 1 \end{bmatrix} u + \begin{bmatrix} 2.5 \\ -1.25 \end{bmatrix} y \end{aligned} [z^˙1z^˙2]=[−2.50.251−0.5][z^1z^2]+[01]u+[2.5−1.25]y
二、仿真(Simulink s-function函数)
1. 搭建Simulink仿真模型
2. s-function函数代码
- Mode_system.m
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 2; %
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3; %z1,z2,y
sizes.NumInputs = 1; %u
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [0;1];
function sys=mdlDerivatives(t,x,u)
M = 1;
K = 1;
B = 0.5;
uc = u(1);
z1 = x(1);
z2 = x(2);
dz1 = z2;
dz2 = (-K/M) * z1-(B/M) * z2 + (1/M)*uc;
sys = [dz1;dz2];
function sys=mdlOutputs(t,x,u)
z1 = x(1);
y = z1;
sys = [y;x]; %sys = [z1,z2,y]
- Observer.m
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 2; %z1_hat,z2_hat
sizes.NumInputs = 2; %u和y
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [0;0];
function sys=mdlDerivatives(t,x,u)
A = [-2.5,1;0.25,-0.5];
B = [0;1];
L = [2.5;-1.25];
z_hat = x; %z_hat = [z1_hat;z2_hat];
u_input = u(1); %输入1
y_meas = u(2); %输入2
dz_hat = A * z_hat + B * u_input + L * y_meas;
sys = dz_hat;
function sys=mdlOutputs(t,x,u)
sys = x; %sys = [z1_hat; z2_hat];
3. 仿真效果
由图可知, z 1 , z 2 z1,z2 z1,z2 分别被 z ^ 1 , z ^ 2 \hat{z}_1\, , \hat{z}_2 z^1,z^2所观测,且效果不错。