From 8a202763c728a3a508aa0303626839583ba27b11 Mon Sep 17 00:00:00 2001
From: Mauco03 <marco.gaibotti@skywarder.eu>
Date: Sat, 17 Feb 2024 20:54:46 +0100
Subject: [PATCH] First steps

- Initial conversion of variables from simulationsData, [MSA]toolkit config files

- implementation of a simple "loadConfig" function
---
 functions/config/loadConfig.m                 | 30 +++++++++++
 .../config/controlConfig.m                    | 26 +++++++++
 .../config/engineConfig.m                     |  6 +++
 .../config/environmentConfig.m                | 11 ++++
 .../config/geometryConfig.m                   | 48 +++++++++++++++++
 .../config/inertiaConfig.m                    | 32 +++++++++++
 .../config/massConfig.m                       |  0
 .../config/odeConfig.m                        | 23 ++++++++
 .../config/parachuteConfig.m                  | 54 +++++++++++++++++++
 .../config/settingsConfig.m                   |  7 +++
 .../config/stochasticConfig.m                 | 43 +++++++++++++++
 .../config/windConfig.m                       | 19 +++++++
 missions/superConfig.m                        |  6 +++
 13 files changed, 305 insertions(+)
 create mode 100644 functions/config/loadConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/controlConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/engineConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/environmentConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/geometryConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/inertiaConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/massConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/odeConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/parachuteConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/settingsConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/stochasticConfig.m
 create mode 100644 missions/2024_Lyra_Roccaraso_September/config/windConfig.m
 create mode 100644 missions/superConfig.m

