diff --git a/classes/Bay.m b/classes/Bay.m index 055847e981d03cf77a46f309ef8a7ab1619e0a3f..6de82158b048905b542b0426bc277e6df168642f 100644 --- a/classes/Bay.m +++ b/classes/Bay.m @@ -1,4 +1,4 @@ -classdef (Abstract) Bay < Config +classdef (Abstract) Bay < Component % An abstraction class that enables a standardized management of data % Properties and methods implemented in the Component class will % impact every physical component of the rocket (e.g. motor, elc ...) @@ -9,30 +9,5 @@ classdef (Abstract) Bay < Config mass inertia end - - properties(Abstract, Access = protected) - % Insert dependencies here - mission Mission - end - - methods(Abstract) - loadData(obj) - end - - methods(Access = protected) - function loadConfig(obj) - fileName = obj.configName; - filePath = obj.mission.configPath; - if ~isfile(fullfile(filePath, fileName)) - error(strcat("File not found inside the config folder: ", filePath)); - end - - varName = strtok(fileName,'C'); - run(fileName); - configObj = eval(varName); - fields = obj.getAvailableProperties(); - for j = 1:size(fields, 2), obj.(fields{j}) = configObj.(fields{j}); end - end - end end diff --git a/classes/Component.asv b/classes/Component.asv deleted file mode 100644 index 1a2e1422ea4be7a75f128c4acb17a32e34da9fff..0000000000000000000000000000000000000000 --- a/classes/Component.asv +++ /dev/null @@ -1,25 +0,0 @@ -classdef (Abstract) Component < Config - % An abstraction class that enables a standardized management of data - % Properties and methods implemented in the Component class will impact - % every data class in the framework (e.g. Component and its subclasses) - - - properties - Property1 - end - - methods - function obj = Component(inputArg1,inputArg2) - %COMPONENT Construct an instance of this class - % Detailed explanation goes here - obj.Property1 = inputArg1 + inputArg2; - end - - function outputArg = method1(obj,inputArg) - %METHOD1 Summary of this method goes here - % Detailed explanation goes here - outputArg = obj.Property1 + inputArg; - end - end -end - diff --git a/classes/Component.m b/classes/Component.m new file mode 100644 index 0000000000000000000000000000000000000000..ac069f481c1de44bd21ca71e313f181b2dc1c2c8 --- /dev/null +++ b/classes/Component.m @@ -0,0 +1,27 @@ +classdef (Abstract) Component < Config + %COMPONENT Summary of this class goes here + % Detailed explanation goes here + + properties(Abstract, Access = protected) + % Insert dependencies here + mission Mission + end + + methods(Access = protected) + function loadConfig(obj) + fileName = obj.configName; + filePath = obj.mission.configPath; + + if ~isfile(fullfile(filePath, fileName)) + error(strcat("File not found inside the config folder: ", filePath)); + end + + varName = strtok(fileName,'C'); + run(fileName); + configObj = eval(varName); + fields = obj.getAvailableProperties(); + for j = 1:size(fields, 2), obj.(fields{j}) = configObj.(fields{j}); end + end + end +end + diff --git a/classes/Config.m b/classes/Config.m index e77bddc1d34002b2d2b7c9d93db09b1df5ae6a76..0b8af1abcf291b77a05501e488f22967f76a5c33 100644 --- a/classes/Config.m +++ b/classes/Config.m @@ -7,6 +7,11 @@ classdef(Abstract) Config < handle configName {mustBeTextScalar} end + methods(Abstract, Access = protected) + loadData + loadConfig + end + methods(Access = protected) function propertiesOut = getAvailableProperties(obj) % This function returns "available" properties diff --git a/classes/Mission.m b/classes/Mission.m index d9edb83ef43bdaed7632955e68f184ff728d723d..2ffe2f8ca86078509c6433c2060585592acff288 100644 --- a/classes/Mission.m +++ b/classes/Mission.m @@ -26,6 +26,7 @@ classdef Mission < Config arguments loadConfig {islogical} = false end + obj.currentPath = fullfile(fileparts(mfilename("fullpath")), '..', 'missions'); if loadConfig, obj.loadConfig; end end @@ -41,4 +42,25 @@ classdef Mission < Config end end end + + methods(Access = protected) + function loadConfig(obj) + fileName = obj.configName; + filePath = obj.currentPath; + + if ~isfile(fullfile(filePath, fileName)) + error(strcat("File not found inside the config folder: ", filePath)); + end + + varName = strtok(fileName,'C'); + run(fileName); + configObj = eval(varName); + fields = obj.getAvailableProperties(); + for j = 1:size(fields, 2), obj.(fields{j}) = configObj.(fields{j}); end + end + end + + methods(Static, Access = protected) + function loadData(), end + end end \ No newline at end of file diff --git a/classes/bays/Motor.m b/classes/bays/Motor.m index adf8ce8d02ca762d8ae00b1a70f827d2c24d4606..fdb3464d2d518f9faafc2deb925fedca1992a718 100644 --- a/classes/bays/Motor.m +++ b/classes/bays/Motor.m @@ -4,7 +4,9 @@ classdef Motor < Bay properties name {mustBeTextScalar} = '' % [-] Motor name - motorLength double % [kg] Motor length + length % [m] Total length (motor + tank) + diameter + inertia tankLength double % [m] Tank length ignitionTime double % [s] Ignition transient duration cutoffTime double % [s] Cutoff transient duration @@ -12,7 +14,6 @@ classdef Motor < Bay thrust double % [N] Engine thrust vector fuelMass double % [kg] Fuel (grain) initial mass oxidizerMass double % [kg] Oxidizer initial mass - propellantMass double % [Kg] Propellant Mass (in time) structureMass double % [kg] Engine Structural Mass fuselageMass double % [kg] Fuselage of the engine only xCg double % [m] Engine xcg from tank tip @@ -21,15 +22,14 @@ classdef Motor < Bay end properties(Dependent) - totalMass double % [kg] Total motor mass - length double % [m] Total length (motor + tank) - totalLength double % [m] Motor + Tank lenght + mass % [kg] Total motor mass + propellantMass double % [Kg] Propellant Mass (in time) fuselageXCg double % [m] xcg of the engine fuselage only from tank tip end properties(Access = protected) configName = 'motorConfig.m' - mission {mustBeA(mission, 'Config')} + mission end methods @@ -48,8 +48,12 @@ classdef Motor < Bay obj.loadData(); end - function totalMass = get.totalMass(obj) - totalMass = obj.propellantMass + ... + function propellantMass = get.propellantMass(obj) + propellantMass = obj.fuelMass + obj.oxidizerMass; + end + + function mass = get.mass(obj) + mass = obj.propellantMass + ... obj.structureMass + obj.fuselageMass; end @@ -57,28 +61,25 @@ classdef Motor < Bay fuselageXCg = (obj.length - ... obj.tankLength)/2 + obj.tankLength; end - - function totalLength = get.totalLength(obj) - totalLength = obj.length + obj.tankLength; - end end - methods (Access = private) + methods (Access = protected) function obj = loadData(obj) if isempty(obj.mission.name) || isempty(obj.name), return; end load(fullfile(obj.mission.dataPath, 'motors.mat'), 'motors'); chosenMotor = motors(strcmp({motors.MotorName}, obj.name)); if isempty(chosenMotor), error(strcat('Unable to find engine: ', obj.name)); end - obj.length = chosenMotor.L; + obj.diameter = chosenMotor.D; + obj.length = chosenMotor.L; obj.tankLength = chosenMotor.Ltank; obj.time = chosenMotor.t; obj.thrust = chosenMotor.T; obj.fuelMass = chosenMotor.mFu; obj.oxidizerMass = chosenMotor.mOx; - obj.propellantMass = chosenMotor.m; obj.structureMass = chosenMotor.mc; - obj.xCg = chosenMotor.xcg; + obj.xCg = chosenMotor.xcg; + obj.inertia = [chosenMotor.Ixx; chosenMotor.Iyy; chosenMotor.Izz]; obj.pe = chosenMotor.Pe; obj.ae = chosenMotor.Ae; obj.fuselageMass = chosenMotor.mFus; diff --git a/classes/bays/Fins.m b/classes/components/Fins.m similarity index 100% rename from classes/bays/Fins.m rename to classes/components/Fins.m diff --git a/classes/bays/Pitot.m b/classes/components/Pitot.m similarity index 100% rename from classes/bays/Pitot.m rename to classes/components/Pitot.m