% -----------------------------------------------------------------------------
% ExtractStride.m
% -----------------------------------------------------------------------------
%
%  This script extracts one stride from spatial hexapod simulation data 
% and returns the associated SLIP coordinate trajectories.
%
% -----------------------------------------------------------------------------
%
%   function slipdata = ExtractStride( hexdata, stridenum );
%
% -----------------------------------------------------------------------------
%  Input Arguments :
%
%   hexdata   : The trajectory data as returned by LoadSimSectData() on the
%               spatial hexapod data output.
%   stridenum : The desired strude number
%
% -----------------------------------------------------------------------------
%  Outputs :
%
%   slipdata : Struct holding the SLIP trajectory data corresponding to the
%              extracted stride. The fields are as follows:
%
%        slipdata.t     : time
%        slipdata.y     : forward position
%        slipdata.z     : height
%        slipdata.ydot  : forward velocity
%        slipdata.zdot  : vertical velocity
%        slipdata.chart : chart
%        slipdata.tdpsi : touchdown angle
%        slipdata.tdxi  : touchdown length
%
%        slipdata.touchdown : Index of touchdown point
%        slipdata.bottom    : Index of bottom point
%        slipdata.liftoff   : Index of liftoff point
%        slipdata.apex      : Index of apex point
%    
% -----------------------------------------------------------------------------
% $Id: ExtractStride.m,v 1.1.1.1 2003/10/28 20:05:59 ulucs Exp $
% -----------------------------------------------------------------------------

function slipdata = ExtractStride( hexdata, stridenum );

indices = FindHexPoints( hexdata );

if ( stridenum > 0 )
  touchdown = indices.touchdown( stridenum );
  bottom = indices.bottom( stridenum );
  liftoff = indices.liftoff( stridenum );
  apex = indices.apex( stridenum );
elseif ( stridenum < 0 )
  touchdown = indices.touchdown( end + stridenum-1 );
  bottom = indices.bottom( end + stridenum-1 );
  liftoff = indices.liftoff( end + stridenum-1 );
  apex = indices.apex( end + stridenum );
else
  error('Invalid stride number!' );
end

slipdata.t = hexdata.time(touchdown:apex);
slipdata.y = hexdata.slipy(touchdown:apex);
slipdata.z = hexdata.slipz(touchdown:apex);
slipdata.ydot = hexdata.slipydot(touchdown:apex);
slipdata.zdot = hexdata.slipzdot(touchdown:apex);
slipdata.chart = hexdata.slipmode(touchdown:apex);
slipdata.tdpsi = hexdata.psicmd(touchdown);
slipdata.tdxi = hexdata.xicmd(touchdown);
slipdata.touchdown = 1;
slipdata.bottom = 1 + bottom - touchdown;
slipdata.liftoff = 1 + liftoff - touchdown;
slipdata.apex = 1 + apex - touchdown;

