Run a linearized simulation of the OH6A.

------------------------------------------------------------------------
See also StateSpacePlot, DrawAC, HUD, HUDCntrl, OH6A, CToD,
PropStateSpace, Eul2Q, QTForm, TimeGUI
------------------------------------------------------------------------

Contents

%--------------------------------------------------------------------------
%  Copyright (c) 1997-1999 Princeton Satellite Systems, Inc.
%  All rights reserved.
%--------------------------------------------------------------------------

Global for the time GUI

%------------------------
global simulationAction
simulationAction = ' ';

Global for the HUD

%-------------------
global hUDOutput
hUDOutput = struct('pushbutton1',0,'pushbutton2',0,'checkbox1',0,...
                   'checkbox2',0,'checkbox3',0);

The OH6A state space model

%---------------------------
g = OH6A;

disp('Eigenvalues')
eig(get(g,'a'))
Eigenvalues
ans =
      -4.9262 +          0i
      -2.0103 +          0i
     -0.82094 +          0i
     0.014268 +    0.51232i
     0.014268 -    0.51232i
  -0.00013746 +    0.40823i
  -0.00013746 -    0.40823i
      -0.2294 +          0i

Create a z transform model

%---------------------------
g = CToD( g, 0.01, 'zoh' );

Initial state vector

%---------------------
x    = [1;0;0;0;0;0;0;0];

HUD state vector

%-----------------
xHUD.v = x(1:3);
xHUD.h = 0;
xHUD.e = [x([8 4]);0];

Set up the HUD

%---------------
dHUD.atmData  = load('AtmData.txt');
dHUD.atmUnits = 'eng';
dHUD.type     = 'helicopter';

Initial control values

%-----------------------
cHUD.control.collective         = 0;
cHUD.control.longitudinalCyclic = 0;
cHUD.control.lateralCyclic      = 0;
cHUD.control.rudder             = 0;
cHUD.control.throttle           = 0;

Control ranges

%---------------
cHUD.collectiveMax              = pi/2;
cHUD.longitudinalCyclicMax      = pi/2;
cHUD.lateralCyclicMax           = pi/2;
cHUD.rudderMax                  = pi/2;
cHUD.dT                         = get( g, 'dT' );

Initialize the HUD

%-------------------
hHUD = HUD( 'init', dHUD, xHUD, [], cHUD );

Initialize the plots

%---------------------
nSim    = 1000;
plots.x = 1:8;
plots.u	= 1:4;
plots.g = g;
dPlot   = StateSpacePlot( 'init', plots, nSim, nSim );

Initialize

%-----------
r = [0;0;1000];

gCobra = load('gCobra');
hCobra = DrawAC( 'init', gCobra, struct('r', r, 'q', [1;0;0;0]), [], dHUD.atmUnits);

Initialize the time display

%----------------------------
tToGoMem.lastJD        =  0;
tToGoMem.lastStepsDone =  0;
tToGoMem.kAve          =  0;
dT                     = get( g, 'dT' );
[ratioRealTime, tToGoMem] =  TimeGUI( nSim, 0, tToGoMem, 0, dT, 'OH6A Simulation' );

for k = 1:nSim

	% Display the status message
	%---------------------------
	[ratioRealTime, tToGoMem] = TimeGUI( nSim, k, tToGoMem, ratioRealTime, dT );

  % State information. The model does  not include all rotational states
  %---------------------------------------------------------------------
  v     = x([1 2 5]);
  e     = [x([8 4]);0];
  omega = [x([7 3]);0];

  % HUD information
  %----------------
  xHUD.v = v;
  xHUD.h = 0;
  xHUD.e = e;
  q      = Eul2Q( e );
  hHUD   = HUD( 'run', dHUD, xHUD, hHUD, cHUD );

  % Controls
  %---------
  u = [hHUD.control.longitudinalCyclic;...
       hHUD.control.collective;...
       hHUD.control.lateralCyclic;...
       hHUD.control.rudder];

  % Plotting
  %---------
  dPlot = StateSpacePlot( 'store', x, [], u, dPlot );

  % 3D Display
  %-----------
  hCobra = DrawAC( 'run', gCobra, struct( 'r', r, 'q', q ), hCobra, dHUD.atmUnits );

  % The simulation
  %---------------
	x = PropStateSpace( g, x, u );
  r = r + dT*QTForm( q, v ); % Simple Euler integration

  % Time control
  %-------------
  switch simulationAction
    case 'pause'
      pause
      simulationAction = ' ';
    case 'stop'
      return;
    case 'plot'
      break;
  end

  HUDCntrl;

end

Plot the results

%-----------------
StateSpacePlot( 'plot', dPlot );


%--------------------------------------