%
% PURPOSE: Parameters for the Altex Simulink sim.  This file is called by 
%          run.m
%
  disp(' ')
  disp(' Altex Parameters:')
%
% Altex/Dorado Specific Constants:
%
  vel = 3.0*kph2mps;        % speed in m/s.  
  Tp  = 52;                 % Thrust in Newtons
  mass= 795;                % Mass; kg
  len = 4.19;               % Length; meters
  dia = 21*in2m;            % Diameter; meters
  xG  = 0;                  % Longitudinal CM offset in B, meters
  yG  = 0;                  % Lateral CM offset in B, meters
  zG  = .08;                % Vertical CM offset in B, meters. + is down.
  zG  = 0;                  % Vertical CM offset in B, meters. + is down.
  xB  = 0;                  % Longitudinal CB offset in B, meters
  yB  = 0;                  % Lateral CB offset in B, meters
  zB  = 0;                  % Vertical CB offset in B, meters.
  zB  = -.08;               % Vertical CB offset in B, meters.
  deltaBuoy= 0;             % Difference from neutral buoyancy, Newtons.
  Decouple = 0;             % Decouple the Surge EOM from Sway/Yaw
%
% Mission Configuration and Initial Conditions:
%
  vel_C_N_N_x = 0;          % Vel of the Current (C) wrto an Earth-Fixed 
  vel_C_N_N_y = 1*kph2mps;  %% Newtonian frame (N), coord in the N frame.
  vel_C_N_N_y = 0*kph2mps;  % No cross current
  r_No_WP1_N_x = 500;       % Dist from Earth-Fixed origin to first way point
  r_No_WP1_N_y = .85;       % Heading of .1 deg = .0017*500
  r_No_WP1_N_y = 10;        % 
  r_No_WP1_N_y = 500;       % 45 Deg.
  WpMode = 0;               % 0=> Waypoint control; 1 => heading control; 
  Heading = .1*d2r;         % This is overridden if WpMode=0.
  WpMode = 0;               % 0=> Waypoint control; 1 => heading control; 
  Heading = 179*d2r;        % This is overridden if WpMode=0.
  depthCmd = 10;            % meters; Commanded depth.
  u0    = vel;              % Initial Vehicle state, mks.
  v0    = 0.;
  w0    = 0.;
  p0    = 0.;
  q0    = 0.;
  r0    = 0.;
  x0    = 0.;
  y0    = 0.;
  z0    = 0.;
  phi0  = 0.;
  theta0= 0.;
  psi0  = 0.;
%
% Control System:
%
  Ts = .1;                  % Control System sampling rate, sec.    
  Kph = .7;                 % Unitless; Heading position gain
  Krh = 2;                  % Sec; w/o integrator; rate gain
  Kvh = 0;                  % sway rate feedback gain, rad/(meters/sec).
  MaxRate = .2 * Krh;       % Rad/sec
  Kwp = 0;                  % Rad/meter; should be > 0; Waypoint gain
  Kwp = .05;                % Rad/meter; should be > 0; Waypoint gain
  Kiwp= 0;                  % Rad/sec/meter; should be > 0. For integrator ver.
  Kiwp= .003;               % Rad/sec/meter; should be > 0. For integrator ver.
  Kpd     =  .08;           % Depth control gain; rad/meter
  Kid     = .005;           % Depth integral gain; rad/meter/sec
  MaxPitch= 15*pi/180;      % Max pitch angle requested by the depth controller.
  MaxDepthInt = 5*pi/180;   % Max pitch angle requested by the depth integrator.
  MaxPitchInt = 5*pi/180;   % Max pitch angle requested by the pitch integrator.
  Kpp     =  1.5;           % Pitch position gain
  Kdp     =  2.0;           % Pitch rate gain
  Kip     =  .05;           % Pitch integral gain
%
  if 1
%
% Gains from Acker:
%
%PP1 =  0.7683    0.9800    0.9800    0.9900    0.9900
%
  Kph = 0.814585;
  Krh = 2.051892;      
  Kvh = 0.078132;      
  Kwp = 0.061713;      
  Kiwp = 0.002108;    
%
  end
