% % SEM 5928 - Sistemas de Controle % Escola de Engenharia de São Carlos - USP % % Adriano Siqueira - 2016 % clear all close all %create graphic interface graph_interface = figure(... 'Unit','normalized',... 'NextPlot','add',... 'Visible','on',... 'NumberTitle','off',... 'Position',[0.01 0.1 0.95 0.8]); set(0,'Current',graph_interface); % the axis named 'movie' shows the motion of the manipulator movie_axis = axes(... 'Units','normalized',... 'Position',[.07 .25 0.4 .7],... 'XGrid','on',... 'YGrid','on'); xlabel('Tempos (s)'); ylabel('y(t)'); movie_axis2 = axes(... 'Units','normalized',... 'Position',[.54 .35 0.4 .6],... 'XGrid','on',... 'YGrid','on'); xlabel('Parte Real'); ylabel('parte Imaginaria'); % button to start the simulation uiStart = uicontrol(... 'Style','slider',... 'Units','normalized',... 'Position',[0.52 0.21 0.45 0.03],... 'Interruptible','on',... 'Max',50,... 'Min',0,... 'Value',1,... 'SliderStep',[.02 0.02],... 'Callback','Aula3_PID_update'); uitext = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.72 0.24 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','K = '); uitextK = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.74 0.24 0.1 0.03],... 'HorizontalAlignment','left',... 'BackgroundColor',[.8 .8 .8],... 'String','1'); uitext = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.52 0.24 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','0'); uitext = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.95 0.24 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','50'); lim1=200; uiStart1 = uicontrol(... 'Style','slider',... 'Units','normalized',... 'Position',[0.52 0.13 0.45 0.03],... 'Interruptible','on',... 'Max',lim1,... 'Min',0,... 'Value',0,... 'SliderStep',[.002 0.002],... 'Callback','Aula3_PID_update'); uitext = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.72 0.16 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','KI = '); uitextKI = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.74 0.16 0.1 0.03],... 'HorizontalAlignment','left',... 'BackgroundColor',[.8 .8 .8],... 'String','0'); uitext1 = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.52 0.16 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','0'); uitext1 = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.95 0.16 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String',num2str(lim1)); uiStart2 = uicontrol(... 'Style','slider',... 'Units','normalized',... 'Position',[0.52 0.05 0.45 0.03],... 'Interruptible','on',... 'Max',20,... 'Min',0,... 'Value',0,... 'SliderStep',[.002 0.002],... 'Callback','Aula3_PID_update'); uitext = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.72 0.08 0.03 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','KD = '); uitextKD = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.75 0.08 0.1 0.03],... 'BackgroundColor',[.8 .8 .8],... 'HorizontalAlignment','left',... 'String','0'); uitext2 = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.52 0.08 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','0'); uitext2 = uicontrol(... 'Style','text',... 'Units','normalized',... 'Position',[0.95 0.08 0.02 0.03],... 'BackgroundColor',[.8 .8 .8],... 'String','20'); selecionaG1 = [... 'if sist == 2,'... 'sist =1;'... 'n=10;'... 'd=conv([1 5],[1 10]);'... 'Gc =tf(n,d);'... 'end;'... 'set(uibotton1,''BackgroundColor'',[.6 .6 .6]);',... 'set(uibotton2,''BackgroundColor'',[.8 .8 .8]);',... 'Aula3_PID_update']; uibotton1 = uicontrol(... 'Style','push',... 'Units','normalized',... 'Position',[0.15 0.06 0.18 0.08],... 'BackgroundColor',[.8 .8 .8],... 'String','G(s) = 10/(s+5)(s+10)'); % selecionaG2 = [... % 'if sist == 1,'... % 'sist =2;'... % 'n=1;'... % 'd=conv([1 1],[1 5]);'... % 'd=conv(d,[1 0.01]);'... % 'Gc =tf(n,d);'... % 'end;'... % 'set(uibotton2,''BackgroundColor'',[.6 .6 .6]);',... % 'set(uibotton1,''BackgroundColor'',[.8 .8 .8]);',... % 'exemploPID']; % % uibotton2 = uicontrol(... % 'Style','push',... % 'Units','normalized',... % 'FontSize',12,... % 'Position',[0.25 0.06 0.18 0.08],... % 'BackgroundColor',[.8 .8 .8],... % 'String','G(s) = 1/s(s+1)(s+5)',... % 'Callback',selecionaG2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Sistema a ser controlado sist = 1; set(uibotton1,'BackgroundColor',[.6 .6 .6]); if sist == 1 n=10; d=conv([1 5],[1 10]); Gc =tf(n,d); elseif sist==2 n=1; d=conv([1 1],[1 5]); d=conv(d,[1 0]); end % n=60; % d=[1 35 0]; Gc =tf(n,d); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Leitura dos ganhos K = get(uiStart,'Value'); KI = get(uiStart1,'Value'); KD = get(uiStart2,'Value'); %Controlador P nPID1 = K; dPID1 = 1; DPID1 = tf(nPID1,dPID1); %Controlador I nPID2 = KI; dPID2 = [1 0]; DPID2 = tf(nPID2,dPID2); %Controlador D nPID3 = [KD 0]; dPID3 = 1; DPID3 = tf(nPID3,dPID3); DPID = DPID1+DPID2+DPID3; %sistema em malha fechada MFc = feedback(DPID*Gc,1); [y,t] = step(MFc,5); set(graph_interface,'CurrentAxes',movie_axis); plot(t,y) %axis([0 .1 0 max(y)]) grid xlabel('Tempos (s)'); ylabel('y(t)'); set(graph_interface,'CurrentAxes',movie_axis2); pzmap(MFc) hold on pzmap(Gc,'r') xlabel('Parte Real'); ylabel('Parte Imaginaria');