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

📄 calcul_pidanalogique.m

📁 比较专业的PID控制器
💻 M
📖 第 1 页 / 共 3 页
字号:
function varargout = calcul_PIDanalogique(varargin)

% CALCUL_PIDANALOGIQUE M-file for calcul_PIDanalogique.fig
%      CALCUL_PIDANALOGIQUE, by itself, creates a new CALCUL_PIDANALOGIQUE or raises the existing
%      singleton*.
%
%      H = CALCUL_PIDANALOGIQUE returns the handle to a new CALCUL_PIDANALOGIQUE or the handle to
%      the existing singleton*.
%
%      CALCUL_PIDANALOGIQUE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CALCUL_PIDANALOGIQUE.M with the given input arguments.
%
%      CALCUL_PIDANALOGIQUE('Property','Value',...) creates a new CALCUL_PIDANALOGIQUE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before calcul_PIDanalogique_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to calcul_PIDanalogique_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help calcul_PIDanalogique

% Last Modified by GUIDE v2.5 18-Apr-2004 15:37:16
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @calcul_PIDanalogique_OpeningFcn, ...
                   'gui_OutputFcn',  @calcul_PIDanalogique_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before calcul_PIDanalogique is made visible.
function calcul_PIDanalogique_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to calcul_PIDanalogique (see VARARGIN)

