带死区的PID控制算法及仿真
1.基本概念
在计算机控制系统重,某些系统为了避免控制作用过于频繁,消除由于频繁动作所引起的振荡,可采用带死区的PID控制算法:
err(k) 为位置跟踪偏差,err0为可调参数,其具体数值可根据实际控制对象由实验确定。若err0太小,会使动作更新过于频繁,达不到稳定被控对象的目的;若err0值太大,则系统则会产生较大滞后。
带死区的PID控制实际上是一个非线性系统,在死区范围内,控制器输出为零;在死区外,控制器有输出。
2.仿真程序
matlab
clear all;
close all;
ts = 0.01;
sys = tf(5.235e005,[1, 87.35, 1.047e4, 0]);
dsys = c2d(sys, ts, 'z');
[num, den] = tfdata(dsys, 'v');
u_1 = 0;
u_2 = 0;
u_3 = 0;
u_4 = 0;
u_5 = 0;
y_1 = 0;
y_2 = 0;
y_3 = 0;
yn_1 = 0;
error_1 = 0;
errpr_2 = 0;
ei = 0;
sys1 = tf(1, [0.04, 1]); %low freq signal filter
dsys1 = c2d(sys1, ts, 'tusion');
[num1, den1] = tfdata(dsys1, 'v');
f_1 = 0;
for k = 1:2000
time(k) = k*ts;
yd(k) = 1; % step signal
%linear model
y(k) = -den(2)*y_1 - den(3)*y_2 - den(4)*y_3 + num(2)*u_1 + num(3)*u_2 + num(4)*u_3;
n(k) = 0.5*rands(1); % noisy signal
yn(k) = y(k) + n(k);
% low freq filter
filty(k) = -den1(2)*f_1 + num1(1)*(yn(k) + yn_1);
error(k) = yd(k) - filty(k);
if abs(error(k)) <= 0.2
ei = ei + error(k)*ts;
else
ei = 0;
end
kp = 0.5;
ki = 0.1;
kd = 0.02;
u(k) = kp*error(k) + ki*ei + kd*(error(k) - error_1)/ts;
if abs(error(k)) <= 0.0
u(k) = 0;
end
if u(k) >= 10
u(k) = 10;
elseif u(k) <= -10
u(k) = -10;
end
yd_1 = yd(k);
u_3 = u_2;
u_2 = u_1;
u_1 = u(k);
y_3 = y_2;
y_2 = y_1;
y_1 = y(k);
f_1 = filty(k);
yn_1 = yn(k);
error_2 = error_1;
error_1 = error(k);
end
figure(1);
subplot(2,1,1);
plot(time, yd, 'r', time, y, 'k:', 'LineWidth', 2);
xlabel('time(s)');
ylabel('yd,y');
legend('ideal position signal', 'position tracking');
subplot(2,1,2);
plot(time, u, 'r', 'LineWidth', 2);
xlabel('time(s');
ylabel('control input');
figure(2);
plot(time, n, 'r', 'LineWidth', 2);
xlabel('time(s)');
ylabel('noisy signal');
如果取消死区,pid给定为:
给定死区范围0.2,输出波动明显减少: