From b478bd2dfd36b3221e5bc2a242df67fd0314564b Mon Sep 17 00:00:00 2001 From: Mauco03 <marco.gaibotti@skywarder.eu> Date: Mon, 17 Feb 2025 08:28:09 +0100 Subject: [PATCH] [handle-value-conversion] Updated Parachutes in simulator --- classes/@Rocket/Rocket.m | 4 +++- classes/@Rocket/update.m | 15 ++++++++++++++- functions/eventFunctions/eventParaCut.m | 2 +- functions/odeFunctions/descentParachute.m | 6 +++--- functions/odeFunctions/descentParafoil.m | 2 +- functions/simulations/stdAscent.m | 4 ++-- functions/simulations/stdDescent.m | 12 ++++++------ 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/classes/@Rocket/Rocket.m b/classes/@Rocket/Rocket.m index 8da0e3c..5d91e4b 100644 --- a/classes/@Rocket/Rocket.m +++ b/classes/@Rocket/Rocket.m @@ -18,7 +18,8 @@ classdef Rocket < Config cutoffInertia (3, 1) double % [kg*m^2] Total inertia at motor cutoff inertiaDot (3, :) double % [kg*m^2/s]Total inertia time derivative - stagesMass double % [kg] Mass of stage 2, 3, .. without chutes + stagesMass (1, :) double % [kg] Mass of stage 2, 3, .. without chutes + stagesInertia (3, :) double % [kg*m^2] Inertia of stage 2, 3, .. without chutes crossSection (1, 1) double % [m^2] Rocket cross sectional area end @@ -101,6 +102,7 @@ classdef Rocket < Config options.checkGeometry logical = true end obj@Config(mission, varsIn); + obj.mission = mission; %% Initialize base properties bayNames = camel2UpperSnake(obj.getProperties(Superclass='Bay')); diff --git a/classes/@Rocket/update.m b/classes/@Rocket/update.m index 4400d73..ae246b7 100644 --- a/classes/@Rocket/update.m +++ b/classes/@Rocket/update.m @@ -38,8 +38,21 @@ if ~override('INERTIA') end %% Cutoff +cutoffXcg = interp1(obj.time, obj.xcg, obj.cutoffTime, "linear", 'extrap'); obj.cutoffMass = interp1(obj.time, obj.mass, obj.cutoffTime, "linear", 'extrap'); obj.cutoffInertia = interp1(obj.time, obj.inertia', obj.cutoffTime, "linear", 'extrap')'; -end +%% Stages +% TODO! generalize for n stages, variable input +obj.stagesMass = zeros(1, 2); +obj.stagesMass(1) = obj.cutoffMass - obj.PARAFOIL.mass; % MAIN mass +obj.stagesMass(2) = obj.PARAFOIL.mass; + +IParafoil = obj.PARAFOIL.inertia + ... + (cutoffXcg - (obj.PARAFOIL.xcg + obj.PARAFOIL.position))^2 * [0, 1, 1] * ... + obj.PARAFOIL.mass; +obj.stagesInertia = zeros(3, 2); +obj.stagesInertia(:, 1) = obj.cutoffInertia - IParafoil'; % MAIN mass +obj.stagesInertia(:, 2) = obj.PARAFOIL.inertia'; +end \ No newline at end of file diff --git a/functions/eventFunctions/eventParaCut.m b/functions/eventFunctions/eventParaCut.m index 7e7d3be..211813d 100644 --- a/functions/eventFunctions/eventParaCut.m +++ b/functions/eventFunctions/eventParaCut.m @@ -40,7 +40,7 @@ altitude = -Y(3); para = descentData.para; stage = descentData.stage; -value = altitude - rocket.parachutes(para, stage).finalAltitude; +value = altitude - rocket.parachutes{para, stage}.finalAltitude; isterminal = 1; direction = 0; diff --git a/functions/odeFunctions/descentParachute.m b/functions/odeFunctions/descentParachute.m index bbca96a..47beab9 100644 --- a/functions/odeFunctions/descentParachute.m +++ b/functions/odeFunctions/descentParachute.m @@ -47,9 +47,9 @@ dY = zeros(6, 1); para = descentData.para; % defined in stdRun {para = i; settings.paraNumber = para;} stage = descentData.stage; -S = rocket.parachutes(para, stage).surface; % [m^2] Surface -CD = rocket.parachutes(para, stage).cd; % [/] Parachute Drag Coefficient -CL = rocket.parachutes(para, stage).cl; % [/] Parachute Lift Coefficient +S = rocket.parachutes{para, stage}.surface; % [m^2] Surface +CD = rocket.parachutes{para, stage}.cd; % [/] Parachute Drag Coefficient +CL = rocket.parachutes{para, stage}.cl; % [/] Parachute Lift Coefficient m = rocket.stagesMass(stage); diff --git a/functions/odeFunctions/descentParafoil.m b/functions/odeFunctions/descentParafoil.m index ec73f32..3b40dac 100644 --- a/functions/odeFunctions/descentParafoil.m +++ b/functions/odeFunctions/descentParafoil.m @@ -50,7 +50,7 @@ qz = Y(13); deltaA = Y(14); dY = zeros(13, 1); -parafoil = rocket.parachutes(descentData.para, descentData.stage); +parafoil = rocket.parachutes{descentData.para, descentData.stage}; %% GETTING DATA % environment diff --git a/functions/simulations/stdAscent.m b/functions/simulations/stdAscent.m index f0ef8d5..60f9812 100644 --- a/functions/simulations/stdAscent.m +++ b/functions/simulations/stdAscent.m @@ -54,8 +54,8 @@ t0 = 0; solution = ode113(@ballistic, [t0, tf], Y0, options, ... rocket, env, wind, [], 0, wrapper); -if settings.simulator.parachute && ~isempty(rocket.parachutes(1, 1).openingTime) && rocket.parachutes(1, 1).openingTime - solution = odextend(solution, [], solution.x(end) + rocket.parachutes(1, 1).openingTime); +if settings.simulator.parachute && ~isempty(rocket.parachutes{1, 1}.openingTime) && rocket.parachutes{1, 1}.openingTime + solution = odextend(solution, [], solution.x(end) + rocket.parachutes{1, 1}.openingTime); end if nargout == 2 diff --git a/functions/simulations/stdDescent.m b/functions/simulations/stdDescent.m index 10076a5..b4b077e 100644 --- a/functions/simulations/stdDescent.m +++ b/functions/simulations/stdDescent.m @@ -107,13 +107,13 @@ for i = 1:nParachutes descentData.para = i; for j = 1:nStages descentData.stage = j; - if isempty(rocket.parachutes(i, j).name), continue; end + if isempty(rocket.parachutes{i, j}.name), continue; end if i ~= 1 && ~isempty(descent(i-1, j).state) prev = descent(i-1, j); end wrapper.reset(); - switch class(rocket.parachutes(i, j)) + switch class(rocket.parachutes{i, j}) case 'Parachute' Y0 = [prev.state.Y(1:3, end); prev.state.Y(4:6, end)]; @@ -144,14 +144,14 @@ for i = 1:nParachutes rocket, environment, wind, descentData, [], 0, wrapper); otherwise error('Unrecognized para type for descent: %s', ... - class(rocket.parachutes(i, j))) + class(rocket.parachutes{i, j})) end - if i < nParachutes && rocket.parachutes(i+1, j).openingTime - solution = odextend(solution, [], solution.x(end) + rocket.parachutes(1, 1).openingTime); + if i < nParachutes && rocket.parachutes{i+1, j}.openingTime + solution = odextend(solution, [], solution.x(end) + rocket.parachutes{1, 1}.openingTime); end - if i < nParachutes && -solution.y(3, end) < rocket.parachutes(i+1, j).finalAltitude + if i < nParachutes && -solution.y(3, end) < rocket.parachutes{i+1, j}.finalAltitude error("Chute (%d, %d) has arrived at a lower altitude than Chute (%d, %d) target altitude." + ... " Please lower Chute (%d, %d) opening delay or target altitude.", i, j, i+1, j); end -- GitLab