T-S模糊模型与状态反馈控制及Matlab仿真 (附代码)

(一) 仿射非线性系统建模

以overhead crane system为例,
overhead crane system
忽略摩擦,我们可以得到如下的状态空间方程,
x ˙ = ( x 2 m l x 4 2    sin ⁡    x 3 + m g    sin ⁡    x 3 cos ⁡    x 3    M + m    sin ⁡ 2    x 3 x 4 − m l x 4 2    sin ⁡    x 3    cos ⁡    x 3 + ( M + m ) g    sin ⁡    x 3    l ( M + m    sin ⁡ 2    x 3 ) ) + u M + m    sin ⁡ 2    x 3 ( 0 1 0 − cos ⁡    x 3 l ) \dot x=\begin{pmatrix}x_2\\\frac{mlx_4^2\;\sin\;x_3+mg\;\sin\;x_3\cos\;x_3\;}{M+m\;\sin^2\;x_3}\\x_4\\-\frac{mlx_4^2\;\sin\;x_3\;\cos\;x_3+(M+m)g\;\sin\;x_3\;}{l(M+m\;\sin^2\;x_3)}\end{pmatrix}+\frac u{M+m\;\sin^2\;x_3}\begin{pmatrix}0\\1\\0\\-\frac{\cos\;x_3}l\end{pmatrix} x˙=x2M+msin2x3mlx42sinx3+mgsinx3cosx3x4l(M+msin2x3)mlx42sinx3cosx3+(M+m)gsinx3+M+msin2x3u010lcosx3

(二) 计算T-S模糊模型子系统

取工作点。一般地,我们会选取平衡点。
x 0 = ( 0 0 0 0 ) x_0=\begin{pmatrix}0\\0\\0\\0\end{pmatrix} x0=0000, x 1 = ( 5 0 π / 6 π / 20 ) x_1=\begin{pmatrix}5\\0\\\pi/6\\\pi/20\end{pmatrix} x1=50π/6π/20, x 2 = ( 5 − 1 − π / 6 0 ) x_2=\begin{pmatrix}5\\-1\\-\pi/6\\0\end{pmatrix} x2=51π/60
A 0 = J ( x 0 ) A_0=J(x_0) A0=J(x0), B 0 = g ( x 0 ) B_0=g(x_0) B0=g(x0)
A i = J ( x i ) + 1 x i T x i [ f ( x i ) − J ( x i ) x i ] x i T A_i=J(x_i)+\frac {1}{{x_i}^Tx_i}[f(x_i)-J(x_i)x_i]{x_i}^T Ai=J(xi)+xiTxi1[f(xi)J(xi)xi]xiT, B i = g ( x i ) B_i=g(x_i) Bi=g(xi), i = 1 , 2 i=1,2 i=1,2

(三) 建立推理,验证开环特性

