function varargout = plist_init(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% DESCRIPTION - This function is intended for the generation of the plist to be used in the
% test_ltpda_acc_conv script for the testing of the conversion to
% acceleration scripts
% 
% CALL
%           [plHlfs, plHdf, plElAct, plThAct, plFreeDyn] = plist_init
% 
% 
% INPUT
%           - 'SAVE' if you input save the function save the plists in the
%           directory specified in 'DIR'
%           - 'DIR' defines the directory for saving the plists files in .xml
%           format the directory format is 'C:\Data\...\'
% 
% 
% OUTPUT
%           - plHlfs low frequency suspension circuit continous transfer
%           function
%           - plHdf drag free circuit continous transfer function
%           - plElAct list of parameters for the retarded electrical
%           actuation
%           - plThAct list of parameters for the thrusters retarded
%           actuation
%           - plFreeDyn list of parameters for the free dynamics
%           calculation
% 
% 
% 
% VERSION:     $Id: plist_init.m,v 1.1 2008/05/27 09:49:37 anneke Exp $
%
% 
% HISTORY:     23-04-2008 L Ferraioli
%                 Creation
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Standard history variables

ALGONAME = mfilename;
VERSION  = '$Id: plist_init.m,v 1.1 2008/05/27 09:49:37 anneke Exp $';
CATEGORY = '';

%% Finding inputs

saving = 0;
dir = 'C:\Dati\mock_data\plists\';

if length(varargin) > 0
    for j=1:length(varargin)
        if strcmp(varargin{j},'SAVE')
		    saving = 1;
        end
        if strcmp(varargin{j},'DIR')
		    dir = varargin{j+1};
        end
    end
end

%% Plists generation

% Continous transfer function of low frequency suspension the control circuit
NumHlfs = [-2.726e-007; 1.665e-005; 1.303e-007; 8.381e-010]; % Numerator
DenHlfs = [1; 0.2189; 0.01922; 0.0007803; 0]; % Denominator
tolHlfs = 1e-015; % Tolerance for the repeated roots

plHlfs = plist('NAME', 'Tfunc lfs circuit','NUMERATOR', NumHlfs, ...
    'DENOMINATOR', DenHlfs, 'RRTOLERANCE', tolHlfs, 'FS', 10, 'OUTPUT_OPTION', 'RESIDUE', 'MODE', 'SYM');

% Continous transfer function of the drag free control circuit
NumHdf = [0.0004659; 0.1349; 4.37; 0.8304; 0.07449; 0.002978; 4.403e-005]; % Numerator
DenHdf = [1; 5.046; 9.609; 11.05; 0.01221; 3.401e-006; 0]; % Denominator
tolHdf = 1e-015; % Tolerance for the repeated roots

plHdf = plist('NAME', 'Tfunc df circuit','NUMERATOR', NumHdf, ...
    'DENOMINATOR', DenHdf, 'RRTOLERANCE', tolHdf, 'FS', 10, 'OUTPUT_OPTION', 'RESIDUE', 'MODE', 'SYM');

% Parameters for the electrical actuation retarder response
tau_el = 0.01; % finite time response of the actuator in s
deltaT_el = 0.305; % Delay time introduced by the circuit in s
fs_el = 10; % data sampling frequency in Hz
tol_el = 1e-007; % Threshold for the filter length definition
Amp_el = 1; % Amplitude of the actuation response

plElAct = plist('NAME', 'electrical actuation parameters', 'TAU', ...
    tau_el, 'DELTAT', deltaT_el, 'FS', fs_el, 'TOL', tol_el, 'AMP', Amp_el);

% Parameters for the thrusters actuation retarder response
tau_th = 0.1; % finite time response of the actuator in s
deltaT_th = 0.315; % Delay time introduced by the circuit in s
fs_th = 10; % data sampling frequency in Hz
tol_th = 1e-007; % Threshold for the filter length definition
Amp_th = 1; % Amplitude of the actuation response

plThAct = plist('NAME', 'thrusters actuation parameters', 'TAU', ...
    tau_th, 'DELTAT', deltaT_th, 'FS', fs_th, 'TOL', tol_th, 'AMP', Amp_th);

% Free Dynamics Parameters
pstiff1 = -1.3e-006; % square of the parasitic stiffness on TM1
pstiff2 = -2e-006; % square of the parasitic stiffness on TM2
ctalk = -0.0001; % Cross talk coefficient

plFreeDyn = plist('NAME', 'Free Dyn Coeffs', 'pstiff1', pstiff1, ...
    'pstiff2', pstiff2, 'cross_talk', ctalk);

%% Saving plists if required

if saving
    save(plHlfs, [dir 'tf_coeffs_Hlfs_' date '.xml']);
    save(plHdf, [dir 'tf_coeffs_Hdf_' date '.xml']);
    save(plElAct, [dir 'el_act_params_' date '.xml']);
    save(plThAct, [dir 'th_act_params_' date '.xml']);
    save(plFreeDyn, [dir 'free_dyn_params_' date '.xml']);
end

%% Output plists

varargout{1} = plHlfs;
varargout{2} = plHdf;
varargout{3} = plElAct;
varargout{4} = plThAct;
varargout{5} = plFreeDyn;


