Skip to content
Snippets Groups Projects
Commit 0b675041 authored by Marco Luigi Gaibotti's avatar Marco Luigi Gaibotti
Browse files

[refactoring-ode][classes] Update

- Improved code readability in Rocket
    bays are now stored in a dictionary to avoid confusion
- Added lengthCenter
parent 1832d6d7
No related branches found
No related tags found
1 merge request!3Refactoring ODE functions
......@@ -90,15 +90,15 @@ classdef(Abstract) Config < handle
properties(ii) = {mp.Name};
end
end
propertiesOut = properties(1:ii);
propertiesOut = string(properties(1:ii));
if nargout == 2
if isempty(options.Superclass) || ~options.Heterogeneous
valuesOut = cell(1, ii);
for i = 1:ii, valuesOut{i} = obj.(propertiesOut{i}); end
for i = 1:ii, valuesOut{i} = obj.(propertiesOut(i)); end
else
valuesOut(ii) = obj.(propertiesOut{1});
for i = 1:ii, valuesOut(i) = obj.(propertiesOut{i}); end
valuesOut(ii) = obj.(propertiesOut(1));
for i = 1:ii, valuesOut(i) = obj.(propertiesOut(i)); end
end
end
end
......
......@@ -32,17 +32,17 @@ classdef Rocket < Component
end
properties(SetAccess = private)
lengthCenter double % [m] Center length - no nose, boat
bays dictionary ... % [Bay] All bays
= dictionary()
inertiaDot double % [kg*m^2/s]Total inertia time derivative
cutoffInertia double % [kg*m^2] Total inertia at motor cutoff
cutoffMass double % [m] Total mass at motor cutoff
coefficients % [-] Aerodynamic coefficients
coefficientsHighAOA % [-] Aerodynamic coefficients for high angle of attacks
absolutePositions % [m] Bay start positions - 0 is set at nose base
absolutePositionsNoMotor % [m] Bay start positions, no Motor - 0 is set at nose base
absolutePositions dictionary ... % [m] Bay start positions - 0 is set at nose base
= dictionary()
crossSection % [m^2] Rocket cross sectional area
bays (1, :) Bay % [Bay] All bays
baysNoMotor (1, :) Bay % [Bay] All bays, except Motor
end
properties(Access = protected, Hidden)
......@@ -53,7 +53,8 @@ classdef Rocket < Component
methods % Updaters
function updateAbsolutePositions(obj)
b = obj.bays;
bDictionay = obj.bays;
b = values(bDictionay);
% Populate shift vectors (how much each bay shifts the next one back)
% Shift overrides are applyed to the previous bay
......@@ -64,31 +65,29 @@ classdef Rocket < Component
shift(overridesShift) = b(overrides).position;
shift(~overridesShift) = [b(~overridesShift).length];
absPositions = cumsum([-shift(1), shift(1:end-1)]);
obj.absolutePositions = absPositions;
obj.absolutePositions = obj.absolutePositions + ...
absPositions = cumsum([-shift(1); shift(1:end-1)]);
absPositions = absPositions + ...
(obj.payload.length - obj.payload.noseLength);
obj.absolutePositionsNoMotor = [absPositions(1:4), absPositions(6:end)];
obj.absolutePositions = dictionary(keys(bDictionay), absPositions);
end
function updateGeometry(obj)
if ~isempty(obj.length)
return;
end
if isempty(obj.length)
% Measures rear - tip
obj.length = (obj.absolutePositions(end) + obj.bays(end).length) - obj.absolutePositions(1);
if ~isempty(obj.crossSection)
return;
obj.length = (obj.absolutePositions("rear") + obj.bays("rear").length) + obj.bays("payload").noseLength;
end
if isempty(obj.crossSection)
obj.crossSection = 0.25*pi*obj.diameter^2;
end
obj.lengthCenter = obj.length - obj.payload.noseLength - obj.rear.boatLength;
end
function updateMassNoMotor(obj)
if ~isempty(obj.massNoMotor)
return;
end
obj.massNoMotor = sum([obj.baysNoMotor.mass]);
bNoMotor = values(remove(obj.bays, 'motor'));
obj.massNoMotor = sum([bNoMotor.mass]);
end
function updateMass(obj)
......@@ -102,8 +101,10 @@ classdef Rocket < Component
if ~isempty(obj.xCgNoMotor)
return;
end
obj.xCgNoMotor = (([obj.absolutePositionsNoMotor] + [obj.baysNoMotor.xCg])* ...
[obj.baysNoMotor.mass]')/obj.massNoMotor;
bNoMotor = values(remove(obj.bays, 'motor'))';
aPosNoMotor = values(remove(obj.absolutePositions, 'motor'))';
obj.xCgNoMotor = ((aPosNoMotor + [bNoMotor.xCg])* ...
[bNoMotor.mass]')/obj.massNoMotor;
end
function updateXCg(obj)
......@@ -112,7 +113,7 @@ classdef Rocket < Component
end
% Motor mass is 5th element of "bays"
obj.xCg = (obj.xCgNoMotor*obj.massNoMotor + ...
obj.motor.mass.*(obj.motor.xCg+obj.absolutePositions(5)))./ ...
obj.motor.mass.*(obj.motor.xCg+obj.absolutePositions('motor')'))./ ...
obj.mass;
end
......@@ -120,11 +121,13 @@ classdef Rocket < Component
if ~isempty(obj.inertiaNoMotor)
return;
end
bNoMotor = values(remove(obj.bays, 'motor'))';
aPosNoMotor = values(remove(obj.absolutePositions, 'motor'))';
% [3x1] Ix, Iy, Iz
% Assumption: xCgs are close to rocket axis
inertias = [obj.baysNoMotor.inertia];
inertias = [bNoMotor.inertia];
temp = inertias(2:3, :) + ...
(obj.xCgNoMotor - ([obj.absolutePositionsNoMotor] + [obj.baysNoMotor.xCg])).^2 .* [obj.baysNoMotor.mass];
(obj.xCgNoMotor' - (aPosNoMotor + [bNoMotor.xCg])).^2 .* [bNoMotor.mass];
obj.inertiaNoMotor = [inertias(1); sum(temp, 2)];
end
......@@ -135,7 +138,7 @@ classdef Rocket < Component
% [3x634] Ix, Iy, Iz
% Assumption: xCgs are close to rocket axis
motorInertia = obj.motor.inertia(2:3, :) + ...
(obj.xCg - (obj.absolutePositions(5) + obj.motor.xCg)).^2 .* obj.motor.mass;
(obj.xCg - (obj.absolutePositions('motor') + obj.motor.xCg)).^2 .* obj.motor.mass;
baysInertia = obj.inertiaNoMotor(2:3, :) + ...
(obj.xCg - obj.xCgNoMotor).^2 .* obj.massNoMotor;
......@@ -209,8 +212,8 @@ classdef Rocket < Component
obj.pitot = Pitot(mission, vars);
obj.parachutes = Parachute(mission);
[~, obj.bays] = obj.getProperties(Superclass='Bay', Heterogeneous=1);
obj.baysNoMotor = [obj.bays(1:4), obj.bays(6:end)]; % Take all bays except motor
[bayNames, bayValues] = obj.getProperties(Superclass='Bay', Heterogeneous=1);
obj.bays = dictionary(bayNames, bayValues);
obj.updateAll();
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment