%
%    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.1 2000/01/10 19:08:37 rob Exp $	

global run_name;

if exist( 'h_tim' ) ~= 1
    h_tim = figure;
    winpos(position(1,:));
else 
    figure( h_tim );
end

set( h_tim, 'name', 'DorOdyssey Timing', 'DeleteFcn', 'clear h_tim' );

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: ' run_name] );
%axis([0 max(time) 0 400])
ylabel( 'Duration, milli-Sec.' );
xlabel( 'Elapsed Time Sec.' );
legend('Control','Navigation')
zoom on
grid on

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