if x is about x 0 x_0 x0, then x ˙ = A 0 x + B 0 u \dot x=A_0x+B_0u x˙=A0x+B0u
if x is about x 1 x_1 x1, then x ˙ = A 1 x + B 1 u \dot x=A_1x+B_1u x˙=A1x+B1u
if x is about x 2 x_2 x2, then x ˙ = A 2 x + B 2 u \dot x=A_2x+B_2u x˙=A2x+B2u
h 0 ( x 3 ) = { sin ⁡    x 3 x 3 , x 3 ≠ 0 1 , x 3 = 0 h_0(x_3)=\left\{\begin{array}{l}\frac{\sin\;x_3}{x_3},x_3\neq0\\1,x_3=0\end{array}\right. h0(x3)={x3sinx3,x3=01,x3=0 h 1 ( x 3 ) = h 2 ( x 3 ) = 1 − h 0 ( x 3 ) 2 h_1(x_3)=h_2(x_3)=\frac{1-h_0(x_3)}{2} h1(x3)=h2(x3)=21h0(x3)
开环

(四) 极点配置,验证闭环特性

选取极点 p 0 = ( − 1.1 − 1.5 − 1.8 − 2.1 ) p_0=\begin{pmatrix}-1.1 -1.5 -1.8 -2.1\end{pmatrix} p0=(1.11.51.82.1) p 1 = ( − 1.3 − 1.6 − 1.9 − 2.2 ) p_1=\begin{pmatrix}-1.3 -1.6 -1.9 -2.2\end{pmatrix} p1=(1.31.61.92.2) p 2 = ( − 1.5 − 1.6 − 1.8 − 1.9 ) p_2=\begin{pmatrix}-1.5 -1.6 -1.8 -1.9\end{pmatrix} p2=(1.51.61.81.9)
闭环

(五) 使用LMI验证稳定性

∃ P = ( 0.4016 0.1427 0.5521 0.5098 0.1427 0.1903 − 0.0489 0.7069 0.5521 − 0.0489 5.7520 − 0.1442 0.5098 0.7069 − 0.1442 2.8079 ) \exists P=\begin{pmatrix}0.4016&0.1427&0.5521&0.5098\\0.1427&0.1903&-0.0489&0.7069\\0.5521&-0.0489&5.7520&-0.1442\\0.5098&0.7069&-0.1442&2.8079\end{pmatrix} P=0.40160.14270.55210.50980.14270.19030.04890.70690.55210.04895.75200.14420.50980.70690.14422.8079
{ ( A i − B i K i ) T P + P ( A i − B i K i ) < 0 ,    ( i = 1 , 2 , 3 ) ( A i − B i K j + A j − B j K i ) T P + P ( A i − B i K j + A j − B j K i ) < 0 , ( i < j ≤ 3 ) \left\{\begin{array}{l}{(A_i-B_iK_i)}^TP+P(A_i-B_iK_i)<0,\;(i=1,2,3)\\{(A_i-B_iK_j+A_j-B_jK_i)}^TP+P(A_i-B_iK_j+A_j-B_jK_i)<0,(i<j\leq3)\end{array}\right. {(AiBiKi)TP+P(AiBiKi)<0,(i=1,2,3)(AiBiKj+AjBjKi)TP+P(AiBiKj+AjBjKi)<0,(i<j3)

clear all;close all;
M=100;m=100;l=5;g=9.82;u=100;
syms x1 x2 x3 x4;
x00=[0 0 0 0]';x01=[5 0 pi/6 pi/20]';x02=[5 -1 -pi/6 0]';
x=[x1;x2;x3;x4];
f=[x2;(m*l*x4^2*sin(x3)+m*g*sin(x3)*cos(x3))/(M+m*sin(x3)*sin(x3));x4;-(m*l*x4^2*sin(x3)*cos(x3)+(M+m)*g*sin(x3))/l/(M+m*sin(x3)*sin(x3))];
gx=1/(M+m*sin(x3)*sin(x3))*[0;1;0;-cos(x3)/l];
J=jacobian(f,x);
Ai=J+(f-J*x)*x'/(x'*x);
A0=double(subs(J,x,x00));B0=double(subs(gx,x,x00));
A1=double(subs(Ai,x,x01));B1=double(subs(gx,x,x01));
A2=double(subs(Ai,x,x02));B2=double(subs(gx,x,x02));

a0=[-1.1 -1.5 -1.8 -2.1];
a1=[-1.3 -1.6 -1.9 -2.2];
a2=[-1.5 -1.6 -1.8 -1.9];

K0=place(A0,B0,a0);K1=place(A1,B1,a1);K2=place(A2,B2,a2);

setlmis([]);
P=lmivar(1,[4,1]);
lmiterm([1 1 1 P],1,A0-B0*K0,'s');
lmiterm([2 1 1 P],1,A1-B1*K1,'s');
lmiterm([3 1 1 P],1,A2-B2*K2,'s');
lmiterm([4 1 1 P],1,A0-B0*K1+A1-B1*K0,'s');
lmiterm([5 1 1 P],1,A1-B1*K2+A2-B2*K1,'s');
lmiterm([6 1 1 P],1,A2-B2*K0+A0-B0*K2,'s');
lmiterm([-7 1 1 P],1,1);
lmisys=getlmis;
[tmin,xfeas]=feasp(lmisys);
tmin
pmat=dec2mat(lmisys,xfeas,P)

t m i n = − 0.0163 t_{min}=-0.0163 tmin=0.0163
P = ( 4.2687 3.1372 6.7828 14.3290 3.1372 6.5107 − 10.3561 29.7178 6.7828 − 10.3561 151.4136 − 37.1458 14.3290 29.7178 − 37.1458 145.7880 ) P=\begin{pmatrix}4.2687&3.1372&6.7828&14.3290\\3.1372&6.5107&-10.3561&29.7178\\6.7828&-10.3561&151.4136&-37.1458\\14.3290&29.7178&-37.1458&145.7880\end{pmatrix} P=4.26873.13726.782814.32903.13726.510710.356129.71786.782810.3561151.413637.145814.329029.717837.1458145.7880

下载链接
https://download.csdn.net/download/qq_29710939/84993530

trolly_sim.m

clear all;close all;
t0=0;tf=30;step=0.1;
x0(1:4)=[10 1 pi/10 0.1]';
global M m l u g;
global A0 A1 A2 B0 B1 B2 x3 K0 K1 K2;
M=100;m=50;l=4;g=9.81;u=100;
syms x1 x2 x3 x4;
x00=[0 0 0 0]';x01=[5 0 pi/6 pi/20]';x02=[5 -1 -pi/6 0]';
x=[x1;x2;x3;x4];
f=[x2;(m*l*x4^2*sin(x3)+m*g*sin(x3)*cos(x3))/(M+m*sin(x3)*sin(x3));x4;-(m*l*x4^2*sin(x3)*cos(x3)+(M+m)*g*sin(x3))/l/(M+m*sin(x3)*sin(x3))];
gx=1/(M+m*sin(x3)*sin(x3))*[0;1;0;-cos(x3)/l];
J=jacobian(f,x);
Ai=J+(f-J*x)*x'/(x'*x);
A0=double(subs(J,x,x00));B0=double(subs(gx,x,x00));
A1=double(subs(Ai,x,x01));B1=double(subs(gx,x,x01));
A2=double(subs(Ai,x,x02));B2=double(subs(gx,x,x02));

[t,x_fuzzy]=ode45('trolly_fuzzy',[t0:step:tf], x0);
[t,x_affine]=ode45('trolly_affine',[t0:step:tf], x0);
figure(1);
subplot(2,2,1);plot(t, x_fuzzy(:,1),'b-.',t,x_affine(:,1),'b:');xlabel('时间(秒)');ylabel('x1');
subplot(2,2,2);plot(t, x_fuzzy(:,2),'b-.',t,x_affine(:,2),'b:');xlabel('时间(秒)');ylabel('x2');
subplot(2,2,3);plot(t, x_fuzzy(:,3),'b-.',t,x_affine(:,3),'b:');xlabel('时间(秒)');ylabel('x3');
subplot(2,2,4);plot(t, x_fuzzy(:,4),'b-.',t,x_affine(:,4),'b:');xlabel('时间(秒)');ylabel('x4');

a0=[-1.1 -1.5 -1.8 -2.1];
a1=[-1.3 -1.6 -1.9 -2.2];
a2=[-1.5 -1.6 -1.8 -1.9];
K0=place(A0,B0,a0);K1=place(A1,B1,a1);K2=place(A2,B2,a2);

[t,x_fuzzy_ctrl]=ode45('trolly_fuzzy_ctrl',[t0:step:tf], x0);
[t,x_affine_ctrl]=ode45('trolly_affine_ctrl',[t0:step:tf], x0);
figure(2);
subplot(2,2,1);plot(t, x_fuzzy_ctrl(:,1),'b-.',t,x_affine_ctrl(:,1),'b:');xlabel('时间(秒)');ylabel('x1');
subplot(2,2,2);plot(t, x_fuzzy_ctrl(:,2),'b-.',t,x_affine_ctrl(:,2),'b:');xlabel('时间(秒)');ylabel('x2');
subplot(2,2,3);plot(t, x_fuzzy_ctrl(:,3),'b-.',t,x_affine_ctrl(:,3),'b:');xlabel('时间(秒)');ylabel('x3');
subplot(2,2,4);plot(t, x_fuzzy_ctrl(:,4),'b-.',t,x_affine_ctrl(:,4),'b:');xlabel('时间(秒)');ylabel('x4');

trolly_affine.m

function xdot = trolly_affine(t, x);
global M m l u g;
f=[x(2);(m*l*x(4)^2*sin(x(3))+m*g*sin(x(3))*cos(x(3)))/(M+m*sin(x(3))*sin(x(3)));x(4);-(m*l*x(4)^2*sin(x(3))*cos(x(3))+(M+m)*g*sin(x(3)))/l/(M+m*sin(x(3))*sin(x(3)))];
gx=1/(M+m*sin(x(3))*sin(x(3)))*[0;1;0;-cos(x(3))/l];
xdot=f+gx*u;

trolly_fuzzy.m

function xdot = trolly_fuzzy(t, x);
global A0 A1 A2 B0 B1 B2 u M m;
if(x(3)==0)
    h0=1;
else
    h0=sin(x(3))/x(3);
end
h1=(1-h0)/2;h2=h1;
xdot=h0*(A0*x+B0*u)+h1*(A1*x+B1*u)+h2*(A2*x+B2*u); 

trolly_affine_ctrl.m

function xdot = trolly_affine_ctrl(t, x);
global M m l u g K0 K1 K2;
f=[x(2);(m*l*x(4)^2*sin(x(3))+m*g*sin(x(3))*cos(x(3)))/(M+m*sin(x(3))*sin(x(3)));x(4);-(m*l*x(4)^2*sin(x(3))*cos(x(3))+(M+m)*g*sin(x(3)))/l/(M+m*sin(x(3))*sin(x(3)))];
gx=1/(M+m*sin(x(3))*sin(x(3)))*[0;1;0;-cos(x(3))/l];
h0=M*(sin(x(3)))^2/(M+m*sin(x(3))*sin(x(3)));
h1=M*(cos(x(3)))^2/(M+m*sin(x(3))*sin(x(3)));
h2=m*(sin(x(3)))^2/(M+m*sin(x(3))*sin(x(3)));
xdot=f+gx*(u-h0*K0*x-h1*K1*x-h2*K2*x);

trolly_fuzzy_ctrl.m

function xdot = trolly_fuzzy_ctrl(t, x);
global A0 A1 A2 B0 B1 B2 u M m K0 K1 K2;
if(x(3)==0)
    h0=1;
else
    h0=sin(x(3))/x(3);
end
h1=(1-h0)/2;h2=h1;
u0=u-h0*K0*x-h1*K1*x-h2*K2*x;
xdot=h0*(A0*x+B0*u0)+h1*(A1*x+B1*u0)+h2*(A2*x+B2*u0); 
  • 19
    点赞
  • 74
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
好的,我可以为你提供一个简单的电饭锅控制系统的 Matlab 建模示例。 首先,我们需要明确电饭锅的控制目标,即让电饭锅内的水煮沸并保持温度在一定范围内。为了实现这个目标,我们可以采用 PID 控制器。 我们设电饭锅内的水量为 $m$,加热器功率为 $P$,水温为 $T$。那么,电饭锅的控制系统可以表示为以下模型: $$ \frac{dT}{dt} = \frac{P}{m c}(T_\text{set} - T) - \frac{U A}{m c}(T - T_\text{amb}) $$ 其中,$c$ 是水的比热容,$U$ 是电饭锅内壁的传热系数,$A$ 是电饭锅内壁的面积,$T_\text{set}$ 是设定的水温,$T_\text{amb}$ 是环境温度。 接下来,我们可以使用 Matlab 中的 control toolbox 来进行建模。具体步骤如下: 1. 定义系统模型: ```matlab m = 1; % 水的质量(kg) c = 4186; % 水的比热容(J/(kg*K)) U = 18; % 传热系数(W/(m^2*K)) A = 0.04; % 内壁面积(m^2) T_amb = 25; % 环境温度(℃) T_set = 100; % 设定温度(℃) P = 800; % 加热功率(W) % 系统模型 sys = tf(P/(m*c), [1 U*A/(m*c) P/(m*c)]); ``` 2. 设计 PID 控制器 ```matlab Kp = 1; Ki = 0.1; Kd = 0.01; % PID 控制器 controller = pid(Kp, Ki, Kd); ``` 3. 将系统模型和 PID 控制器组合成闭环控制系统 ```matlab % 闭环系统 sys_cl = feedback(controller*sys, 1); ``` 4. 仿真系统响应,观察系统的稳态误差、振荡等情况 ```matlab % 仿真时间 t = 0:0.1:100; % 仿真输入 r = T_set*ones(size(t)); % 仿真输出 [y,t] = lsim(sys_cl,r,t); % 绘制系统响应曲线 plot(t, r, 'r--', t, y, 'b-'); title('Electrical Rice Cooker Control System') xlabel('Time (s)') ylabel('Water Temperature (℃)') legend('Set Temperature', 'Water Temperature') ``` 这样,我们就完成了电饭锅控制系统的 Matlab 建模。当然,这只是一个简单的示例,实际情况中还需要考虑更多因素,比如系统的非线性特性、噪声等等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值