diff --git a/functions/config/loadConfig.m b/functions/config/loadConfig.m
new file mode 100644
index 0000000..5543e5c
--- /dev/null
+++ b/functions/config/loadConfig.m
@@ -0,0 +1,30 @@
+function varargout = loadConfig(varargin)
+% launchProb - This function reads and outputs data structures from .m
+% files present in the config folder
+%
+% INPUTS:         - fileNames
+% 
+% OUTPUTS:
+%                 - stucts, ordered based on input
+
+varargout = cell(1, nargin);
+
+currPath = fileparts(mfilename('fullpath'));
+superPath = fullfile(currPath, '..', '..', 'missions');
+
+%% LOAD superConfig
+run(fullfile(superPath, 'superConfig.m'));
+configPath = fullfile(superPath, super.mission, 'config');
+
+%% LOAD desired configs
+    for i = 1:nargin
+        fileName = char(varargin{i});
+        if ~isfile(fullfile(configPath, fileName))
+            error(strcat("File not found inside the config folder: ", varargin{i})); 
+        end
+        
+        varName = strtok(fileName,'C');
+        run(fileName);
+        varargout{i} = eval(varName);
+    end
+end
\ No newline at end of file
diff --git a/missions/2024_Lyra_Roccaraso_September/config/controlConfig.m b/missions/2024_Lyra_Roccaraso_September/config/controlConfig.m
new file mode 100644
index 0000000..6811037
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/controlConfig.m
@@ -0,0 +1,26 @@
+% CONFIG - This script sets up control parameters
+
+%% AEROBRAKES SETTINGS
+% Multiple air-brakes and smooth opening simulation
+% If FALSE:
+%       - settings.control: only the first value will be computed;
+%       - settings.dtControl: is not read.
+% If TRUE:
+%       - settings.control: define the sequence of air-brakes opening
+%                           configuration. Closed air-brakes are simulated
+%                           untill the conditions settings.tControl and
+%                           settings.machControl are both verified, check
+%                           simulationsData.m;
+%       - settings.dtControl: define the usage time of the i-th
+%                             configuration. Its length must be -1 the
+%                             length of settings.control
+
+control.multipleAB = false;                                                % If true, multiple and smooth airbrakes opening will be simulated
+control.opening = [1 3];                                                   % aerobrakes, 1-2-3 for 0%, 50% or 100% opened
+control.deltaTime = [10];                                                  % aerobrakes, configurations usage time
+
+%% AIRBRAKES CONTROL SETTINGS
+control.minTime = 0;                              % [s] time after which the airbrakes can be used
+control.maxMach = 0.8;                                   % [-] Maximum Mach at which airbrakes can be used
+control.servoOmega = 150*pi/180;                                 % [rad/s] Servo-motor angular velocity
+control.height = linspace(0, 0.0363, 3);                      % [m] Block airbrakes opening coordinate ( First entry must be 0! )
\ No newline at end of file
diff --git a/missions/2024_Lyra_Roccaraso_September/config/engineConfig.m b/missions/2024_Lyra_Roccaraso_September/config/engineConfig.m
new file mode 100644
index 0000000..b47c217
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/engineConfig.m
@@ -0,0 +1,6 @@
+% CONFIG - This script sets up parameters for the engine
+
+engine.name = 'HRE_FURIA-Rv2-T04T03';
+engine.burnTime = inf;                                 % [s] Burn duration
+engine.ignitionTime = 000; %0.4;                       % [s] Ignition transient
+engine.cutOffTime = 000; %0.3;                         % [s] Cut-off transient
diff --git a/missions/2024_Lyra_Roccaraso_September/config/environmentConfig.m b/missions/2024_Lyra_Roccaraso_September/config/environmentConfig.m
new file mode 100644
index 0000000..96c77af
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/environmentConfig.m
@@ -0,0 +1,11 @@
+% CONFIG - This script sets up parameters for the environment
+%
+% Use this file to write launch data, independent from the rocket itself
+
+environment.lat0 = 41.8084579;                                   % [deg] Launchpad latitude
+environment.lon0 = 14.0546408;                                   % [deg] Launchpad longitude
+environment.z0 = 1414;                                           % [m] Launchpad Altitude
+environment.lpin1 = 000;                                      % [m] Distance from the upper pin to the upper tank cap
+environment.lpin2 = 000;                                      % [m] Distance from the lower pin to the lower tank cap  
+environment.lrampa = 000;                                         % [m] Total launchpad length 
+environment.g0 = gravitywgs84(environment.z0, environment.lat0);           % Gravity costant at launch latitude and altitude
\ No newline at end of file
diff --git a/missions/2024_Lyra_Roccaraso_September/config/geometryConfig.m b/missions/2024_Lyra_Roccaraso_September/config/geometryConfig.m
new file mode 100644
index 0000000..5c7990c
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/geometryConfig.m
@@ -0,0 +1,48 @@
+% CONFIG - This script contains information about the geometry of the
+% rocket
+
+
+%% Boat-tail
+% The boat-tail is simulated as a trunc of cone with the major diameter
+% equal to the rocket one (settings.C)
+geometry.boatLength = 000;                                       % [m] Boat-tail length
+geometry.boatDiameter = 000;                                     % [m] Boat-tail base diameter
+
+%% Rocket ogive and central body
+geometry.caliber = 000;                                          % [m] Caliber (Fuselage Diameter)
+geometry.crossSection = pi*geometry.C^2/4;                       % [m^2] Cross-sectional Surface
+geometry.noseLength = 000;                                       % [m] Nosecone Length
+geometry.ogiveType = 'MHAACK';                                   % [-] Nosecone shape
+geometry.nosePower = 000; %3/4;                                  % [-] Nosecone power type parameter
+geometry.noseP = 000; %1.250152e+00;                             % [-] P coefficient for modified nosecone shapes
+geometry.noseC = 000; %1.799127e-01;                             % [-] C coefficient for modified nosecone shapes
+
+geometry.centerLength = 000; %1.517;                             % [m] Central body length
+geometry.mNoMot = 000; %16.423;                                  % [kg] Mass of everything above engine
+geometry.xcgNoMot = 000; %1.149;                                 % [m] XCG of everything above engine (from nosecone base)
+
+%% Aerodynamics
+%%% Pitot tube
+geometry.pitot.initialConeLength = 0;                            % [m] Pitot initial conic section length
+geometry.pitot.finalConeLength = 0;                              % [m] Pitot final conic section length
+geometry.pitot.initialConeDiameter = 0;                          % [m] Pitot initial conic section diameter
+geometry.pitot.finalConeDiameter = 0;                            % [m] Pitot final conic section diameter
+geometry.pitot.length = 0;                                       % [m] Pitot tube length
+geometry.pitot.diameter = 0;                                     % [m] Pitot tube diameter
+
+%%% Finset 
+geometry.fins.attachedChordLength = 0.30;                                       % [m] attached chord length
+geometry.fins.freeChordLenght = 0.14;                                       % [m] free chord length
+geometry.fins.height = 0.11;                                       % [m] fin heigth
+geometry.fins.deltaXLE = 0.13;                                     % [m] start of Chord 2 measured from start of Chord 1
+geometry.fins.nPanel = 3;                                          % [m] number of fins
+geometry.fins.leadingEdgeRadius = [0 0];                                         % [deg] Leading edge radius at each span station
+geometry.fins.axialDistance = 0.012;                                           % [m] distance between end of root chord and end of center body
+geometry.fins.zupRaw = 0.00175;                                    % [m] fin semi-thickness
+geometry.fins.LmaxuRaw = 0.00175;                                  % [m] Fraction of chord from leading edge to max thickness
+
+%%% Protub data
+geometry.protuberances.xDistance = 1.517;                                       % [m] axial position from nosecone base
+geometry.protuberances.n = 3;                                            % [-] number of brakes
+geometry.protuberances.length = 0.008;                                       % [m] brakes thickness
+geometry.protuberances.width = 0.1002754821;                                % [m] brakes width (normal)
diff --git a/missions/2024_Lyra_Roccaraso_September/config/inertiaConfig.m b/missions/2024_Lyra_Roccaraso_September/config/inertiaConfig.m
new file mode 100644
index 0000000..ac8ca9c
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/inertiaConfig.m
@@ -0,0 +1,32 @@
+% CONFIG - This script contains information about the inertias of the
+% rocket
+
+%% MASS GEOMERTY DETAILS
+% x-axis: along the fuselage
+% y-axis: right wing
+% z-axis: downward
+
+%%% Inertias for fuselage only (no engine)
+inertia.rocket.Ixx = 0.06535397;                              % [kg*m^2] Inertia to x-axis
+inertia.rocket.Iyy = 12.07664659;                             % [kg*m^2] Inertia to y-axis
+inertia.rocket.Izz = 12.07701314;                             % [kg*m^2] Inertia to z-axis
+
+%%% Inertias for engine only
+inertia.engine.Ixx = HREmotors(iMotor).Ixx;                            % [kg*m^2] Inertia to x-axis
+inertia.engine.Iyy = HREmotors(iMotor).Iyy;                            % [kg*m^2] Inertia to y-axis
+inertia.engine.Izz = HREmotors(iMotor).Izz;                            % [kg*m^2] Inertia to z-axis
+
+% %%% Total inertias
+% inertia.Ixx = inertia.rocketIxx + engineIxx;
+% 
+% inertia.Iyy = inertia.rocketIyy + ((inertia.xcgNoMot - inertia.xcg).^2) .* inertia.mNoMot + ...
+%     (engineIyy + ((inertia.motor.xcg + inertia.LcenterRocket - inertia.xcg).^2 ) .* (inertia.motor.expM + inertia.motor.mc));
+% 
+% inertia.Izz = inertia.rocketIzz + ((inertia.xcgNoMot - inertia.xcg).^2) .* inertia.mNoMot + ...
+%     (engineIzz + ((inertia.motor.xcg + inertia.LcenterRocket - inertia.xcg).^2) .* (inertia.motor.expM + inertia.motor.mc));
+% 
+% inertia.I = [inertia.Ixx; inertia.Iyy; inertia.Izz];
+
+%%% Inertias derivatives (avoiding calculations in ascent.m)
+% inertia.Idot = diff(inertia.I')'./diff(inertia.motor.expTime);
+% inertia.Idot(:, end+1) = inertia.Idot(:, end);
\ No newline at end of file
diff --git a/missions/2024_Lyra_Roccaraso_September/config/massConfig.m b/missions/2024_Lyra_Roccaraso_September/config/massConfig.m
new file mode 100644
index 0000000..e69de29
diff --git a/missions/2024_Lyra_Roccaraso_September/config/odeConfig.m b/missions/2024_Lyra_Roccaraso_September/config/odeConfig.m
new file mode 100644
index 0000000..b2adb47
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/odeConfig.m
@@ -0,0 +1,23 @@
+% CONFIG - This script contains ODE settings
+
+ode.finalTime = 2000;    % [s] Final integration time
+
+% create an option structure for the integrations:
+
+% - AbsTol is the threshold below which the value of the solution becomes unimportant
+% - RelTol is the tolerance betweeen two consecutive values
+% - Events is the event function that defines when the integration must be
+% - stopped (it has to be created)
+% - InitialStep is the highest value tried by the solver
+
+ode.optionsasc1 = odeset('Events', @eventApogee, 'InitialStep', 1);          %ODE options for ascend
+ode.optionsasc2 = odeset('InitialStep', 1);                                  %ODE options for due to the opening delay of the parachute
+ode.optionsascMultipleAB = odeset('Events', @eventAB,  'InitialStep', 1);    %ODE options for opening of the airbrakes
+ode.optionspara = odeset('Events', @eventParaCut);                           %ODE options for the parachutes
+ode.optionsdesc = odeset('Events', @eventLanding);                           %ODE options for ballistic descent
+ode.optionspad = odeset('Events', @eventPad);                                %ODE options for the launchpad phase
+
+% Settings for descent 6dof simulation
+ode.optionsDrogue6DOF = odeset('Events', @eventParaCut, 'AbsTol', 1e-6,'RelTol', 1e-6);         %ODE options for due to cutting of the drogue chute
+ode.optionsMainExt6DOF = odeset('Events', @eventMainExit, 'AbsTol', 1e-6,'RelTol', 1e-6);       %ODE options for due to the extraction of the main chute
+settings.ode.optionsMain6DOF = odeset('Events', @eventLanding, 'AbsTol', 1e-6,'RelTol', 1e-6);           %ODE options to terminate descent phase
\ No newline at end of file
diff --git a/missions/2024_Lyra_Roccaraso_September/config/parachuteConfig.m b/missions/2024_Lyra_Roccaraso_September/config/parachuteConfig.m
new file mode 100644
index 0000000..1ca9704
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/parachuteConfig.m
@@ -0,0 +1,54 @@
+% CONFIG - This script contains information about the parachutes onboard
+
+%% ROCKET CHUTES
+% parachute 1
+parachute.para(1, 1).name = 'DROGUE chute';
+parachute.para(1, 1).surface = 1.2219;    % [m^2]   Surface
+parachute.para(1, 1).mass = 0.15;   % [kg]   Parachute Mass
+parachute.para(1, 1).cd = 0.96;     % [/] Parachute Drag Coefficient
+parachute.para(1, 1).cl = 0;        % [/] Parachute Lift Coefficient
+parachute.para(1, 1).openingDelay = 1;     % [s] drogue opening delay
+parachute.para(1, 1).finalAltitude = 350;           % [m] Final altitude of the parachute
+parachute.para(1, 1).cx = 1.4;      % [/] Parachute Longitudinal Drag Coefficient
+parachute.para(1, 1).chordLength = 1.5;       % [m] Shock Chord Length
+parachute.para(1, 1).chordK = 7200;      % [N/m^2] Shock Chord Elastic Constant
+parachute.para(1, 1).chordC = 0;         % [Ns/m] Shock Chord Dynamic Coefficient
+parachute.para(1, 1).m = 1;         % [m^2/s] Coefficient of the surface vs. time opening model
+parachute.para(1, 1).nf = 12;       % [/] Adimensional Opening Time
+parachute.para(1, 1).expulsionSpeed = 5;     % [m/s] Expulsion Speed
+
+% parachute 2
+parachute.para(2, 1).name = 'MAIN chute';
+parachute.para(2, 1).surface = 7.34;      % [m^2]   Surface
+parachute.para(2, 1).mass = 1.05;   % [kg]   Parachute Mass
+parachute.para(2, 1).cd = 1.75;     % [/] Parachute Drag Coefficient
+parachute.para(2, 1).cl = 0;        % [/] Parachute Lift Coefficient
+parachute.para(2, 1).finalAltitude = 0;     % [m] Final altitude of the parachute
+parachute.para(2, 1).cx = 1.2;      % [/] Parachute Longitudinal Drag Coefficient
+parachute.para(2, 1).chordLength = 6;         % [m] Shock Chord Length
+parachute.para(2, 1).chordK = 3000;      % [N/m^2] Shock Chord Elastic Constant
+parachute.para(2, 1).chordC = 0;         % [Ns/m] Shock Chord Dynamic Coefficient
+parachute.para(2, 1).m = 1;         % [m^2/s] Coefficient of the surface vs. time opening model
+parachute.para(2, 1).nf = 8.7;      % [/] Adimensional Opening Time
+
+%% PAYLOAD CHUTES
+% parachute 1
+parachute.para(1, 2).name = "Payload DROGUE";
+parachute.para(1, 2).surface = 0.11;      % [m^2]   Surface
+parachute.para(1, 2).mass = 0.15;   % [kg]   Parachute Mass
+parachute.para(1, 2).cd = 1.2;      % [/] Parachute Drag Coefficient
+parachute.para(1, 2).cl = 0;        % [/] Parachute Lift Coefficient
+parachute.para(1, 2).openingDelay = 1;     % [s] drogue opening delay
+parachute.para(1, 2).finalAltitude = 300;   % [m] Final altitude of the parachute
+parachute.para(1, 2).cx = 1.4;      % [/] Parachute Longitudinal Drag Coefficient
+parachute.para(1, 2).chordLength = 1.5;       % [m] Shock Chord Length
+parachute.para(1, 2).chordK = 7200;      % [N/m^2] Shock Chord Elastic Constant
+parachute.para(1, 2).chordC = 0;         % [Ns/m] Shock Chord Dynamic Coefficient
+parachute.para(1, 2).m = 1;         % [m^2/s] Coefficient of the surface vs. time opening model
+parachute.para(1, 2).nf = 12;       % [/] Adimensional Opening Time
+parachute.para(1, 2).expulsionSpeed = 10;     % [m/s] Expulsion Speed
+
+% parachute 2
+parachute.para(2, 2).name = "Payload AIRFOIL";
+parachute.para(2, 2).mass = 0.50;    % [kg]   Parachute Mass
+parachute.para(2, 2).finalAltitude = 0;      % [m] Final altitude of the parachute
diff --git a/missions/2024_Lyra_Roccaraso_September/config/settingsConfig.m b/missions/2024_Lyra_Roccaraso_September/config/settingsConfig.m
new file mode 100644
index 0000000..0044a9b
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/settingsConfig.m
@@ -0,0 +1,7 @@
+% CONFIG - This script sets up which feature a mission uses
+%
+% Use this file to store information about the features implemented in a
+% mission (e.g. whether a specific algorithm is used, the engine type, 
+% flags...)
+
+features.engineType = 'hybrid';      % [-] choices are: solid, hybrid
\ No newline at end of file
diff --git a/missions/2024_Lyra_Roccaraso_September/config/stochasticConfig.m b/missions/2024_Lyra_Roccaraso_September/config/stochasticConfig.m
new file mode 100644
index 0000000..5c107b6
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/stochasticConfig.m
@@ -0,0 +1,43 @@
+% CONFIG - This script sets up parameters for stochastic simulations
+%
+% Use this file to specify numbers of simulations, parameter variations...
+
+stochastic.n = 10;                                                     % Number of cases
+stochastic.parThreads = false;                                               % choose true if you are running low on ram on your pc, note: it will use twice the workers and be more intensive on your cpu
+stochastic.confidence = [0.65 0.90];
+stochastic.plots = true; 
+stochastic.geoPlots = false; 
+stochastic.internalStressPlots = false;
+stochastic.formatPlotsASD = false;
+
+% Simulation type: 
+%   1-apogee only    
+%   2-ballistic descent     
+%   3-parachute descent     
+%   4-both ballistic and parachute descent
+%   5-stability 
+stochastic.simType = 4;
+
+stochastic.parameters = addParameter();                 % Parameters to add: type help addParameters for more info
+
+% stochastic.parameters = addParameter('CA', 4, 1, -0.2, 0, ...
+%                             stochastic.parameters, settings);
+
+%%% launch probability details
+stochastic.probability.xLim = 2e3;                    % Max ovest displacement [m]
+stochastic.probability.vLim = 50;                     % Max drogue velocity [Pa]
+stochastic.probability.xcpLim = 1.5;                  % Min XCP
+
+%%% Safe Ellipse - roccaraso
+stochastic.SafeEllipse(1).name = 'prova';
+stochastic.SafeEllipse(1).a = 1100;
+stochastic.SafeEllipse(1).b = 2800;
+stochastic.SafeEllipse(1).x0  = 0;
+stochastic.SafeEllipse(1).y0 = -300;
+stochastic.SafeEllipse(1).alpha = 10;
+
+%% LANDING POINTS
+% satellite maps of the landing zone
+% delta limit on the coordinates (for the landing map)
+stochastic.limLat = 0.04;
+stochastic.limLon = 0.025;
\ No newline at end of file
diff --git a/missions/2024_Lyra_Roccaraso_September/config/windConfig.m b/missions/2024_Lyra_Roccaraso_September/config/windConfig.m
new file mode 100644
index 0000000..42c88a0
--- /dev/null
+++ b/missions/2024_Lyra_Roccaraso_September/config/windConfig.m
@@ -0,0 +1,19 @@
+% CONFIG - This script sets up wind direction and magnitude based on
+% altitudes
+%
+% Wind azimuth angle indications (wind directed towards):
+% 0 deg (use 360 instead of 0)  -> North
+% 90 deg                        -> East
+% 180 deg                       -> South
+% 270 deg                       -> West
+
+wind.magnitude = [5, 5];                                                   % [m/s] Magnitude, [min, max]                                                                     % [m/s] Maximum Magnitude
+wind.elevationMin = [0, 0] * pi/180;                                       % [rad] Elevation, user input in degrees, [min, max <= 90]
+wind.azimuthMin = [180, 180] * pi/180;                                     % [rad] Azimuth, user input in degrees, [min, max]
+
+wind.altitudes = [0 200 2000];
+wind.magDistribution = ["g", "u", "u"];
+wind.mag = [7 2 10;
+            0.5 9 20];
+wind.azDistribution = ["u", "u", "u"];
+wind.az = 90*pi/180 * ones(2,3);
\ No newline at end of file
diff --git a/missions/superConfig.m b/missions/superConfig.m
new file mode 100644
index 0000000..fa4c19f
--- /dev/null
+++ b/missions/superConfig.m
@@ -0,0 +1,6 @@
+% CONFIG - This script sets up all the parameters for all tools
+%
+% Use this file to store relevant, universally true settings, 
+% such as the current mission. The config "BIOS"
+
+super.mission = '2024_Lyra_Roccaraso_September';
\ No newline at end of file
-- 
GitLab