📄 pid_controller.m
字号:
set(handles.PTS_text,'String','Approximation Not Valid');
set(handles.STS_text,'String','Approximation Not Valid');
end
%==========================================================================
function num_edit_Callback(hObject, eventdata, handles)
% hObject handle to num_edit (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 num_edit as text
% str2double(get(hObject,'String')) returns contents of num_edit as a double
% --- Executes during object creation, after setting all properties.
function num_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to num_edit (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
function den_edit_Callback(hObject, eventdata, handles)
% hObject handle to den_edit (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 den_edit as text
% str2double(get(hObject,'String')) returns contents of den_edit as a double
% --- Executes during object creation, after setting all properties.
function den_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to den_edit (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 selection change in PID_popupmenu.
function PID_popupmenu_Callback(hObject, eventdata, handles)
% hObject handle to PID_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns PID_popupmenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from PID_popupmenu
% --- Executes during object creation, after setting all properties.
function PID_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to PID_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
function Kp_edit_Callback(hObject, eventdata, handles)
% hObject handle to Kp_edit (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 Kp_edit as text
% str2double(get(hObject,'String')) returns contents of Kp_edit as a double
% --- Executes during object creation, after setting all properties.
function Kp_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Kp_edit (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
function Ki_edit_Callback(hObject, eventdata, handles)
% hObject handle to Ki_edit (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 Ki_edit as text
% str2double(get(hObject,'String')) returns contents of Ki_edit as a double
% --- Executes during object creation, after setting all properties.
function Ki_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Ki_edit (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
function Kd_edit_Callback(hObject, eventdata, handles)
% hObject handle to Kd_edit (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 Kd_edit as text
% str2double(get(hObject,'String')) returns contents of Kd_edit as a double
% --- Executes during object creation, after setting all properties.
function Kd_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to Kd_edit (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 PID_pushb.
function PID_pushb_Callback(hObject, eventdata, handles)
% hObject handle to PID_pushb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%===== Values from Controller popup menu and Responses menu ===============
value = get(handles.PID_popupmenu,'Value');
%====================== Values from Radio Button ======================
ss_pushbutton = get (handles.ss_radiob,'Value');
tf_pushbutton = get (handles.tf_radiob,'Value');
%==================== Selecting Only Proportional Controller %===============
if value == 1
value_str = get(handles.Kp_edit,'String');
value_dou = str2num (value_str);
if tf_pushbutton == get(handles.tf_radiob,'Max');
global sys_tf
sys_final_P = sys_tf * value_dou;
global sys_fd_P
sys_fd_P = feedback(sys_final_P,1);
end
if ss_pushbutton == get(handles.ss_radiob,'Max')
%================= Error If Either A,B,C or D is empty ================
global a_dou b_dou c_dou d_dou
if isempty(a_dou) || isempty(b_dou) || isempty(c_dou) || isempty(d_dou)
errordlg('Please enter all A,B,C and D in correct format');
end
%======= Error If the State Space Model is not correct ================
[r1 c1] = size(a_dou);
[r2 c2] = size(c_dou);
[r3 c3] = size(b_dou);
[r4 c4] = size(d_dou);
if c1 ~= c2
errordlg('Please Enter Valid State Space Model');
end
if r1 ~= r3
errordlg('Please Enter Valid State Space Model');
end
if c3 ~= c4
errordlg('Please Enter Valid State Space Model');
end
%==================================================================
global a_dou b_dou c_dou d_dou
[num den] = ss2tf(a_dou, b_dou ,c_dou ,d_dou);
sys_tf_ss = tf(num,den);
sys_final_P = sys_tf_ss * value_dou;
global sys_fd_P
sys_fd_P = feedback(sys_final_P,1);
end
[s t]= step(sys_final_P);
axes(handles.axes5)
plot(t,s),grid on
set(handles.OLSR_text,'String','P Controller');
global sys_fd_P
[s t]= step(sys_fd_P);
axes(handles.axes6)
plot(t,s),grid on
set(handles.CLSR_text,'String','P Controller');
end
%==================== Selecting Proportional Integral Controller ===============
if value == 2
value_str = get(handles.Kp_edit,'String');
value_dou = str2num (value_str);
value_strPi = get(handles.Ki_edit,'String');
value_douPi = str2num (value_strPi);
value_tfpi = tf(value_douPi,[1 0]);
if tf_pushbutton == get(handles.tf_radiob,'Max')
global sys_tf
PI = value_dou + value_tfpi;
sys_final_PI = sys_tf * PI;
global sys_fd_PI
sys_fd_PI = feedback(sys_final_PI,1);
end
if ss_pushbutton == get(handles.ss_radiob,'Max')
%================= Error If Either A,B,C or D is empty ================
global a_dou b_dou c_dou d_dou
if isempty(a_dou) || isempty(b_dou) || isempty(c_dou) || isempty(d_dou)
errordlg('Please enter all A,B,C and D in correct format');
end
%======= Error If the State Space Model is not correct ================
[r1 c1] = size(a_dou);
[r2 c2] = size(c_dou);
[r3 c3] = size(b_dou);
[r4 c4] = size(d_dou);
if c1 ~= c2
errordlg('Please Enter Valid State Space Model');
end
if r1 ~= r3
errordlg('Please Enter Valid State Space Model');
end
if c3 ~= c4
errordlg('Please Enter Valid State Space Model');
end
%==================================================================
global a_dou b_dou c_dou d_dou
[num den] = ss2tf(a_dou, b_dou ,c_dou ,d_dou);
sys_tf_ss = tf(num,den);
PI = value_dou + value_tfpi;
sys_final_PI = sys_tf_ss * PI;
global sys_fd_PI
sys_fd_PI = feedback(sys_final_PI,1);
end
[s t]= step(sys_fd_PI);
axes(handles.axes6)
plot(t,s),grid on
set(handles.CLSR_text,'String','PI Controller');
[s t]= step(sys_final_PI);
axes(handles.axes5)
plot(t,s),grid on
set(handles.OLSR_text,'String','PI Controller');
end
%==================== Selecting Proportional Derivative Controller ===============
if value == 3
value_str = get(handles.Kp_edit,'String');
value_dou = str2num (value_str);
value_strPd = get(handles.Kd_edit,'String');
value_douPd = str2num (value_strPd);
value_tfpd = tf([value_douPd 0],1);
if tf_pushbutton == get(handles.tf_radiob,'Max')
global sys_tf
PD = value_dou + value_tfpd;
sys_final_PD = sys_tf * PD;
global sys_fd_PD
sys_fd_PD = feedback(sys_final_PD,1);
end
if ss_pushbutton == get(handles.ss_radiob,'Max')
%================= Error If Either A,B,C or D is empty ================
global a_dou b_dou c_dou d_dou
if isempty(a_dou) || isempty(b_dou) || isempty(c_dou) || isempty(d_dou)
errordlg('Please enter all A,B,C and D in correct format');
end
%======= Error If the State Space Model is not correct ================
[r1 c1] = size(a_dou);
[r2 c2] = size(c_dou);
[r3 c3] = size(b_dou);
[r4 c4] = size(d_dou);
if c1 ~= c2
errordlg('Please Enter Valid State Space Model');
end
if r1 ~= r3
errordlg('Please Enter Valid State Space Model');
end
if c3 ~= c4
errordlg('Please Enter Valid State Space Model');
end
%==================================================================
global a_dou b_dou c_dou d_dou
[num den] = ss2tf(a_dou, b_dou ,c_dou ,d_dou);
sys_tf_ss = tf(num,den);
PD = value_dou + value_tfpd;
sys_final_PD = sys_tf_ss * PD;
global sys_fd_PD
sys_fd_PD = feedback(sys_final_PD,1);
end
[s t]= step(sys_fd_PD);
axes(handles.axes6)
plot(t,s),grid on
set(handles.CLSR_text,'String','PD Controller');
[s t]= step(sys_final_PD);
axes(handles.axes5)
plot(t,s),grid on
set(handles.OLSR_text,'String','PD Controller');
end
%==================== Selecting PID Controller ===============
if value == 4
value_str = get(handles.Kp_edit,'String');
value_dou = str2num (value_str);
value_strPd = get(handles.Kd_edit,'String');
value_douPd = str2num (value_strPd);
value_tfpd = tf([value_douPd 0],1);
value_strPi = get(handles.Ki_edit,'String');
value_douPi = str2num (value_strPi);
value_tfpi = tf(value_douPi,[1 0]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -