文档库 最新最全的文档下载
当前位置:文档库 › 基于MATLAB的数字PID仿真

基于MATLAB的数字PID仿真

基于MATLAB的数字PID仿真
基于MATLAB的数字PID仿真

基于MATLAB 的数字PID 仿真

一、实验目的

1、 了解MATLAB 集成开发环境

2、 了解MATLAB 编程基本方法

3、 了解MATLAB 中数字控制器设计的基本方法

4、 加深对数字PID 的理解

二、实验内容

1、位置PID 的MA TLAB 仿真。

2、增量PID 的MA TLAB 仿真

三、实验程序框图

四、实验步骤

1、 熟悉MATLAB 开发环境

2、 输入参考程序

3、 设置断点,运行程序,观察运行结果

4、 参考程序

(1) 位置PID

被控对象21

()0.00670.1G s s s =+,控制参数20,

0.50p d k k ==

clear all

ts=0.001;

xk=zeros(2,1);

e_1=0;

u_1=0;

PID 控制程序流程图

for k=1:1:2000

time(k)=k*ts;

rin(k)=0.50*sin(1*2*pi*k*ts);

para=u_1;

tspan=[0 ts];

[tt,xx]=ode45('chap1_6f',tspan,xk,[],para);

xk=xx(length(xx),:);

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);

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);

num=[0,0,1];

den=[0.0067,0.1,0];

sys=tf(num,den);

[yy,time]=lsim(sys,rin,time);

plot(time,rin,'r',time,yout,'b',time,yy,'g');

(2)增量PID 被控对象2400

()50G s s s =+,控制参数8,0.10,

10p i d k k k ===

clear all ;

ts=0.001;

sys=tf(400,[1,50,0]);

dsys=c2d(sys,ts,'z');

[num,den]=tfdata(dsys,'V');

u_1=0.0;

u_2=0.0;

u_3=0.0;

y_1=0;

y_2=0;

y_3=0;

x=[0,0,0]';

error_1=0;

error_2=0;

for k=1:1:1000

time(k)=k*ts;

rin(k)=1.0;

kp=8;

ki=0.10;

kd=10;

du(k)=kp*x(1)+kd*x(2)+ki*x(3); 控制器输出

u(k)=u_1+du(k);

if u(k)>=10

u(k)=10;

end

if u(k)<=-10

u(k)=-10;

end

yout(k)=-den(2)*y_1-den(3)*y_2+num(2)*u_1+num(3)*u_2; 系统输出

error=rin(k)-yout(k);

u_3=u_2;

u_2=u_1;

u_1=u(k);

y_3=y_2;

y_2=y_1;

y_1=yout(k);

x(1)=error-error_1;

x(2)=error-2*error_1+error_2;

x(3)=error;

error_2=error_1;

error_1=error;

end

[yy,time]=lsim(sys,rin,time);

plot(time,rin,'b',time,yout,'r',time,yy,’g’);

xlabel('time(s)');

ylabel('rin,yout');

五、思考题

1、把增量PID参考程序中阶跃输入改成正弦输入,求出PID控制器输出。

相关文档