diff --git a/classes/misc/Coefficient.m b/classes/misc/Coefficient.m new file mode 100644 index 0000000000000000000000000000000000000000..d5d60e26454780c8ce58c19b276fb9d6bba31cea --- /dev/null +++ b/classes/misc/Coefficient.m @@ -0,0 +1,94 @@ +classdef Coefficient + % Motor: Manages the coefficients associated with a rocket + % + % Constructor: + % - Coefficient: Creates an instance of the Coefficient class. + % Loaded config: - + % Loaded data: aeroCoefficients.mat + % Arguments: + % - filePath: char, path to coefficient file to load + % - name: (optional) coefficient name. Used when dynamic + % derivatives are also needed + % + % Coefficients are retrieved from DM in the following format: + % Coefficient matrix: double (15, nAlpha, nMach, nBeta, nAlt, nAbk, nXcg) + % Where the 15 coefficients are + % - CA Axial force + % - CYB Side force derivative wrt beta + % - CY0 Side force + % - CNA Normal force derivative wrt alpha + % - CN0 Normal force + % - Cl Rolling moment + % - Clp Rolling moment derivative wrt roll rate + % - Cma Pitching moment derivative wrt alpha + % - Cm0 Pitching moment + % - Cmad Pitching moment derivative wrt alpha dot + % - Cmq Pitching moment derivative wrt pitch rate + % - Cnb Yawing moment derivative wrt beta + % - Cn0 Yawing moment + % - Cnr Yawing moment derivative wrt yaw rate + % - Cnp Yawing moment derivative wrt roll rate + % + % NOTE: When dynamic derivatives are not loaded, the matrix will be + % 6-D, as there will be no need to interpolate wrt to the xcg: moment + % transport formulas will be used instead + + properties + static % Static coefficients: [CA, CY, CN, Cl, Cm, Cn] + dynamic % Dynamic derivatives: [Clp, Cmad, Cmq, Cnr, Cnp] + + finsCN % Fins-only CN + geometry % Reference geometry + state % Flight envelope + end + + properties(Access = private) + loadDynamic % Whether to load dynamic derivatives. Adds XCG dependece + end + + methods + function obj = Coefficient(filePath, name) + arguments + filePath (1, :) char + name (1, :) char = 'generic' + end + + obj = obj.loadData(filePath, name); + end + end + + methods(Access = private) + function obj = loadData(obj, filePath, name) + % Load the coefficients from the specified file + % filePath: char, path to coefficient file to load + % name: (optional) coefficient name. Used when dynamic + % derivatives are also needed + % + % NOTE: Coefficient alpha and beta derivatives are not loaded + % as coefficients are already interpolated linearly + + + if ~exist(filePath, 'file'), return; end + warning('off'); % Disable warning in case coefficients are not present + dataCoeffs = load(filePath, name); + warning('on'); + + if ~isfield(dataCoeffs, name), return; end + dataCoeffs = dataCoeffs.(name); + + obj.loadDynamic = ~strcmp(name, 'generic'); + obj.finsCN = dataCoeffs.finsCN; + obj.geometry = dataCoeffs.geometry; + obj.state = dataCoeffs.state; + + % Load CA, CY, CN, Cl, Cm, Cn + obj.static = dataCoeffs.total([1, 3, 5, 6, 9, 13], :, :, :, :, :, :); + + if obj.loadDynamic + % Load Clp, Cmad, Cmq, Cnr, Cnp + obj.dynamic = dataCoeffs.total([7, 10, 11, 14, 15], :, :, :, :, :, :); + end + end + end +end +