From 071fcde17398112d89f84e708a1eb0b518dcfbe3 Mon Sep 17 00:00:00 2001 From: Mauco03 <marco.gaibotti@skywarder.eu> Date: Fri, 7 Feb 2025 23:24:19 +0100 Subject: [PATCH] [handle-value-conversion][classes] Refactored Environment and Settings classes --- classes/Environment.m | 153 ++++++++++++++++++++++++++++++------------ classes/Settings.m | 4 +- 2 files changed, 112 insertions(+), 45 deletions(-) diff --git a/classes/Environment.m b/classes/Environment.m index eb05240..db82db8 100644 --- a/classes/Environment.m +++ b/classes/Environment.m @@ -1,4 +1,4 @@ -classdef Environment < Component +classdef Environment < Config % Environment: Represents launch site dependent variables. % % Constructor: @@ -11,21 +11,38 @@ classdef Environment < Component % - varIn: (optional) config source. Alternative to config.m % file - properties + + %% Cached properties + properties(Access = private) + PHI + OMEGA + LAT0 + LON0 + Z0 + PIN1_LENGTH + PIN2_LENGTH + RAMP_LENGTH + TEMPERATURE = 288.15 + PRESSURE = 101325 + RHO = 1.225 + GAMMA = 1.4 + end + + properties (Dependent) + phi double % [rad] Launchpad Azimuth, user input in degrees + omega double % [rad] Launchpad Elevation, user input in degrees + lat0 double % [deg] Launchpad latitude lon0 double % [deg] Launchpad longitude z0 double % [m] Launchpad Altitude - omega double % [deg] Launchpad Elevation - phi double % [deg] Launchpad Azimuth pin1Length double % [m] Distance from the upper pin to the upper tank cap pin2Length double % [m] Distance from the lower pin to the lower tank cap rampLength double % [m] Total launchpad length - temperature double = 288.15 % [K] Ground temperature + temperature double % [K] Ground temperature pressure double % [Pa] Ground pressure rho double % [Kg/m^3] Ground air density - gamma double = 1.4 % [-] Gas constant - R double = 287 % [-] Gas constant + gamma double % [-] Gas constant end properties(SetAccess = private) @@ -37,11 +54,13 @@ classdef Environment < Component effectiveRampAltitude double % [m] Projection of effectiveRampLength on z axis end - properties(Access = protected) + properties(Access = private) + tankLength double % [m] Motor tank length + end + + properties(Constant, Access = protected) configName = 'environmentConfig.m' variableName = '' - mission Mission - motor Motor end methods @@ -51,54 +70,102 @@ classdef Environment < Component motor Motor = Motor() varIn = [] end - obj@Component(mission, varIn); - obj.motor = motor; - - %% Update angles - obj.omega = deg2rad(obj.omega); - obj.phi = deg2rad(obj.phi); - - obj.updateAll(); + obj@Config(mission, varIn); + obj.tankLength = motor.tankLength; + obj = obj.updateRamp(); end end - % Updaters methods - function updateAll(obj) - obj.updateG0; - obj.updatePinDistance; - obj.updateRamp; - obj.updateLocal; + function obj = set.phi(obj, value) + obj.PHI = deg2rad(value); end - - function updateAllExcetpG0(obj) % useful for parallel computing based on threads (gravitywgs84 not supported) - obj.updatePinDistance; - obj.updateRamp; - obj.updateLocal; + + function obj = set.omega(obj, value) + obj.OMEGA = deg2rad(value); + obj = obj.updateRamp(); end - function obj = updateG0(obj) - if(~isempty(obj.lat0)) - obj.g0 = gravitywgs84(obj.z0, obj.lat0); - end + function obj = set.lat0(obj, value) + obj.LAT0 = value; + obj = obj.updateG0(); end - function obj = updatePinDistance(obj) - obj.pinDistance = obj.pin1Length + obj.pin2Length ... - + obj.motor.tankLength; + function obj = set.lon0(obj, value) + obj.LON0 = value; + end + + function obj = set.z0(obj, value) + obj.Z0 = value; + obj = obj.updateG0(); + end + + function obj = set.pin1Length(obj, value) + obj.PIN1_LENGTH = value; + obj = obj.updateRamp(); + end + + function obj = set.pin2Length(obj, value) + obj.PIN2_LENGTH = value; + obj = obj.updateRamp(); + end + + function obj = set.rampLength(obj, value) + obj.RAMP_LENGTH = value; + obj = obj.updateRamp(); + end + + function obj = set.temperature(obj, value) + obj.TEMPERATURE = value; + obj = obj.updateLocal(); + end + + function obj = set.pressure(obj, value) + obj.PRESSURE = value; + obj = obj.updateLocal(); + end + + function obj = set.rho(obj, value) + obj.RHO = value; + obj = obj.updateLocal(); + end + + function obj = set.gamma(obj, value) + obj.GAMMA = value; + obj = obj.updateLocal(); + end + + function value = get.phi(obj), value = obj.PHI; end + function value = get.omega(obj), value = obj.OMEGA; end + function value = get.lat0(obj), value = obj.LAT0; end + function value = get.lon0(obj), value = obj.LON0; end + function value = get.z0(obj), value = obj.Z0; end + function value = get.pin1Length(obj), value = obj.PIN1_LENGTH; end + function value = get.pin2Length(obj), value = obj.PIN2_LENGTH; end + function value = get.rampLength(obj), value = obj.RAMP_LENGTH; end + function value = get.temperature(obj), value = obj.TEMPERATURE; end + function value = get.pressure(obj), value = obj.PRESSURE; end + function value = get.rho(obj), value = obj.RHO; end + function value = get.gamma(obj), value = obj.GAMMA; end + end + + % Updaters + methods + function obj = updateG0(obj) + if(length([obj.Z0, obj.LAT0]) == 2) + obj.g0 = gravitywgs84(obj.Z0, obj.LAT0); + end end function obj = updateRamp(obj) - obj.effectiveRampLength = obj.rampLength - obj.pinDistance; - obj.effectiveRampAltitude = obj.effectiveRampLength*sin(obj.omega); + obj.pinDistance = obj.PIN1_LENGTH + obj.PIN2_LENGTH + obj.tankLength; + obj.effectiveRampLength = obj.RAMP_LENGTH - obj.pinDistance; + obj.effectiveRampAltitude = obj.effectiveRampLength*sin(obj.OMEGA); end function obj = updateLocal(obj) - if isempty(obj.temperature), obj.temperature = 288.15; end - if isempty(obj.gamma), obj.gamma = 1.4; end - - obj.local = [obj.z0, obj.temperature, ... % vector containing inputs for atmosphereData - obj.pressure, obj.rho]; + obj.local = [obj.Z0, obj.TEMPERATURE, ... % vector containing inputs for atmosphereData + obj.PRESSURE, obj.RHO]; end end end \ No newline at end of file diff --git a/classes/Settings.m b/classes/Settings.m index 88b8a16..1d41b5c 100644 --- a/classes/Settings.m +++ b/classes/Settings.m @@ -1,4 +1,4 @@ -classdef Settings < Config & dynamicprops +classdef Settings < dynamicprops % Settings: Provides standardized way of loading config files % Looks for files in missions > settings for global settings % Looks for files in caller's folder otherwise @@ -14,7 +14,7 @@ classdef Settings < Config & dynamicprops % If config name is provided, Settings checks inside the settings % folder or inside the caller's folder - properties(Access = protected) + properties(Constant, Access = protected) configPath = '' configName = '' variableName = '' -- GitLab