matlab积分饱和消除一例

clc;clear all;close all
%convert transfer function to state spaces
num=conv([1 -3],[1 5]);
den_temp=conv([1 0],[1 1]);
den=conv(den_temp,[1 3]);
[Ap,Bp,Cp,Dp]=tf2ss(num,den);
%calculate gain of observer
po_temp=conv([1 10],[1 10]);
po=conv(po_temp,[1 10]);
Kob=T2place(Ap',Cp',po)';
%calculate coficient matrix
O1=zeros(3,1);O2=zeros(1,1);O3=zeros(1,1);
A=[Ap O1;Cp O2];
B=[Bp;O3];
%calculate gain of expended state spaces
p_temp1=conv([1 2],[1 2]);
p_temp2=conv(p_temp1,[1 2]);
p=conv(p_temp2,[1 2]);
K=T2place(A,B,p);
%initional
Kp=K(1,1:3);
Ky=K(1,4);%
delta_t=0.001;
t=0:delta_t:20;

xp_hat_dot=zeros(3,1);
xp=zeros(3,1);
y_plot=zeros(1,length(t));
u_plot=zeros(1,length(t));
y=0;
y_pre=0;
y_plot(1)=y;

u=0;
u_pre=0;
u_plot(1)=u;

r=ones(1,length(t));
disturbance=[zeros(1,(length(t)-1)/2) ones(1,(length(t)-1)/2+1)];
u_max=1.5;
u_min=-1.5;

for k=2:length(t)
    %
    u_dot=-K*[xp_hat_dot;y-r(k)];
    u=u_pre+u_dot*delta_t;
    u_pre=u;
    u=u+disturbance(k);
    if u>u_max
        u=u_max;
    elseif u<u_min
        u=u_min;
    end
    xp_hat_dot=xp_hat_dot+delta_t*(Ap*xp_hat_dot+Bp*u_dot-Kob*Cp*xp_hat_dot)+Kob*(y-y_pre);
    xp=xp+delta_t*(Ap*xp+Bp*u);
    y_pre=y;
    y=Cp*xp;
     
    y_plot(k)=y;
    u_plot(k)=u;
end
figure(1)
plot(t,y_plot,'-r')
xlabel('time (sec)');
ylabel('y');
hold on
figure(2)
plot(t,u_plot,'-g')
xlabel('time (sec)');
ylabel('u');

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值