From 381c138cc695dd70b1d47f19a53af8aacb374f3c Mon Sep 17 00:00:00 2001 From: MatteoGotti <matteo.gotti@skywarder.eu> Date: Mon, 29 Apr 2024 15:20:35 +0200 Subject: [PATCH] [refactoring-ode][classes] fixed inertiaNoMot in Rocket.m, updated Motor.m - First attempt of retrocompatibility with solid motors --- classes/Rocket.m | 2 +- classes/bays/Motor.m | 72 +++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/classes/Rocket.m b/classes/Rocket.m index d4f948a..31f40b0 100644 --- a/classes/Rocket.m +++ b/classes/Rocket.m @@ -131,7 +131,7 @@ classdef Rocket < Component inertias = [bNoMotor.inertia]; temp = inertias(2:3, :) + ... (obj.xCgNoMotor' - (aPosNoMotor + [bNoMotor.xCg])).^2 .* [bNoMotor.mass]; - obj.inertiaNoMotor = [sum(inertias(1)); sum(temp, 2)]; + obj.inertiaNoMotor = [sum(inertias(1, :)); sum(temp, 2)]; end function updateInertia(obj) diff --git a/classes/bays/Motor.m b/classes/bays/Motor.m index 53138d7..b30031f 100644 --- a/classes/bays/Motor.m +++ b/classes/bays/Motor.m @@ -1,14 +1,14 @@ classdef Motor < Bay -% Motor: Represents the motor configuration for a rocket. -% -% Constructor: -% - Motor: Creates an instance of the Motor class. -% Loaded config: rocketConfig.m > motor -% Loaded data: motors.mat -% Arguments: -% - mission: Mission, mission object -% - varIn: (optional) config source. Alternative to config.m file - + % Motor: Represents the motor configuration for a rocket. + % + % Constructor: + % - Motor: Creates an instance of the Motor class. + % Loaded config: rocketConfig.m > motor + % Loaded data: motors.mat + % Arguments: + % - mission: Mission, mission object + % - varIn: (optional) config source. Alternative to config.m file + properties name {mustBeTextScalar} = '' % [-] Motor name position % [m] Absolute position, relative to nose base @@ -36,7 +36,7 @@ classdef Motor < Bay isHRE logical % [-] Flag relateed to the type of motor: true if HRE end - properties(Access = protected) + properties(Access = protected) configName = 'rocketConfig.m' variableName = 'motor' mission Mission = Mission() @@ -58,28 +58,23 @@ classdef Motor < Bay end function mass = get.mass(obj) - mass = obj.propellantMass + ... - obj.structureMass; %+ obj.fuselageMass; + mass = obj.propellantMass + obj.structureMass; end function fuselageXCg = get.fuselageXCg(obj) fuselageXCg = (obj.length - ... - obj.tankLength)/2 + obj.tankLength; - end - - function isHRE = get.isHRE(obj) - isHRE = contains(obj.name, 'HRE'); + obj.tankLength)/2 + obj.tankLength; end end methods (Access = protected) function obj = loadData(obj) if isempty(obj.mission.name) || isempty(obj.name) - return; + return; end load(fullfile(obj.mission.dataPath, 'motors.mat'), 'motors'); chosenMotor = motors(strcmp({motors.MotorName}, obj.name)); - + if ~(isempty(obj.name) || isvarname(obj.name)) error('Motor name is not a valid MATLAB variable name') end @@ -87,21 +82,30 @@ classdef Motor < Bay if isempty(chosenMotor) error(strcat('Unable to find engine: ', obj.name)); end - - 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.structureMass = chosenMotor.mc; - obj.propellantMass = chosenMotor.m; - obj.xCg = chosenMotor.xcg; - obj.inertia = [chosenMotor.Ixx; chosenMotor.Iyy; chosenMotor.Izz]; - obj.pe = chosenMotor.Pe; - obj.ae = chosenMotor.Ae; - obj.fuselageMass = chosenMotor.mFus; + obj.isHRE = contains(obj.name, 'HRE'); + + if obj.isHRE + 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.structureMass = chosenMotor.mc; + obj.propellantMass = chosenMotor.m; + obj.inertia = [chosenMotor.Ixx;chosenMotor.Iyy;chosenMotor.Izz]; + obj.xCg = chosenMotor.xcg; + obj.pe = chosenMotor.Pe; + obj.ae = chosenMotor.Ae; + obj.fuselageMass = chosenMotor.mFus; + else + obj.length = chosenMotor.L; + obj.time = chosenMotor.t; + obj.thrust = chosenMotor.T; + obj.propellantMass = chosenMotor.m; + obj.structureMass = chosenMotor.mc; + end if isempty(obj.cutoffTime) || obj.cutoffTime > obj.time(end) obj.cutoffTime = obj.time(end); end -- GitLab