From 32301968b7c6af7e93f1a38e6927098a1180152a Mon Sep 17 00:00:00 2001 From: giuliaghirardini <giuliaghirardini2001@gmail.com> Date: Mon, 18 Nov 2024 21:33:40 +0100 Subject: [PATCH] [xcg-study][utils] Added data and implemented function to plot fins only --- utils/xCgStudy/finsGenerator.m | 49 ++++++++++++++++++++++++++++++++ utils/xCgStudy/importfile.m | 47 ++++++++++++++++++++++++++++++ utils/xCgStudy/lyraXCGdata.mat | 3 ++ utils/xCgStudy/optsettings.txt | 5 ++++ utils/xCgStudy/xCG - Foglio3.csv | 7 +++++ utils/xCgStudy/xCG - Foglio4.csv | 7 +++++ 6 files changed, 118 insertions(+) create mode 100644 utils/xCgStudy/finsGenerator.m create mode 100644 utils/xCgStudy/importfile.m create mode 100644 utils/xCgStudy/lyraXCGdata.mat create mode 100644 utils/xCgStudy/optsettings.txt create mode 100644 utils/xCgStudy/xCG - Foglio3.csv create mode 100644 utils/xCgStudy/xCG - Foglio4.csv diff --git a/utils/xCgStudy/finsGenerator.m b/utils/xCgStudy/finsGenerator.m new file mode 100644 index 00000000..e4175b24 --- /dev/null +++ b/utils/xCgStudy/finsGenerator.m @@ -0,0 +1,49 @@ +clc +clear + +%% generate mission +mission = Mission(true); +rocket = Rocket(mission); + +%% evaluate data +r = rocket.diameter/2*1000; + +filename = 'xCG - Foglio3.csv'; +xCGopt = importfile(filename); +[ncases, ~] = size(xCGopt); + +%% aspect ratio +area = ((xCGopt.attachedChord + xCGopt.freeChord).*xCGopt.height./2).*2; +span = r*ones(ncases, 1) + xCGopt.height.*2; +lambda = area./span.^2; + +%% plot +for i = 1:ncases + plotFins(xCGopt.attachedChord(i), xCGopt.freeChord(i), xCGopt.deltaXle(i), ... + xCGopt.height(i), r, xCGopt.xcgNoMotor(i)); +end + +%% function +function plotFins(C1, C2, deltaXLE, height, r, xcgnomotor) + figure(); + + plotFin1 = plot([0 deltaXLE], [r r+height],'k', 'Linewidth', 1.2); hold on + set(plotFin1,'Tag','gaplotFin1'); + plotFin2 = plot([C1 deltaXLE+C2], [r r+height],'r', 'Linewidth', 1.2); + set(plotFin2,'Tag','gaplotFin2'); + plotFin3 = plot([deltaXLE deltaXLE+C2], [r+height r+height],'b', 'Linewidth', 1.2); + set(plotFin3,'Tag','gaplotFin3'); + plot([0 C1], [r r], 'g', 'Linewidth', 1.2); + plot([0 deltaXLE], [r+height r+height],'k--') + plot([deltaXLE deltaXLE], [r+height r],'m--') + + legend({'l1','l2',['freeChord = ',num2str(C2),' mm'], ... + ['attachedChord = ',num2str(C1),' mm'], ['deltaXLE = ',num2str(deltaXLE),' mm'], ... + ['height = ',num2str(height),' mm']}, 'Location', 'southoutside', ... + 'NumColumns', 2) + axis equal + xlabel('x [mm]'); ylabel('y [mm]'); title('Current Best Shape') + title('Fins optimization result') + subtitle(['xcg no motor = ',num2str(xcgnomotor),' m']) + grid('minor') +end \ No newline at end of file diff --git a/utils/xCgStudy/importfile.m b/utils/xCgStudy/importfile.m new file mode 100644 index 00000000..0d2ef868 --- /dev/null +++ b/utils/xCgStudy/importfile.m @@ -0,0 +1,47 @@ +function xCGFoglio3 = importfile(filename, dataLines) +%IMPORTFILE Import data from a text file +% XCGFOGLIO3 = IMPORTFILE(FILENAME) reads data from text file FILENAME +% for the default selection. Returns the data as a table. +% +% XCGFOGLIO3 = IMPORTFILE(FILE, DATALINES) reads data for the specified +% row interval(s) of text file FILENAME. Specify DATALINES as a +% positive scalar integer or a N-by-2 array of positive scalar integers +% for dis-contiguous row intervals. +% +% Example: +% xCGFoglio3 = importfile("D:\GitHub\xCG - Foglio3.csv", [2, Inf]); +% +% See also READTABLE. +% +% Auto-generated by MATLAB on 10-Nov-2024 00:13:23 + +%% Input handling + +% If dataLines is not specified, define defaults +if nargin < 2 + dataLines = [2, Inf]; +end + +%% Set up the Import Options and import the data +opts = delimitedTextImportOptions("NumVariables", 5); + +% Specify range and delimiter +opts.DataLines = dataLines; +opts.Delimiter = ","; + +% Specify column names and types +opts.VariableNames = ["xcgNoMotor", "attachedChord", "freeChord", "deltaXle", "height"]; +opts.VariableTypes = ["double", "double", "double", "double", "double"]; + +% Specify file level properties +opts.ExtraColumnsRule = "ignore"; +opts.EmptyLineRule = "read"; + +% Specify variable properties +opts = setvaropts(opts, "xcgNoMotor", "TrimNonNumeric", true); +opts = setvaropts(opts, "xcgNoMotor", "DecimalSeparator", ","); + +% Import the data +xCGFoglio3 = readtable(filename, opts); + +end \ No newline at end of file diff --git a/utils/xCgStudy/lyraXCGdata.mat b/utils/xCgStudy/lyraXCGdata.mat new file mode 100644 index 00000000..3fb416e9 --- /dev/null +++ b/utils/xCgStudy/lyraXCGdata.mat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96b60a2da0240bd3756d53bbf6f31a54c6314cb1a8d6bdc57b922829463cc277 +size 4012 diff --git a/utils/xCgStudy/optsettings.txt b/utils/xCgStudy/optsettings.txt new file mode 100644 index 00000000..b414031b --- /dev/null +++ b/utils/xCgStudy/optsettings.txt @@ -0,0 +1,5 @@ +options = optimoptions('ga', 'MaxStallGenerations', 5, 'FunctionTolerance', ... + 1/settings.optimization.expectedApogee, 'MaxGenerations', 12, 'NonlinearConstraintAlgorithm', 'penalty',... + 'PopulationSize', 500, 'PlotFcn', {'gaplotbestindiv', 'gaplotbestf',... + @(options, state, flag) gaplotshape(rocket, settings, options, state, flag)},... + 'Display', 'iter', 'UseParallel', settings.optimization.parpool, 'UseVectorized', false); diff --git a/utils/xCgStudy/xCG - Foglio3.csv b/utils/xCgStudy/xCG - Foglio3.csv new file mode 100644 index 00000000..f6098622 --- /dev/null +++ b/utils/xCgStudy/xCG - Foglio3.csv @@ -0,0 +1,7 @@ +xcg no motor,attached chord,free chord,delta xle,height +"1,0276",30,12,13,13 +"1,1",30,13,14,15 +"1,05",30,10,20,15 +"1,115",30,12,17,15 +"1,12",30,11,19,15 +"1,121",30,12,17,15 \ No newline at end of file diff --git a/utils/xCgStudy/xCG - Foglio4.csv b/utils/xCgStudy/xCG - Foglio4.csv new file mode 100644 index 00000000..2f4f6a35 --- /dev/null +++ b/utils/xCgStudy/xCG - Foglio4.csv @@ -0,0 +1,7 @@ +xcg no motor,attached chord,free chord,delta xle,height +"0,725",30,10,17,12 +"0,75",30,10,12,12 +"0,775",30,10,13,12 +"0,8",30,10,19,12 +"0,8273",30,10,11,13 +"1,0276",30,12,13,13 \ No newline at end of file -- GitLab