⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pid_controller.m

📁 This software is developed to provide ease with controller design. For PID control, options are give
💻 M
📖 第 1 页 / 共 5 页
字号:
        
     if tf_pushbutton == get(handles.tf_radiob,'Max')
   
        global sys_tf
        PID = value_dou + value_tfpi + value_tfpd;
        sys_final_PID = sys_tf * PID;
        global sys_fd_PID
        sys_fd_PID = feedback(sys_final_PID,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);
        PID = value_dou + value_tfpi + value_tfpd;
        sys_final_PID = sys_tf_ss * PID;
        global sys_fd_PID
        sys_fd_PID = feedback(sys_final_PID,1);    
    end

    [s t]= step(sys_fd_PID);
    axes(handles.axes6)
    plot(t,s),grid on
    set(handles.CLSR_text,'String','PID Controller');
    
    [s t]= step(sys_final_PID);
    axes(handles.axes5)
    plot(t,s),grid on
    set(handles.OLSR_text,'String','PID Controller');
               
    
end
% --------------------------------------------------------------------
function SRWC_Callback(hObject, eventdata, handles)
% hObject    handle to SRWC (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
    step(sys_tf),title('Step Response 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
    step(sys_ss),title('Step Response Without Controller'),grid on
end

% --------------------------------------------------------------------
function IRWC_Callback(hObject, eventdata, handles)
% hObject    handle to IRWC (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
    Impulse(sys_tf),title('Impulse Response 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
    impulse(sys_ss),title('Impulse Response Without Controller'),grid on
end
% --------------------------------------------------------------------
function PZMWC_Callback(hObject, eventdata, handles)
% hObject    handle to PZMWC (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'); 

%================= 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
    pzmap(sys_tf),title('Pole Zero Map 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
    pzmap(sys_ss),title('Pole Zero Map Without Controller'),grid on
end
%=====================================================================


% --------------------------------------------------------------------
function SRC_Callback(hObject, eventdata, handles)
% hObject    handle to SRC (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,step(sys_fd_P),title('Step Response With Proportional Controller'),grid on
end

if value == 2
    global sys_fd_PI
    figure,step(sys_fd_PI),title('Step Response With Proportional Integral Controller'),grid on
end

if value == 3
    global sys_fd_PD
    figure,step(sys_fd_PD),title('Step Response With Proportional Derivative Controller'),grid on
end

if value == 4
    global sys_fd_PID
    figure,step(sys_fd_PID),title('Step Response With PID Controller'),grid on
end

% --------------------------------------------------------------------
function IRC_Callback(hObject, eventdata, handles)
% hObject    handle to IRC (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,impulse(sys_fd_P),title('Impulse Response With Proportional Controller'),grid on
end

if value == 2
    global sys_fd_PI
    figure,impulse(sys_fd_PI),title('Impulse Response With Proportional Integral Controller'),grid on
end

if value == 3
    global sys_fd_PD
    figure,impulse(sys_fd_PD),title('Impulse Response With Proportional Derivative Controller'),grid on
end

if value == 4
    global sys_fd_PID
    figure,impulse(sys_fd_PID),title('Impulse Response With PID Controller'),grid on
end

% --------------------------------------------------------------------
function PZMC_Callback(hObject, eventdata, handles)
% hObject    handle to PZMC (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,pzmap(sys_fd_P),title('Pole Zero Map With Proportional Controller'),grid on
end

if value == 2
    global sys_fd_PI
    figure,pzmap(sys_fd_PI),title('Pole Zero Map With Proportional Integral Controller'),grid on
end

if value == 3
    global sys_fd_PD
    figure,pzmap(sys_fd_PD),title('Pole Zero Map With Proportional Derivative Controller'),grid on
end

if value == 4
    global sys_fd_PID
    figure,pzmap(sys_fd_PID),title('Pole Zero Map With PID Controller'),grid on
end

% --------------------------------------------------------------------
function BPWC_Callback(hObject, eventdata, handles)
% hObject    handle to BPWC (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
    bode(sys_tf),title('Bode Diagram 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');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -