clear all
close all

%help response_step

title1= 'Resposta ao degrau: -90º=> 0º, Carga=Vazio';
files1=['degrau-90;0_kp=1.2_kd=0.00_m0#volt_posEff_controlReq.txt',
        'degrau-90;0_kp=1.2_kd=0.10_m0#volt_posEff_controlReq.txt',
        'degrau-90;0_kp=1.2_kd=0.30_m0#volt_posEff_controlReq.txt',
        'degrau-90;0_kp=1.2_kd=0.50_m0#volt_posEff_controlReq.txt'];
label1=['Kp=1.2   Kd=0.00',
        'Kp=1.2   Kd=0.10',
        'Kp=1.2   Kd=0.30',
        'Kp=1.2   Kd=0.50'];
legend1=['Percurso COM controlo',
         'Pedido do controlador'];

title2= 'Resposta ao degrau: -45º=>+45º, Carga=Vazio';
files2=['degrau-45;+45_M0_nocontrol.txt                             ',
        'degrau-45;+45_m0_kp=0.06_kd=0.00#posF_posEff_controlReq.txt',
        'degrau-45;+45_m0_kp=0.06_kd=0.06#posF_posEff_controlReq.txt',
        'degrau-45;+45_m0_kp=0.10_kd=0.00#posF_posEff_controlReq.txt',
        'degrau-45;+45_M0_kp=0.10.txt                               ',
        'degrau-45;+45_M0_kp=0.15.txt                               '];
label2=['No control       ',
        'Kp=0.06   Kd=0.00',
        'Kp=0.06   Kd=0.06',
        'Kp=0.10   Kd=0.00',
        'Kp=0.10   Kd>0.00',
        'Kp=0.15   Kd=0.00'];
legend2=['Percurso SEM controlo',
         'Percurso COM controlo',
         'Pedido do controlador'];


f2=figure(2);
set(f2,'name',title2);

for i=1:size(files2,1)
    clear array;
    array=load(files2(i,:));
    
    subplot(3,2,i);
    if (i==1)
        array0=array;
        plot(array0(:,1),array0(:,3),'b');
    else
        plot(array0(:,1),array0(:,3),'b',...
             array(:,1),array(:,3),'r',array(:,1),array(:,4),'g');
    end
    
    xlabel(label2(i,:));
    ylabel('Posição (graus)');
    
    if (i==size(files2,1))
        legend(legend2,'location','northeast');
    end
end


f1=figure(1);
set(f1,'name',title1);
for i=1:size(files1,1)
    clear array;
    array=load(files1(i,:));
    
    subplot(2,2,i);
    plot(array(:,1),array(:,3),'b',array(:,1),array(:,4),'r');
    
    xlabel(label1(i,:));
    ylabel('Posição (graus)');
    
    if (i==size(files1,1))
        legend(legend1,'location','southeast');
    end
end