%
% Tailcone Specific Constants:
% NOTE: Assume that for Yaw/Pitch control purposes, the ring and struts have 
% the properties of an Odyssey fin, with 4 times the surface area.  For 
% the surge equation, use the total (approximate, of course) area.
%
  xPcp= -3*in2m;            % Distance from pivot to ring CP in tailcone coords
  xPR = -1.0*in2m;          % Dist from the elevator pivot to the rudder pivot.
  radius = 6*in2m;          % Perp. dist from tailcone CL to stator CP (??).
  r2 = sqrt(2);
  r_Ro_S1_R=[xPcp 0          -radius    ]';   % Dist from Ro to S1 in R, in -> m.
  r_Ro_S2_R=[xPcp -radius/r2 -radius/r2 ]';   % Dist from Ro to S1 in R, in -> m.
  r_Ro_S3_R=[xPcp -radius     0         ]';   % Dist from Ro to S1 in R, in -> m.
  r_Ro_S4_R=[xPcp -radius/r2  radius/r2 ]';   % Dist from Ro to S1 in R, in -> m.
  r_Ro_S5_R=[xPcp 0           radius    ]';   % Dist from Ro to S1 in R, in -> m.
  r_Ro_S6_R=[xPcp  radius/r2  radius/r2 ]';   % Dist from Ro to S1 in R, in -> m.
  r_Ro_S7_R=[xPcp  radius     0         ]';   % Dist from Ro to S1 in R, in -> m.
  r_Ro_S8_R=[xPcp  radius/r2 -radius/r2 ]';   % Dist from Ro to S1 in R, in -> m.
  aR  = 2.50*in2m;          % Dist from c.l. to rudder actuator base
  rR1 = 1.00*in2m;          % See notes 99/4/20 p.13.  Values from Mark's 
  rR2 = 2.50*in2m;          % diagrams, p.16-17.                          
  xRR = 11.5*in2m;          % Center-hole to center-hole act. dist. in P.  zz
  maxDeltaR = pi/12;        % Max tailcone deflection; 15 degrees.        
% maxDeltaRDot = 3*pi/180;  % Max tailcone deflection rate; 5 deg/sec.    
% deltaRDead = .01*in2m/rR2;% Rudder deadband; 10 "mils"; actu. & pin.    
% deltaRDead = maxDeltaRDot*Ts;% Max rudder displacement in one sample interval
  maxActDisp = 1*in2m*m2c;  % One inch max displacement; counts
  maxActRate = .5*in2m*m2c; % Max actuator rate; counts/sec.
  maxActDispTs = maxActRate*Ts;% Max actuator disp. in one sample interval
  iSB  =0;                  % Current to power stepper controller board.
%
  Stall = 30*d2r;           % Stall angle of the strut; Deg -> rad.
%
% Hydrodynamic coefficients for Odyssey Fins:
%
  Ar  = 4.26;               % Aspect ratio
  Cdc = 0.723;              % Crossflow Cd
  Cd0 = 0.0065;             % Cd from NACA 0015 section; PNA p. 503, 2nd Ed.
  Ef  = 0.90;               % "Oswald" efficiency factor; PNA p. 503, 2nd Ed.
  dCl = 3.392;              % Lift coefficient slope 
  StrutArea  = 0.0299;      % Odyssey fin area; m^2
  ControlArea = StrutArea;  % Equivalent rudder/elevator area (m^2). 
  LinCtrlArea = StrutArea*4;% Equivalent rudder/elevator area (m^2). For linear.m
  TotalArea = .47*pi*5*in2m + StrutArea*4;  % Ring + 4 struts;m^2. 
                                            % For drag calc in the Surge Eqn.
%
% Hydrodynamic coefficients for Knut's stator blades:
%
  span = 7*in2m;            % Span, m
  chord = 2.25*in2m;        % chord, m
  Ar  = span/chord;         % Aspect ratio
  Cdc = 0.81;               % Crossflow Cd
  Cd0 = 0.012;              % Cd, see PNA p. 503, 2nd Ed.
  Ef  = 0.90;               % "Oswald" efficiency factor; PNA p. 503, 2nd Ed.
  dCl = 6.28;               % Lift coefficient slope 
  StrutArea = span*chord;   % stator area; m^2
  ControlArea = StrutArea;  % Equivalent rudder/elevator area (m^2). 
%
% Hydrodynamic coefficients for Altex Ring:
%
  ArR  = 4.26;              % Aspect ratio
  CdcR = 0.723;             % Crossflow Cd
  Cd0R = 0.0065;            % Cd from NACA 0015 section; PNA p. 503, 2nd Ed.
  EfR  = 0.90;              % "Oswald" efficiency factor; PNA p. 503, 2nd Ed.
  dClR = 3.392;             % Lift coefficient slope 
  RingArea = StrutArea*2;   % Effective Ring Area; m^2
  LinCtrlArea = StrutArea*4;% Equivalent rudder/elevator area (m^2). For linear.m
%
% Hydrodynamic coefficients for Knut's duct.  Dia = 15 in, Chord = 5 in,
% and thickness = .75 in.
%
  ArR  = 4.26;              % Aspect ratio
  CdcR = 0.81;              % Crossflow Cd
  Cd0R = 0.010;             % Cd from NACA 0015 section; PNA p. 503, 2nd Ed.
  EfR  = 0.90;              % "Oswald" efficiency factor; PNA p. 503, 2nd Ed.
  dClR = 1.53;              % Lift coefficient slope 
  RingArea = pi*5*15*in2m^2;% Effective Ring Area; m^2
  LinCtrlArea = RingArea/2; % Equivalent rudder/elevator area (m^2). For linear.m
%
% Area used to compute drag coefficient Xuu.  See Eqn. 101, p 17; Notes.
%
  TotalArea = RingArea + StrutArea*8;  
%
% Open loop rudder commands:
  deltaR = 1*d2r;
  deltaR = 10*d2r;
  tdeltaR= 2;               % Rudder slew time
  tdur= 20;                 % Rudder slew time
%
% Sim Parameters:
  tStop = 2*60;             % Stop time, sec