% Choose default command line output for calcul_PIDanalogique
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes calcul_PIDanalogique wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = calcul_PIDanalogique_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.function t_CreateFcn(hObject, eventdata, handles)% hObject    handle to t (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction t_Callback(hObject, eventdata, handles)% hObject    handle to t (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 t as text%        str2double(get(hObject,'String')) returns contents of t as a double
t = str2double(get(hObject, 'String'));
if isnan(t)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

data = getappdata(gcbf, 'metricdata');
data.t = t;
setappdata(gcbf, 'metricdata', data);% --- Executes during object creation, after setting all properties.function k_CreateFcn(hObject, eventdata, handles)% hObject    handle to k (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction k_Callback(hObject, eventdata, handles)% hObject    handle to k (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)
k = str2double(get(hObject, 'String'));% Hints: get(hObject,'String') returns contents of k as text%        str2double(get(hObject,'String')) returns contents of k as a double
if isnan(k)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

data = getappdata(gcbf, 'metricdata');
data.k = k;
setappdata(gcbf, 'metricdata', data);% --- Executes during object creation, after setting all properties.function theta_CreateFcn(hObject, eventdata, handles)% hObject    handle to theta (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    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end
function theta_Callback(hObject, eventdata, handles)% hObject    handle to theta (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)theta = str2double(get(hObject, 'String'));% Hints: get(hObject,'String') returns contents of theta as text%        str2double(get(hObject,'String')) returns contents of theta as a double
if isnan(theta)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

data = getappdata(gcbf, 'metricdata');
data.theta = theta;
setappdata(gcbf, 'metricdata', data);% --- Executes on button press in calcul.function calcul_Callback(hObject, eventdata, handles)% hObject    handle to calcul (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)clc

% clear all
% close all

data = getappdata(gcbf, 'metricdata');
%*****************%
%*Ziegler Nichols*%
%*****************%

 
if get(handles.ziegler, 'Value')
    kc_zigler =1.2*data.t/(data.theta*data.k);
    Ti_zigler = 2*data.theta;
    Td_zigler = 0.5*data.theta;
    set(handles.kc, 'String', kc_zigler);
     set(handles.ti, 'String', Ti_zigler); 
     set(handles.td, 'String', Td_zigler);
end
%******************%
%****Cohen Coon****%
%******************%
if get(handles.cohen, 'Value')
    kc_cohen = (16*data.t+3*data.theta)/(12*data.k*data.theta);
    Ti_cohen = data.theta*(32+6*data.theta/data.t)/(13+8*data.theta/data.t);
    Td_cohen = 4*data.theta/(11+20*data.theta/data.t);
    set(handles.kc, 'String', kc_cohen);
     set(handles.ti, 'String', Ti_cohen); 
     set(handles.td, 'String', Td_cohen);
end
%****************%
%**REGLABILITEE**%
%****************%
if get(handles.reglab, 'Value')
    rc = data.theta/data.t;
    if  ((rc >= 0) & (rc < 0.1))
        kp_regla = 5/data.k ;   
        Ti_regla = data.t;
        Td_regla = 0;
        set(handles.kc, 'String', kp_regla);
        set(handles.ti, 'String', Ti_regla); 
        set(handles.td, 'String', Td_regla);
    elseif ((rc >= 0.1) & (rc < 0.2))
        kp_regla = 0.5/(data.k*rc);
        Ti_regla = data.t;
        Td_regla = 0;
        set(handles.kc, 'String', kp_regla);
        set(handles.ti, 'String', Ti_regla); 
        set(handles.td, 'String', Td_regla);
    elseif ((rc >= 0.2) & (rc < 0.5))
        kp_regla = 0.5*(1+0.5*rc)/(data.k*rc)
        Ti_regla = data.t*(1+0.5*rc)
        Td_regla = data.t*0.5*rc/(0.5*rc+1)
        set(handles.kc, 'String', kp_regla);
        set(handles.ti, 'String', Ti_regla); 
        set(handles.td, 'String', Td_regla);
    else
        disp(                   '****************************************************')
        disp(                   '*************** IL FAUT QUE: ***********************')
        disp(                   '*                  theta                           *')
        disp(                   '***    0 <= ---------------------------- <= 0.5  ***')
        disp(                   '*                    T                             *')
        disp(                   '****************************************************')
        disp(                   '****************************************************')
        set(handles.kc, 'String', 0);
        set(handles.ti, 'String', 0); 
        set(handles.td, 'String', 0);
    end
end
%***************************%
%**OPTIMISATION DE CRITERE**%
%***************************%
if get(handles.optim, 'Value')
   

    
    %regulateur
    %**********************
    %asservissement
    %**********************
    if get(handles.ass, 'Value')
            %a
            Asservissement(1).ise  = 1.26239;
            Asservissement(1).iae  = 1.13031;
            Asservissement(1).itae = 0.98384;
            %b
            Asservissement(2).ise  = -0.83880;
            Asservissement(2).iae  = -0.81314;
            Asservissement(2).itae = -0.49851;
            %c
            Asservissement(3).ise  = 6.03560;
            Asservissement(3).iae  = 7.7527;
            Asservissement(3).itae = 2.71348;
            %d
            Asservissement(4).ise  = -6.0191;
            Asservissement(4).iae  = -5.7241;
            Asservissement(4).itae = -2.29778;
            %e
            Asservissement(5).ise  = 0.47617;
            Asservissement(5).iae  = 0.32175;
            Asservissement(5).itae = 0.21433;
            %f
            Asservissement(6).ise  = 0.24572;
            Asservissement(6).iae  = 0.17707;
            Asservissement(6).itae = 0.16768;
        if get(handles.ise, 'Value')
            %ISE
            kp_ass = Asservissement(1).ise*((data.theta/data.t)^Asservissement(2).ise)/data.k;
            Ti_ass = kp_ass*data.t/(Asservissement(3).ise+(data.theta/data.t)*Asservissement(4).ise);
            Td_ass = (data.t/kp_ass)*Asservissement(5).ise*(data.theta/data.t)^Asservissement(6).ise;
            set(handles.kc, 'String', kp_ass);
            set(handles.ti, 'String', Ti_ass); 
            set(handles.td, 'String', Td_ass);
        elseif get(handles.iae, 'Value')
            %IAE    
            kp_ass = Asservissement(1).iae*((data.theta/data.t)^Asservissement(2).iae)/data.k;
            Ti_ass = kp_ass*data.t/(Asservissement(3).iae+(data.theta/data.t)*Asservissement(4).iae);
            Td_ass = (data.t/kp_ass)*Asservissement(5).iae*(data.theta/data.t)^Asservissement(6).iae;
            set(handles.kc, 'String', kp_ass);
            set(handles.ti, 'String', Ti_ass); 
            set(handles.td, 'String', Td_ass);
        elseif get(handles.itae, 'Value')
            %ITAE
            kp_ass = Asservissement(1).itae*((data.theta/data.t)^Asservissement(2).itae)/data.k;
            Ti_ass = kp_ass*data.t/(Asservissement(3).itae+(data.theta/data.t)*Asservissement(4).itae);
            Td_ass = (data.t/kp_ass)*Asservissement(5).itae*(data.theta/data.t)^Asservissement(6).itae;
            set(handles.kc, 'String', kp_ass);
            set(handles.ti, 'String', Ti_ass); 
            set(handles.td, 'String', Td_ass);
        end
    end
    %**********************
    %Regulation
    %**********************
     if get(handles.regu, 'Value')
         %REGULATION
         %a
         Regulation(1).ise  = 1.3466;
         Regulation(1).iae  = 1.31509;
         Regulation(1).itae = 1.3176;

⌨️ 快捷键说明

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