Fuzzypid Se Imprime

Embed Size (px)

Citation preview

  • 7/27/2019 Fuzzypid Se Imprime

    1/8

    function varargout = GUIFUZZYPID(varargin)% GUIFUZZYPID MATLAB code for GUIFUZZYPID.fig% GUIFUZZYPID, by itself, creates a new GUIFUZZYPID or raises the existing% singleton*.%% H = GUIFUZZYPID returns the handle to a new GUIFUZZYPID or the handle to% the existing singleton*.%% GUIFUZZYPID('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in GUIFUZZYPID.M with the given input arguments.%% GUIFUZZYPID('Property','Value',...) creates a new GUIFUZZYPID or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before GUIFUZZYPID_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to GUIFUZZYPID_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 GUIFUZZYPID

    % Last Modified by GUIDE v2.5 21-Apr-2012 16:21:04

    % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...

    'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @GUIFUZZYPID_OpeningFcn, ...'gui_OutputFcn', @GUIFUZZYPID_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);

    if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});

    end

    if nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

    elsegui_mainfcn(gui_State, varargin{:});

    end% End initialization code - DO NOT EDIT

    % --- Executes just before GUIFUZZYPID is made visible.function GUIFUZZYPID_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 GUIFUZZYPID (see VARARGIN)

    % Choose default command line output for GUIFUZZYPIDhandles.output = hObject;

    % Update handles structureguidata(hObject, handles);

  • 7/27/2019 Fuzzypid Se Imprime

    2/8

    %Colocar Imagen de fondo 1background = imread('background3.jpg'); %Leer imagenaxes(handles.background); %Carga la imagen en backgroundaxis off;imshow(background); %Presenta la imagen% Choose default command line output for Sumadorahandles.output = hObject;% Update handles structureguidata(hObject, handles);axes(handles.logo)background = imread('espe.jpg');axis off;imshow(background);% UIWAIT makes GUIFUZZYPID wait for user response (see UIRESUME)% uiwait(handles.figure1);

    % --- Outputs from this function are returned to the command line.function varargout = GUIFUZZYPID_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 structurevarargout{1} = handles.output;

    % --- Executes on slider movement.function slider1_Callback(hObject, eventdata, handles)% hObject handle to slider1 (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,'Value') returns position of slider% get(hObject,'Min') and get(hObject,'Max') to determine range of sliderglobal value;

    value=get(hObject,'Value');handles.valsp=value;text=handles.valsp;main=(handles.valorsp);if (ishandle(main))

    mainHandles=guidata(main);ysp=mainHandles.valorsp;set(ysp,'String',text);

    end

    % --- Executes during object creation, after setting all properties.function slider1_CreateFcn(hObject, eventdata, handles)% hObject handle to slider1 (see GCBO)

    % eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called

    % Hint: slider controls usually have a light gray background.if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

    set(hObject,'BackgroundColor',[.9 .9 .9]);end

  • 7/27/2019 Fuzzypid Se Imprime

    3/8

    function valorsp_Callback(hObject, eventdata, handles)% hObject handle to valorsp (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 valorsp as text% str2double(get(hObject,'String')) returns contents of valorsp as a double

    % --- Executes during object creation, after setting all properties.function valorsp_CreateFcn(hObject, eventdata, handles)% hObject handle to valorsp (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 valore_Callback(hObject, eventdata, handles)% hObject handle to valore (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 valore as text% str2double(get(hObject,'String')) returns contents of valore as a double

    % --- Executes during object creation, after setting all properties.

    function valore_CreateFcn(hObject, eventdata, handles)% hObject handle to valore (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 valorkp_Callback(hObject, eventdata, handles)% hObject handle to valorkp (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 valorkp as text% str2double(get(hObject,'String')) returns contents of valorkp as a double

  • 7/27/2019 Fuzzypid Se Imprime

    4/8

    % --- Executes during object creation, after setting all properties.function valorkp_CreateFcn(hObject, eventdata, handles)% hObject handle to valorkp (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 valorkd_Callback(hObject, eventdata, handles)% hObject handle to valorkd (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 valorkd as text% str2double(get(hObject,'String')) returns contents of valorkd as a double

    % --- Executes during object creation, after setting all properties.function valorkd_CreateFcn(hObject, eventdata, handles)% hObject handle to valorkd (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 valorki_Callback(hObject, eventdata, handles)% hObject handle to valorki (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 valorki as text% str2double(get(hObject,'String')) returns contents of valorki as a double

    % --- Executes during object creation, after setting all properties.function valorki_CreateFcn(hObject, eventdata, handles)% hObject handle to valorki (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,'defaultUicontrolBackgr

  • 7/27/2019 Fuzzypid Se Imprime

    5/8

    oundColor'))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)AHORA=str2double(get(handles.valorsp,'String'))

    %close all;clc;delete(instrfindall)

    %% CONFIGURACIN COMINICACIN SERIAL

    PS=serial('COM4'); % puerto serial utilizado

    set(PS,'Baudrate',9600); % se configura la velocidad a 9600 Baudiosset(PS,'StopBits',1); % se configura bit de parada a unoset(PS,'DataBits',8); % se configura que el dato es de 8 bits, debe estar entre 5 y 8

    set(PS,'Parity','none'); % se configura sin paridadset(PS,'Terminator','CR/LF'); % c caracter con que finaliza el envoset(PS,'OutputBufferSize',1); % n es el nmero de bytes a enviarset(PS,'InputBufferSize' ,1); % n es el nmero de bytes a recibirset(PS,'Timeout',5); % 5 segundos de tiempo de esperafopen(PS);disp('AHORA PAP, YA LE DISTE!!!')set_point=AHORA;

    %% DECLARACIN DE CONSTANTES

    T=0.1;

    Ki=0.001;

    Kpmax=0.5;Kpmin=0.1;Kdmax=0.001;Kdmin=0.00001;

    max=100;min=0;i0=0;e0=0;

    aux=set_point;muestra=0;ut=0;ut0=0;i=0;LUMINOSIDAD=0;TIEMPO=0;SET=0;ERROR=0;ERROR_DER=0;

  • 7/27/2019 Fuzzypid Se Imprime

    6/8

    SALIDA=[];envio=0;

    lum_actual=fread(PS,1, 'char'); %leo el puerto y almaceno

    %% M6UESTREO DE DATOS Y CONTROL PID

    while(1)AHORA = round(get(handles.slider1,'Value'));set_point=AHORA;

    muestra=muestra+1;time=muestra*T;fwrite(PS,envio);pause(0.01);ent_an=fread(PS,1, 'char')/51 %leo el puerto y almacenolum_actualec=1.6901*ent_an^4-24.205*ent_an^3+130.49*ent_an^2-325.09*ent_an+3

    34.59;

    LUMINOSIDAD(muestra)=lum_actualec;TIEMPO(muestra)=time;SET(muestra)=set_point;

    axes(handles.axes3);plot(TIEMPO,LUMINOSIDAD)hold onplot(TIEMPO,SET,'r')limitemax=time;title('CONTROL PID DE LUMINOSIDAD');if time>5rango= time-4.6;

    elseif (time

  • 7/27/2019 Fuzzypid Se Imprime

    7/8

    ERROR_DER(muestra)=(e-e0)/T;% axes(handles.axes4);% plot(TIEMPO,ERROR)% hold on% title('ERROR EN EL CONTROL PID DE LUMINOSIDAD');% axis([0,time,0-10,80])% xlabel('Tiempo [s]');% ylabel('Error [%Lum]');% hold on%

    axes(handles.axes4);plot(TIEMPO,ERROR)hold onlimitemax=time;title('ERROR EN EL CONTROL PID DE LUMINOSIDAD');if time>5rango= time-4.6;

    elseif (timemax)

    ut=max;elseif (ut

  • 7/27/2019 Fuzzypid Se Imprime

    8/8

    end