%
%    TIMING - Plots timing information for control cycles.
%
%    MIT SeaGrant Lab
%
%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: timing.m,v 1.7 2001/01/04 00:18:31 rob Exp $

global titleStr;
global vehicleName;

if exist( 'h_tim' ) ~= 1
    h_tim = figure;
else
    figure( h_tim );
end

set( h_tim, 'name', [vehicleName,' Timing'], 'DeleteFcn', 'clear h_tim' );
set(gcf,'position',position)

time = dataDC(:,1);

subplot( 2, 1, 1 )
cla
m = size( time, 1 );
m1= size( dataNav(:,1), 1 );
[xx,yy] = stairs( time(1:m-1), diff(time) );
[xx1,yy1] = stairs( dataNav(1:m1-1), diff(dataNav(:,1)) );
plot( xx, yy*1000, xx1, yy1*1000 );
title( ['Backdifference of Time-Stamps: ' titleStr] );
%axis([0 max(time) 0 400])
ylabel( 'Duration (ms)' );
xlabel( 'Elapsed Time (s)' );
zoom on
grid on
if exist('dataSim') == 1
  m2= size( dataSim(:,1), 1 );
  [xx2,yy2] = stairs( dataSim(1:m2-1), diff(dataSim(:,1)) );
  line( xx2, yy2*1000, 'color','c' );
  legend('Control','Navigation','Sim')
else
  legend('Control','Navigation')
end

if exist('dataTC') == 1
  subplot(2,1,2)
  m2= size( dataTC(:,1), 1 );
  [xx2,yy2] = stairs( dataTC(1:m2-1), diff(dataTC(:,1)) );
  plot( xx2, yy2,'r');
  ylabel( 'Duration, Seconds' );
  xlabel( 'Elapsed Time (s)' );
  title('Backdifference of Time-Stamps in Tailcone Log')
  zoom on
  grid on
end






if 0
subplot( 2, 2, 3 )
cla
plot( time, 'r' );
title( 'Time Evolution' );
ylabel( 'Seconds' );
xlabel( 'Control Cycle' );
zoom on
grid on

subplot( 2, 2, 4 )
cla
plot( time, time - (0:m-1)'/5, 'c' );
title( 'Cumulative Overrun' );
ylabel( 'tardiness (s)' );
xlabel( 'elapsed time (s)' );
zoom on
grid on

end