1.算法仿真效果 matlab2022a仿真结果如下:
2.算法涉及理论知识概要 PID控制器
PID控制器(比例-积分-微分控制器),由比例单元 P、积分单元 I 和微分单元 D 组成。通过Kp, Ki和Kd三个参数的设定。PID控制器主要适用于基本线性和动态特性不随时间变化的系统。
PID 控制器的方块图PID 控制器是一个在工业控制应用中常见的反馈回路部件。这个控制器把收集到的数据和一个参考值进行比较,然后把这个差别用于计算新的输入值,这个新的输入值的目的是可以让系统的数据达到或者保持在参考值。和其他简单的控制运算不同,PID控制器可以根据历史数据和差别的出现率来调整输入值,这样可以使系统更加准确,更加稳定。可以通过数学的方法证明,在其他控制方法导致系统有稳定误差或过程反复的情况下,一个PID反馈回路却可以保持系统的稳定。
具有比例-积分-微分控制规律的控制器,称PID控制器。这种组合具有三种基本规律各自的特点,其运动方程为:
由此可见,当利用PID控制器进行串联校正时,除可使系统的型别提高一级外,还将提供两个负实零点。与PI控制器相比,PID控制器除了同样具有提高系统的稳态性能的优点外,还多提供一个负实零点,从而在提高系统动态性能方面,具有更大的优越性。因此,在工业过程控制系统中,广泛使用PID控制器。PID控制器各部分参数的选择,在系统现场调试中最后确定。通常,应使积分部分发生在系统频率特性的低频段,以提高系统的稳态性能;而使微分部分发生在系统频率特性的中频段,以改善系统的动态性能。
H无穷控制器
H∞控制是一种具有很好鲁棒性的设计方法,具有设计思想明确、控制效果好等优点,尤其适用于模型摄动的多输入多输出(MIMO)系统。H∞控制在控制理论、设计方法及应用等方面,经过多年不断发展和完善,已成为一种具有较完整体系的鲁棒控制理论。为适应控制系统稳定性、自适应性、智能化及工程化的更高要求,基于线性矩阵不等式(LMI)的H∞控制、非线性H∞控制以及H∞控制与神经网络和模糊控制结合,成为近年来H∞控制研究的热点。随着H∞控制研究的深入,其存在的诸如理论复杂、计算量大和参数摄动范围有限等问题将会逐步得到解决,适用范围也会更广、应用前景会更好。
关于H无穷控制器的设计,主要需要根据具体的控制对象进行设计,这里,提供一个网站,是结合matlab进行介绍说明的,感觉还不错:
http://wenku.baidu.com/view/9b5a2218c281e53a5802ff14.html
3.MATLAB核心程序
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SEL = get(handles.checkbox1,'Value');
kps = str2num(get(handles.edit1,'String'));
kis = str2num(get(handles.edit2,'String'));
kds = str2num(get(handles.edit3,'String'));
Time = str2num(get(handles.edit5,'String'));
ts = 0.001;
J = 0.05;
q = 0.1;
sys = tf(1,[J,q,0]);
dsys = c2d(sys,ts,'z');
[num,den] = tfdata(dsys,'v');
u_1 = 0;
u_2 = 0;
y_1 = 0;
y_2 = 0;
error_1 = 0;
ei = 0;
kp = zeros(Time/ts,1);
ki = zeros(Time/ts,1);
kd = zeros(Time/ts,1);
for k=1:1:Time/ts
time(k) = k*ts;
yd(k) = 1;
y(k) = -den(2)*y_1-den(3)*y_2+num(2)*u_1+num(3)*u_2;
error(k) = yd(k)-y(k);
derror(k) = (error(k)-error_1)/ts;
%kp
P_c1 = kps;
tmpsp(k) = P_c1 + sech(error(k));
if SEL == 0
kp(k)= kps;
end
if SEL == 1
kp(k)= tmpsp(k);
end
%kd
P_d1 = kis;
tmpsd(k) = P_d1 + sech(error(k));
if SEL == 0
kd(k)= kis;
end
if SEL == 1
kd(k)= tmpsd(k);
end
%ki
P_i1 = kds;
tmpsi(k) = P_i1 + sech(error(k));
if SEL == 0
ki(k)= kds;
end
if SEL == 1
ki(k)= tmpsi(k);
end
ei = ei+error(k)*ts;
u(k) = kp(k)*error(k)+kd(k)*derror(k)+ki(k)*ei;
%延迟,参数更新
u_2 = u_1;
u_1 = u(k);
y_2 = y_1;
y_1 = y(k);
error_1 = error(k);
end
if SEL == 0
save pidr1.mat time yd y
end
if SEL == 1
save pidr2.mat time yd y
end
axes(handles.axes1);
plot(time,kp,'r');
xlabel('time(s)');
ylabel('kp');
axes(handles.axes3);
plot(time,kd,'r');
xlabel('time(s)');
ylabel('kd');
axes(handles.axes4);
plot(time,ki,'r');
xlabel('time(s)');
ylabel('ki');
axes(handles.axes2);
cla reset
plot(time,yd,'r',time,y,'k:','linewidth',2);
xlabel('time(s)');
ylabel('Position signal');
legend('Ideal position signal','Position tracking');
t1 = (max(y)-mean(yd))/mean(yd);
msgbox(['Over adjust: ',num2str(100*t1),'%',' Kp,Ki,Kd is: ',num2str(kp(end)),'; ',num2str(ki(end)),'; ',num2str(kd(end))]);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
cla reset
load pidr1.mat
plot(time,y,'r:');
xlabel('time(s)');
ylabel('Position signal');
hold on
load pidr2.mat
plot(time,y,'b:');
xlabel('time(s)');
ylabel('Position signal');
legend('initial kpkikd','adpative kpkikd');
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
标签:控制器,end,PID,handles,hObject,matlab,time
From: https://blog.51cto.com/matworld/6248020