close all
clear all



%filename = '../DecodedResults/Dailies/2025.11.06.mat';


%filename = '../DecodedResults/2026.04.16T14.05.15.mat';
%filename = '../DecodedResults/2025.12.10T10.59.44.mat';
%filename = '../DecodedResults/2025.12.10T11.44.49.mat';
%filename = '../DecodedResults/2025.12.10T11.50.32';

%filename = '../DecodedResults/Dailies/2025.12.10.mat';
%filename = '../DecodedResults/Dailies/2026.04.16.mat';

filename = '../DecodedResults/2026.04.16T15.41.59.mat';



%struct StatusBits {  
%    unsigned int PitchCosineMode : 1;
%    unsigned int RollCosineMode : 1;
%    unsigned int DeployRequest : 1;
%    unsigned int Deployed : 1; 
%};


load(filename);

II = 8;
figure
i = 1;
ah(i) = subplot(II,1,i);
plot(Time_DateNum,Status & 0b00000100,'-x');
hold all
plot(Time_DateNum,Status & 0b00001000,'-o');
title(filename);
legend('Deploy Request (Status bit 2)','Deployed (Status bit 3)');

datetick('x');

i = i+1;
ah(i) = subplot(II,1,i);
plot(Time_DateNum,IMU_data.pitch,'-x');
ylim([-100 10]);
ylabel('pitch');

datetick('x');

i = i+1;
ah(i) = subplot(II,1,i);
plot(Time_DateNum,IMU_data.roll,'-x');
ylabel('roll');
grid on;
datetick('x');

i = i+1;
ah(i) = subplot(II,1,i);
if(exist('VN100_n','var'))
  plot(Time_DateNum,VN100_n,'-x');
else
  plot(Time_DateNum,NaN(size(Time_DateNum)));
end
ylabel('VN100_n');
grid on;
datetick('x');


i = i+1;
ah(i) = subplot(II,1,i);
if(exist('VN100_ret','var'))
  plot(Time_DateNum,VN100_ret,'-x');
else
  plot(Time_DateNum,NaN(size(Time_DateNum)));
end
ylabel('VN100_ret');
grid on;
datetick('x');


i = i+1;
ah(i) = subplot(II,1,i);
plot(Time_DateNum,PitchCmd,'-x');
ylabel('PitchCmd');
grid on;
datetick('x');

i = i+1;
ah(i) = subplot(II,1,i);
plot(Time_DateNum,RollCmd,'-x');
ylabel('RollCmd');
grid on;
datetick('x');

i = i+1;
ah(i) = subplot(II,1,i);
plot(Time_DateNum(2:end),PitchTarget(2:end)-IMU_data.pitch(2:end),'-x');
ylabel('PitchError');
grid on;
datetick('x');
ylim([-100 100]);


linkaxes(ah,'x');