Skip to content

Commit 7b43949

Browse files
authored
Merge pull request #8 from itchono/asc2024
ASC2024
2 parents 3838054 + 39d65e2 commit 7b43949

17 files changed

+333
-27
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ resources/**
1313
*.txt
1414

1515
# Animations
16-
anim
16+
anim
17+
18+
# Workspaces
19+
*.mat

postprocessing/plotting/imseq_vecex.m

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
function imseq_vecex(y, cfg, nfmax, view_dim)
2+
% plot for vector export, based on maximum # of vector lines and frames
3+
% Expect y to be (6, N)
4+
% no need to interpolate vectors unless you have VERY big skips in L
5+
% Reference: https://www.mathworks.com/help/matlab/ref/getframe.html
6+
% Splits by orbit number
7+
8+
[~, ~, ~, ~, ~, L] = unpack_mee(y);
9+
10+
if nargin < 3
11+
nfmax = 20;
12+
view_dim = 3;
13+
end
14+
15+
%% Data processing
16+
ind_orbits = find(diff(mod(L, 2*pi)) < 0);
17+
num_orbits = length(ind_orbits);
18+
19+
%% Initial plot stuff
20+
L_sample = linspace(0, 2*pi, 60);
21+
plot_sphere(0, 0, 0, 6378e3, [0.3010, 0.7450, 0.9330]);
22+
hold on
23+
24+
cm = colormap("turbo");
25+
th = title(sprintf("Orbit 1 of %d", num_orbits));
26+
27+
% plot initial trace
28+
cart_sample = mee2cartesian([repmat(y(1:5, 1), 1, numel(L_sample)); L_sample]);
29+
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(1, :), "DisplayName", "Initial Orbit", "LineWidth", 1, "LineStyle", "--");
30+
31+
% plot main orbit
32+
main_orbit = plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", "black", "DisplayName", "Current Orbit", "LineWidth", 1);
33+
34+
% plot final trace
35+
cart_sample = mee2cartesian([repmat(y(1:5, end), 1, numel(L_sample)); L_sample]);
36+
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(end, :), "DisplayName", "Final Orbit", "LineWidth", 1, "LineStyle", "--");
37+
38+
% colorbar
39+
colorbar;
40+
clim([1,num_orbits]);
41+
42+
axis equal
43+
view(view_dim)
44+
45+
%% Initialize path
46+
mkdir("anim")
47+
mkdir("anim", cfg.casename)
48+
49+
%% Animation
50+
% spacing; never plot more than 20 frames
51+
stride = max(1, ceil(num_orbits/nfmax));
52+
53+
% ensure we always plot the last orbit
54+
ii = 1; % counter
55+
for j = [1:stride:num_orbits, num_orbits]
56+
% Update plots
57+
idx = ind_orbits(j);
58+
cart_sample = mee2cartesian([repmat(y(1:5, idx), 1, numel(L_sample)); L_sample]);
59+
main_orbit.XData = cart_sample(1, :);
60+
main_orbit.YData = cart_sample(2, :);
61+
main_orbit.ZData = cart_sample(3, :);
62+
63+
% Add shadow of previous orbits
64+
colour_idx = ceil(j/num_orbits*length(cm));
65+
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(colour_idx, :), "LineWidth", 1);
66+
67+
th.String = sprintf("Orbit %d of %d", j, num_orbits);
68+
69+
% Draw and get frame
70+
drawnow
71+
72+
% https://www.mathworks.com/matlabcentral/answers/363832-some-figures-not-saving-as-vector-graphics-svg
73+
% https://www.mathworks.com/matlabcentral/answers/471164-print-pdf-to-a-specific-size
74+
hf = gcf;
75+
hf.Units = 'centimeters'; % set figure units to cm
76+
hf.PaperUnits = 'centimeters'; % set pdf printing paper units to cm
77+
hf.PaperSize = hf.Position(3:4); % assign to the pdf printing paper the size of the figure
78+
print(hf,'-vector','-dpdf',fullfile("anim", cfg.casename, sprintf("anim-%d.pdf", ii))) % pdf
79+
ii = ii + 1; % JANK but works
80+
end
81+
end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
% plot for vector export, maximum # of lines etc.
2+
3+
function plot_orbit_vecex(y)
4+
% Expect y to be (6, N)
5+
% Splits by orbit number so that maximum number of lines is under 300
6+
7+
[~, ~, ~, ~, ~, L] = unpack_mee(y);
8+
9+
%% Data processing
10+
ind_orbits = find(diff(mod(L, 2*pi)) < 0);
11+
num_orbits = length(ind_orbits);
12+
13+
%% Initial plot stuff
14+
L_sample = linspace(0, 2*pi, 60);
15+
plot_sphere(0, 0, 0, 6378e3, [0.3010, 0.7450, 0.9330]);
16+
hold on
17+
18+
cm = colormap("turbo");
19+
20+
NMAX = 200;
21+
22+
% spacing
23+
stride = max(1, ceil(num_orbits/NMAX));
24+
25+
% ensure we always plot the last orbit
26+
for j = [1:stride:num_orbits, num_orbits]
27+
% Update plots
28+
idx = ind_orbits(j);
29+
cart_sample = mee2cartesian([repmat(y(1:5, idx), 1, numel(L_sample)); L_sample]);
30+
31+
% Add shadow of previous orbits
32+
colour_idx = ceil(j/num_orbits*length(cm));
33+
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(colour_idx, :), "LineWidth", 0.5);
34+
end
35+
36+
title(sprintf("Earth Inertial Coordinates (Showing Every %d Orbits)", stride));
37+
xlabel("x (m)")
38+
ylabel("y (m)")
39+
zlabel("z (m)")
40+
cbar = colorbar;
41+
42+
% wrangle the discrete colorbar tick alignment
43+
cbscalein = cbar.Limits;
44+
cbscaleout = [0 num_orbits];
45+
nt = 8;
46+
ticks = linspace(cbscaleout(1),cbscaleout(2), nt);
47+
cbar.Ticks = diff(cbscalein)*(ticks-cbscaleout(1))/diff(cbscaleout) + cbscalein(1);
48+
cbar.TickLabels = round(linspace(0, num_orbits, nt)');
49+
50+
ylabel(cbar, "Orbit Number")
51+
axis equal;
52+
view(3)
53+
end

postprocessing/postprocess.m

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,26 @@
66
plot_elements_mee(y, t, cfg.y_target);
77
exportgraphics(hf1, fullfile("outputs", casename, 'orbital_elements.pdf'), 'ContentType', 'vector')
88

9-
hf2 = figure;
10-
plot_elements_ke(y, t, cfg.y_target);
11-
exportgraphics(hf2, fullfile("outputs", casename, 'orbital_elements_ke.pdf'), 'ContentType', 'vector')
9+
% KE plot is not very critical
10+
% hf2 = figure;
11+
% plot_elements_ke(y, t, cfg.y_target);
12+
% exportgraphics(hf2, fullfile("outputs", casename, 'orbital_elements_ke.pdf'), 'ContentType', 'vector')
1213

13-
% Split up plots
14-
hf3 = figure;
15-
plot_steering_history(y, t, cfg);
16-
exportgraphics(hf3, fullfile("outputs", casename, 'steering_history.pdf'), 'ContentType', 'vector')
14+
% old plot - nothing very useful came of it for production purposes
15+
% hf3 = figure;
16+
% plot_steering_history(y, t, cfg);
17+
% exportgraphics(hf3, fullfile("outputs", casename, 'steering_history.pdf'), 'ContentType', 'vector')
1718

18-
hf4 = figure;
19-
[y_interp, ~] = interp_mee(y, t, 100);
20-
plot_orbit_mee(y_interp);
21-
exportgraphics(hf4, fullfile("outputs", casename, 'trajectory_plot.png'), ...
22-
'Resolution', 300)
19+
% bitmap plot superceded by vector output
20+
% hf4 = figure;
21+
% [y_interp, ~] = interp_mee(y, t, 100);
22+
% plot_orbit_mee(y_interp);
23+
% exportgraphics(hf4, fullfile("outputs", casename, 'trajectory_plot.png'), ...
24+
% 'Resolution', 300)
25+
26+
hf5 = figure;
27+
plot_orbit_vecex(y);
28+
exportgraphics(hf5, fullfile("outputs", casename, 'trajectory_plot.pdf'), 'ContentType', 'vector')
2329

2430
%% Video
2531
anim_osculating_mee(y, fullfile("outputs", casename, 'trajectory_animation.mp4'));

scripts/benchmark_transfer.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
% Supposed to be a worst-case for the guidance law
44
% As of the latest version, we get a performance of 874 revolutions, and
55
% about 6.7 km/s of delta-v expenditure using the unpenalized law
6-
% to within a tolerance of 1e-3; somewhat sesitive to NDF angles
6+
% to within a tolerance of 1e-3; somewhat sensitive to NDF angles
77

88
%% Problem Definition
99
% Create a struct for neatness
@@ -14,7 +14,7 @@
1414
cfg.solver = @ode89;
1515
cfg.t_span = [0, 1e8];
1616
cfg.options = odeset('RelTol', 1e-4, "Stats", "on", "MaxStep", 1e4);
17-
cfg.tol = 1e-3;
17+
cfg.tol = 5e-3;
1818
cfg.guidance_weights = [1; 1; 1; 1; 1];
1919
cfg.penalty_param = 1;
2020
cfg.min_pe = 10000e3;

scripts/benchmark_transfer_j2.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%% Description
2-
% J2 version of benchmark transfer
2+
% Determine effects of J2 on benchmark transfer
33

44
%% Problem Definition
55
% Create a struct for neatness
@@ -10,7 +10,7 @@
1010
cfg.solver = @ode89;
1111
cfg.t_span = [0, 1e8];
1212
cfg.options = odeset('RelTol', 1e-4, "Stats", "on", "MaxStep", 1e4);
13-
cfg.tol = 1e-3;
13+
cfg.tol = 5e-3;
1414
cfg.guidance_weights = [1; 1; 1; 1; 1];
1515
cfg.penalty_param = 1;
1616
cfg.min_pe = 10000e3;

scripts/benchmark_transfer_optim.m renamed to scripts/benchmark_transfer_optim_100.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
cfg.t_span = [0, 1e8];
1212
cfg.options = odeset('RelTol', 1e-4, "Stats", "on", "MaxStep", 1e4);
1313
cfg.tol = 5e-3;
14-
cfg.guidance_weights = [1.774e+00; 5.149e-01; 3.327e-01; 9.925e+00; 5.317e-01];
14+
cfg.guidance_weights = [ 6.810e-01; 3.343e-01; 4.072e-01; 9.965e+00; 4.360e-01];
1515
cfg.penalty_param = 1;
1616
cfg.min_pe = 10000e3;
1717
cfg.penalty_weight = 0;
18-
cfg.kappa = deg2rad(64);
18+
cfg.kappa = deg2rad(61.3);
1919
cfg.dynamics = "mee";
2020
cfg.j2 = false;
2121

scripts/benchmark_transfer_optim_20.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%% Description
2+
% Version of benchmark transfer with optimized weights
3+
4+
%% Problem Definition
5+
% Create a struct for neatness
6+
cfg.y0 = [20000e3; 0.5; -0.2; 0.5; 0; 0];
7+
cfg.y_target = [25000e3; 0.2; 0.5; 0; 0.3];
8+
cfg.propulsion_model = @sail_thrust;
9+
cfg.steering_law = @quail;
10+
cfg.solver = @ode89;
11+
cfg.t_span = [0, 1e9];
12+
cfg.options = odeset('RelTol', 1e-4, "Stats", "on", "MaxStep", 1e4);
13+
cfg.tol = 5e-3;
14+
cfg.guidance_weights = [2.06270441; 0.95005485; 4.44929224; 6.58042015; 7.3647472 ];
15+
cfg.penalty_param = 1;
16+
cfg.min_pe = 10000e3;
17+
cfg.penalty_weight = 0;
18+
cfg.kappa = deg2rad(56.32);
19+
cfg.dynamics = "mee";
20+
cfg.j2 = false;
21+
22+
%% Run
23+
[~, cfg.casename, ~] = fileparts(mfilename);
24+
[y, t, dv] = run_mission(cfg);

scripts/benchmark_transfer_optim_j2.m renamed to scripts/benchmark_transfer_optim_200.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
cfg.t_span = [0, 1e8];
1212
cfg.options = odeset('RelTol', 1e-4, "Stats", "on", "MaxStep", 1e4);
1313
cfg.tol = 5e-3;
14-
cfg.guidance_weights = [1.774e+00; 5.149e-01; 3.327e-01; 9.925e+00; 5.317e-01];
14+
cfg.guidance_weights = [ 1.485e+00; 3.472e+00; 1.973e-01; 7.157e+00;
15+
9.814e+00];
1516
cfg.penalty_param = 1;
1617
cfg.min_pe = 10000e3;
1718
cfg.penalty_weight = 0;
18-
cfg.kappa = deg2rad(64);
19+
cfg.kappa = deg2rad(59.83);
1920
cfg.dynamics = "mee";
20-
cfg.j2 = true;
21+
cfg.j2 = false;
2122

2223
%% Run
2324
[~, cfg.casename, ~] = fileparts(mfilename);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
%% Description
2+
% Version of benchmark transfer with optimized weights
3+
4+
%% Problem Definition
5+
% Create a struct for neatness
6+
cfg.y0 = [20000e3; 0.5; -0.2; 0.5; 0; 0];
7+
cfg.y_target = [25000e3; 0.2; 0.5; 0; 0.3];
8+
cfg.propulsion_model = @sail_thrust;
9+
cfg.steering_law = @quail;
10+
cfg.solver = @ode89;
11+
cfg.t_span = [0, 1e8];
12+
cfg.options = odeset('RelTol', 1e-4, "Stats", "on", "MaxStep", 1e4);
13+
cfg.tol = 1e-2;
14+
cfg.guidance_weights = [ 6.827e-01; 9.304e-01; 1.111e+00; 3.386e+00;
15+
8.306e+00 ];
16+
cfg.penalty_param = 1;
17+
cfg.min_pe = 10000e3;
18+
cfg.penalty_weight = 0;
19+
cfg.kappa = deg2rad(62.51);
20+
cfg.dynamics = "mee";
21+
cfg.j2 = false;
22+
23+
%% Run
24+
[~, cfg.casename, ~] = fileparts(mfilename);
25+
[y, t, dv] = run_mission(cfg);

0 commit comments

Comments
 (0)