close all
clear all

size=14;

mo=load('degrauM14nocontrol_volt_posEff_kt0#-45;+45.txt');
mc=load('degrauM14kp=006_volt_posEff_controlReq#-45;+45.txt');
step=ones(length(mo),1)*45;
N=floor(length(mo)/2);

figure(2);
axes('fontsize',size);
plot(mo(1:N,1),step(1:N),'b',mo(1:N,1),mo(1:N,3),'m',mc(1:N,1),mc(1:N,3),'r',mc(1:N,1),mc(1:N,4),'g','linewidth',2);
grid on
xlabel('time (s)','fontsize',size);
ylabel('Position (degrees)','fontsize',size)
legend('Step requested','Open loop response','Closed loop response','Controller output signal','location','SouthEast');

figure(3)
eo=45-mo(:,3);
ec=45-mc(:,3);
axes('fontsize',size)
plot(mo(1:N,1),eo(1:N),'m',mc(1:N,1),ec(1:N),'r','linewidth',2);
grid on
xlabel('time (s)','fontsize',size);
ylabel('Position (degrees)','fontsize',size)
legend('Open loop response error','Closed loop response error','location','NorthEast');

figure(4)
mo=load('rampaM14nocontrol_posReq_posEff_kt0#-45;+45_dt100.txt');
mc=load('rampaM14kp=020_posReq_posEff_controlReq#-45;+45_dt100.txt');

N=floor(length(mo)*4/5);
axes('fontsize',size)
plot(mo(1:N,1),mo(1:N,2),'k',mo(1:N,1),mo(1:N,3),'b',mc(1:N,1),mc(1:N,3),'r',mc(1:N,1),mc(1:N,4),'m','linewidth',2);
grid on
xlabel('time (s)','fontsize',size);
ylabel('Position (degrees)','fontsize',size)
%legend('Ramp requested','Open loop response','Closed loop response','Controller output signal','location','SouthEast');

figure(5);
eo=mo(:,2)-mo(:,3);
ec=mc(:,2)-mc(:,3);
axes('fontsize',size)
plot(mo(1:N,1),eo(1:N),'b',mc(1:N,1),ec(1:N),'r','linewidth',2);
grid on
xlabel('time (s)');
ylabel('Error (degrees)','fontsize',size)
%legend('Open loop error','Closed loop error','location','NorthEast');
