diff --git a/classes/DataWrapper.m b/classes/DataWrapper.m index 02dfb1a71f639676483f1f3f5f309f64b1a7aebf..62981eb589d4bc3a4cf7b0a49d416abd813dddfa 100644 --- a/classes/DataWrapper.m +++ b/classes/DataWrapper.m @@ -3,42 +3,58 @@ classdef DataWrapper < handle % % Constructor: % - OutputWrapper: Creates an instance of the Wrapper class. + % Arguments: + % - reference, data used to preallocate cache with empty fields + % - chunkSize, default: 1000, space to preallocate each + % time cache is full + % - shift, default: 0, leaves n empty fields at the + % beginning of cache if needed % % WARNING: Intended for data exchange where output arguments are inaccessible. + % AVOID using such method if output arguments can be read to + % improve code maintainability properties(SetAccess = private) - data struct - dummy struct + data struct % Cached data + dummy struct % Empty struct for field reference end properties(Access = private) - counter int32 - shift int32 - chunkSize int32 % Size of preallocated memory - dataLen int32 % Current size of cache + counter int32 % Current size of data stored + shift int32 % Number of fields to skip in cache, useful to preallocate initial values / starting conditions + chunkSize int32 % Size of preallocated memory + dataLen int32 % Current preallocated size of cache end methods - function obj = DataWrapper(dataDummy, chunkSize, shift) + function obj = DataWrapper(reference, chunkSize, shift) arguments - dataDummy struct + reference struct chunkSize {mustBeInteger, mustBePositive} = 1000 shift = 0 end obj.chunkSize = chunkSize; - obj.shift = shift; % Useful to preallocate initial value + obj.shift = shift; - fields = fieldnames(dataDummy)'; fields{2, 1} = []; + fields = fieldnames(reference)'; fields{2, 1} = []; obj.dummy = struct(fields{:}); obj.reset(); end function setCache(obj, data) + % setCache - Saves data as last element in cache (unpromoted) + % When calling setCache, any unpromoted data will be + % overridden + % To avoid overwriting, promote data using setData + obj.data(obj.counter + 1) = data; end function setData(obj) + % setData - Promoted current data stored in cache + % promoted data will be saved until wrapper is reset + obj.counter = obj.counter + 1; if obj.counter == obj.dataLen len = obj.dataLen + obj.chunkSize; @@ -48,11 +64,16 @@ classdef DataWrapper < handle end function out = popData(obj) + % popData - Reads data from wrapper + % This action WILL reset cache + out = obj.packageData(obj.data(1:obj.counter)); obj.reset(); end function out = getData(obj, startIdx) + % detData - Reads data from wrapper + % This action will NOT reset cache arguments obj startIdx = 1 @@ -61,6 +82,8 @@ classdef DataWrapper < handle end function obj = reset(obj) + % reset - Resets cache to starting conditions + obj.data = obj.dummy; % Set struct dataType obj.data(obj.chunkSize) = obj.dummy; % Preallocate struct diff --git a/classes/Mission.m b/classes/Mission.m index 947f76bf863aae8065dc888feabb36ab069a6434..2694c76e83ce1712ebf9242cc469df34a12a58da 100644 --- a/classes/Mission.m +++ b/classes/Mission.m @@ -27,9 +27,9 @@ classdef Mission < Config end methods - function obj = Mission(m) + function obj = Mission(mission) arguments - m {mustBeA(m, {'logical', 'string', 'char'})} = false + mission {mustBeA(mission, {'logical', 'string', 'char'})} = false end if nargin == 0 @@ -40,8 +40,8 @@ classdef Mission < Config filePath = trimPath(filePath); obj.currentPath = filePath; - if isa(m, 'char') || isa(m, 'string') - obj.name = m; + if isa(mission, 'char') || isa(mission, 'string') + obj.name = mission; else obj.loadConfig(); end diff --git a/classes/bays/Motor.m b/classes/bays/Motor.m index 909d992560f8dd1557db59cca6b55bcf2eae166d..3a8af1ffa1d9645fb741fcd2a51d53f0412686a4 100644 --- a/classes/bays/Motor.m +++ b/classes/bays/Motor.m @@ -63,6 +63,10 @@ classdef Motor < Bay end function updateAll(obj) + obj.updateMass(); + end + + function updateMass(obj) obj.fuselageXCg = (obj.length - ... obj.tankLength)/2 + obj.tankLength; obj.mass = obj.propellantMass + obj.structureMass; diff --git a/functions/odeFunctions/ballistic.m b/functions/odeFunctions/ballistic.m index 5b3636f2131a0c2ee28dab9050416c1b057c0712..5992de85a73f1091cc44fbd481fec2190b6745e0 100644 --- a/functions/odeFunctions/ballistic.m +++ b/functions/odeFunctions/ballistic.m @@ -46,10 +46,10 @@ w = Y(6); p = Y(7); q = Y(8); r = Y(9); -q0 = Y(10); -q1 = Y(11); -q2 = Y(12); -q3 = Y(13); +qw = Y(10); +qx = Y(11); +qy = Y(12); +qz = Y(13); angle = Y(14); dY = zeros(14, 1); @@ -68,7 +68,7 @@ isControlActive = false; isAngleSaturated = false; %% QUATERION ATTITUDE -Q = [q0 q1 q2 q3]; +Q = [qw qx qy qz]; Q = Q/norm(Q); %% ADDING WIND (supposed to be added in NED axes); @@ -252,7 +252,7 @@ else dr = (Ixx - Iyy)/Izz*p*q + qdynL_V/Izz*(velsNorm*Cn + (Cnr*r+Cnp*p)*C/2)... - Izzdot*r/Izz; - % Compute the aerodynamici roll angle + % Compute the aerodynamic roll angle [~, phi] = getAlphaPhi(alpha, beta); % Aerodynamic-force coefficient in the alpha-total plane diff --git a/functions/odeFunctions/descentParachute.m b/functions/odeFunctions/descentParachute.m index be81dbd2e8cafa57d0e7f25baaa9e8dcf49b2896..6ec95378cec9be33c9d4dfb51b50b31bf024b771 100644 --- a/functions/odeFunctions/descentParachute.m +++ b/functions/odeFunctions/descentParachute.m @@ -19,6 +19,9 @@ end % % - (rocket, environment, wind), data Classes % - settings, struct +% - descentData, struct +% * para, double, current parachute (para matrix row) +% * stage, double, current stage (para matrix col) % - wrapper, handle to export data % % OUTPUTS: diff --git a/functions/odeFunctions/descentParafoil.m b/functions/odeFunctions/descentParafoil.m index e45670d91e5219894e40511af4eea2a0cd3b7d78..66ceca02f3c4575132657618bcdb30fa604ce276 100644 --- a/functions/odeFunctions/descentParafoil.m +++ b/functions/odeFunctions/descentParafoil.m @@ -41,10 +41,10 @@ w = Y(6); p = Y(7); q = Y(8); r = Y(9); -q0 = Y(10); % scalar first -q1 = Y(11); -q2 = Y(12); -q3 = Y(13); +qw = Y(10); % scalar first +qx = Y(11); +qy = Y(12); +qz = Y(13); deltaA = 0; dY = zeros(13, 1); @@ -93,7 +93,7 @@ deltaSMax = parafoil.deltaSMax; % max value %% ROTATIONS -Q = [q0 q1 q2 q3]; % we want it scalar first +Q = [qw qx qy qz]; % we want it scalar first Q = Q/norm(Q); %% ADDING WIND (supposed to be added in NED axes); diff --git a/functions/odeOutputFcn/storeData.m b/functions/odeOutputFcn/storeData.m index 54d45fb6c1b2619d2a1d103fb3462ae6f1a13c68..57f8af03623d79179bcb9849596e17c1bd43d3a0 100644 --- a/functions/odeOutputFcn/storeData.m +++ b/functions/odeOutputFcn/storeData.m @@ -1,4 +1,9 @@ function s = storeData(~, ~, flag, varargin) +% storeData: Stores ODE extra data after each successful integration step +% into a DataWrapper class - see help DataWrapper for more info +% +% WARNING: it is assumed that the data wrapper is the last arguent + s = 0; switch flag case {'init', 'done'}