%    VPLANE - script to plot depth and pitch control parameters in
%    subplots of one large window.
%
%    B. A. Moran, 16-Jun-1995

%    Copyright (C) 1995-1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: vplane.m,v 1.6 1998/05/15 15:01:41 bamoran Exp $	

global run_name

if exist( 'h_dpt' ) ~= 1
    h_dpt = figure;
    if strcmp( computer, 'SGI' )
	winpos( [200*rand 200*rand 1024 768] );
    else
	winpos( position(1,:) );
    end
else 
    h_dpt = figure( h_dpt ); 
end
    
set( h_dpt, 'name', 'Odyssey II Depth Control', 'DeleteFcn', 'clear h_dpt' );
set( h_dpt, 'color','w','position',[10 300 600 800]);

rows = 1:length(data);
if diff(data(1:2,c_depth)) > .5
    rows(1) = [];
end

subplot( 2, 1, 1 )
cla
[xx,yy] = stairs( data(rows,m_present_time), data(rows,c_depth) );
plot( data(rows, m_present_time), data(rows,m_depth), xx, yy );
if exist( 't_depth' ) == 1
    colors = get( gca, 'ColorOrder' );
    [xx,yy] = stairs( data(rows,m_present_time), data(rows,t_depth) );
    line( xx, yy, 'Color', colors(3,:) );
end
grid
set( gca, 'ydir', 'reverse' );
set(gca,'Ylim',[0 21],'fontweight','bold');
title( ['Commanded and Measured Depth: ' run_name] );
ylabel( 'depth (m)' );
legend('c depth','m depth','t depth');
% zoom on

subplot( 2, 1, 2 )
cla
[xx,yy] = stairs( time, data(:,c_pitch)*180/pi );
plot( time, data(:,m_pitch)*180/pi, xx, yy );
set(gca,'fontweight','bold'); 
if exist( 'd_integral' ) == 1
    line( time, data(:,d_integral)*180/pi, 'Color', colors(4,:) );
    title( 'Commanded & Measured Pitch, Depth Integral' )
else
    title( 'Commanded and Measured Pitch' );    
end

ylabel( 'pitch (deg)' );
set(gca,'ylim',[-50 50]); grid
zoom on

xlabel( 'elapsed time (s)' );
subplot( 4, 1, 4 )
cla
pctrl

clear rows xx yy colors
