⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap1_6.m

📁 数字pid控制仿真
💻 M
字号:
%Discrete PID control for continuous plant
clear all;
close all;

ts=0.001;  %Sampling time
xk=zeros(2,1);
e_1=0;
u_1=0;

for k=1:1:2000
time(k) = k*ts;

rin(k)=0.50*sin(1*2*pi*k*ts);
  
para=u_1;              % D/A
tSpan=[0 ts];
[tt,xx]=ode45('chap1_6f',tSpan,xk,[],para);
xk = xx(length(xx),:);    % A/D
yout(k)=xk(1); 

e(k)=rin(k)-yout(k);
de(k)=(e(k)-e_1)/ts; 

u(k)=20.0*e(k)+0.50*de(k);
%Control limit
if u(k)>10.0
   u(k)=10.0;
end
if u(k)<-10.0
   u(k)=-10.0;
end

u_1=u(k);
e_1=e(k);
end
figure(1);
plot(time,rin,'r',time,yout,'b');
xlabel('time(s)'),ylabel('rin,yout');
figure(2);
plot(time,rin-yout,'r');
xlabel('time(s)'),ylabel('error');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -