📄 pid_controller.m
字号:
b_dou = str2num(b);
c= get(handles.C_edit,'String');
c_dou = str2num(c);
d= get(handles.D_edit,'String');
d_dou = str2num(d);
%================= Error If Either A,B,C or D is empty ================
if isempty(a_dou) || isempty(b_dou) || isempty(c_dou) || isempty(d_dou)
errordlg('Please enter all A,B,C and D');
end
sys_ss = ss(a_dou,b_dou,c_dou,d_dou);
figure
bode(sys_ss),title('Bode Diagram Without Controller'),grid on
end
%=====================================================================
% --------------------------------------------------------------------
function NPWC_Callback(hObject, eventdata, handles)
% hObject handle to NPWC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%====================== Values from Radio Button ======================
tf_pushbutton = get (handles.tf_radiob,'Value');
ss_pushbutton = get(handles.ss_radiob,'Value');
%================= Error If both were not Selected ===================
if ss_pushbutton == get(handles.ss_radiob,'Min') && tf_pushbutton == get(handles.tf_radiob,'Min')
errordlg('First Enter either "State Space" or "Transfer Function"');
end
%================= Implementing Transfer Function ====================
if tf_pushbutton == get(handles.tf_radiob,'Max') && ss_pushbutton == get(handles.ss_radiob,'Min')
num= get (handles.num_edit,'string');
num_dou = str2num(num);
den= get (handles.den_edit,'string');
den_dou = str2num(den);
%================= Error If Either Num or Den is empty ==============
if isempty(num_dou) || isempty(den_dou)
errordlg('Please Enter "Transfer Function"');
end
sys_tf = tf(num_dou,den_dou);
figure
nyquist(sys_tf),title('Nyquist Plot Without Controller'),grid on
end
%================= Implementing State Space Model ====================
if ss_pushbutton == get(handles.ss_radiob,'Max') && tf_pushbutton == get(handles.tf_radiob,'Min')
a= get(handles.A_edit,'String');
a_dou = str2num(a);
b= get(handles.B_edit,'String');
b_dou = str2num(b);
c= get(handles.C_edit,'String');
c_dou = str2num(c);
d= get(handles.D_edit,'String');
d_dou = str2num(d);
%================= Error If Either A,B,C or D is empty ==============
if isempty(a_dou) || isempty(b_dou) || isempty(c_dou) || isempty(d_dou)
errordlg('Please enter all A,B,C and D');
end
sys_ss = ss(a_dou,b_dou,c_dou,d_dou);
figure
nyquist(sys_ss),title('Nyquist Plot Without Controller'),grid on
end
%=====================================================================
% --------------------------------------------------------------------
function NCWC_Callback(hObject, eventdata, handles)
% hObject handle to NCWC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%====================== Values from Radio Button ======================
tf_pushbutton = get (handles.tf_radiob,'Value');
ss_pushbutton = get(handles.ss_radiob,'Value');
%================= Error If both were not Selected ===================
if ss_pushbutton == get(handles.ss_radiob,'Min') && tf_pushbutton == get(handles.tf_radiob,'Min')
errordlg('First Enter either "State Space" or "Transfer Function"');
end
%================= Implementing Transfer Function ====================
if tf_pushbutton == get(handles.tf_radiob,'Max') && ss_pushbutton == get(handles.ss_radiob,'Min')
num= get (handles.num_edit,'string');
num_dou = str2num(num);
den= get (handles.den_edit,'string');
den_dou = str2num(den);
%================= Error If Either Num or Den is empty ==============
if isempty(num_dou) || isempty(den_dou)
errordlg('Please Enter "Transfer Function"');
end
sys_tf = tf(num_dou,den_dou);
figure
nichols(sys_tf),title('Nichols Chat Without Controller'),grid on
end
%================= Implementing State Space Model ====================
if ss_pushbutton == get(handles.ss_radiob,'Max') && tf_pushbutton == get(handles.tf_radiob,'Min')
a= get(handles.A_edit,'String');
a_dou = str2num(a);
b= get(handles.B_edit,'String');
b_dou = str2num(b);
c= get(handles.C_edit,'String');
c_dou = str2num(c);
d= get(handles.D_edit,'String');
d_dou = str2num(d);
%================= Error If Either A,B,C or D is empty ==============
if isempty(a_dou) || isempty(b_dou) || isempty(c_dou) || isempty(d_dou)
errordlg('Please enter all A,B,C and D');
end
sys_ss = ss(a_dou,b_dou,c_dou,d_dou);
figure
nichols(sys_ss),title('Nichols Chat Without Controller'),grid on
end
%=====================================================================
% --------------------------------------------------------------------
function BPC_Callback(hObject, eventdata, handles)
% hObject handle to BPC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value = get(handles.PID_popupmenu,'Value');
if value == 1
global sys_fd_P
figure,bode(sys_fd_P),title('Bode Plot With Proportional Controller'),grid on
end
if value == 2
global sys_fd_PI
figure,bode(sys_fd_PI),title('Bode Plot With Proportional Integral Controller'),grid on
end
if value == 3
global sys_fd_PD
figure,bode(sys_fd_PD),title('Bode Plot With Proportional Derivative Controller'),grid on
end
if value == 4
global sys_fd_PID
figure,bode(sys_fd_PID),title('Bode Plot With PID Controller'),grid on
end
% --------------------------------------------------------------------
function NPC_Callback(hObject, eventdata, handles)
% hObject handle to NPC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value = get(handles.PID_popupmenu,'Value');
if value == 1
global sys_fd_P
figure,nyquist(sys_fd_P),title('Nyquist Plot With Proportional Controller'),grid on
end
if value == 2
global sys_fd_PI
figure,nyquist(sys_fd_PI),title('Nyquist Plot With Proportional Integral Controller'),grid on
end
if value == 3
global sys_fd_PD
figure,nyquist(sys_fd_PD),title('Nyquist Plot With Proportional Derivative Controller'),grid on
end
if value == 4
global sys_fd_PID
figure,nyquist(sys_fd_PID),title('Nyquist Plot With PID Controller'),grid on
end
% --------------------------------------------------------------------
function NCC_Callback(hObject, eventdata, handles)
% hObject handle to NCC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value = get(handles.PID_popupmenu,'Value');
if value == 1
global sys_fd_P
figure,nichols(sys_fd_P),title('Nichols ChartWith Proportional Controller'),grid on
end
if value == 2
global sys_fd_PI
figure,nichols(sys_fd_PI),title('Nichols Chart With Proportional Integral Controller'),grid on
end
if value == 3
global sys_fd_PD
figure,nichols(sys_fd_PD),title('Nichols Chart With Proportional Derivative Controller'),grid on
end
if value == 4
global sys_fd_PID
figure,nichols(sys_fd_PID),title('Nichols Chart With PID Controller'),grid on
end
% --------------------------------------------------------------------
function RLWC_Callback(hObject, eventdata, handles)
% hObject handle to RLWC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%====================== Values from Radio Button ======================
tf_pushbutton = get (handles.tf_radiob,'Value');
ss_pushbutton = get(handles.ss_radiob,'Value');
%================= Error If both Options Selected ====================
if ss_pushbutton == get(handles.ss_radiob,'Max') && tf_pushbutton == get(handles.tf_radiob,'Max')
errordlg('Select One Option from "State Space" or "Transfer Function"');
end
%================= Error If both were not Selected ===================
if ss_pushbutton == get(handles.ss_radiob,'Min') && tf_pushbutton == get(handles.tf_radiob,'Min')
errordlg('First Enter either "State Space" or "Transfer Function"');
end
%================= Implementing Transfer Function ====================
if tf_pushbutton == get(handles.tf_radiob,'Max') && ss_pushbutton == get(handles.ss_radiob,'Min')
num= get (handles.num_edit,'string');
num_dou = str2num(num);
den= get (handles.den_edit,'string');
den_dou = str2num(den);
%================= Error If Either Num or Den is empty ==============
if isempty(num_dou) || isempty(den_dou)
errordlg('Please Enter "Transfer Function"');
end
sys_tf = tf(num_dou,den_dou);
figure
rlocus(sys_tf),title('Root Locus Without Controller')
end
%================= Implementing State Space Model ====================
if ss_pushbutton == get(handles.ss_radiob,'Max') && tf_pushbutton == get(handles.tf_radiob,'Min')
a= get(handles.A_edit,'String');
a_dou = str2num(a);
b= get(handles.B_edit,'String');
b_dou = str2num(b);
c= get(handles.C_edit,'String');
c_dou = str2num(c);
d= get(handles.D_edit,'String');
d_dou = str2num(d);
%================= Error If Either A,B,C or D is empty ==============
if isempty(a_dou) || isempty(b_dou) || isempty(c_dou) || isempty(d_dou)
errordlg('Please enter all A,B,C and D');
end
sys_ss = ss(a_dou,b_dou,c_dou,d_dou);
figure
rlocus(sys_ss),title('Root Locus Without Controller'),grid on
end
% --------------------------------------------------------------------
function RLC_Callback(hObject, eventdata, handles)
% hObject handle to RLC (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value = get(handles.PID_popupmenu,'Value');
if value == 1
global sys_fd_P
figure,rlocus(sys_fd_P),title('Root Locus With Proportional Controller')
end
if value == 2
global sys_fd_PI
figure,rlocus(sys_fd_PI),title('Root Locus With Proportional Integral Controller')
end
if value == 3
global sys_fd_PD
figure,rlocus(sys_fd_PD),title('Root Locus With Proportional Derivative Controller')
end
if value == 4
global sys_fd_PID
figure,rlocus(sys_fd_PID),title('Root Locus With PID Controller')
end
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_3_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_4_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
% --- Executes on selection change in TAFR_popupmenu.
function TAFR_popupmenu_Callback(hObject, eventdata, handles)
% hObject handle to TAFR_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 TAFR_popupmenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from TAFR_popupmenu
% --- Executes during object creation, after setting all properties.
function TAFR_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to TAFR_popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -