Skip to content

Commit

Permalink
Merge pull request #6 from itchono/develop-110
Browse files Browse the repository at this point in the history
Presentation Push
  • Loading branch information
itchono authored Apr 5, 2024
2 parents d8f47e7 + b00d630 commit fef7238
Show file tree
Hide file tree
Showing 49 changed files with 1,222 additions and 250 deletions.
3 changes: 2 additions & 1 deletion init.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

% 1) Add all subfolders to path
base_path = fileparts(which(mfilename));
subdir_names = ["postprocessing", "scripts", "sim", "steering", "utils"];
subdir_names = ["postprocessing", "scripts", "sim",...
"tests", "steering", "utils"];
for subdir = subdir_names
path_to_add = genpath(fullfile(base_path, subdir));
fprintf("Adding path: %s\n", path_to_add);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function plot_osculating_mee(y, save_path)
function anim_osculating_mee(y, save_path)
% Expect y to be (6, N)
% no need to interpolate vectors unless you have VERY big skips in L
% Reference: https://www.mathworks.com/help/matlab/ref/getframe.html
% Splits by orbit number

[p, f, g, h, k, L] = unpack_mee(y);
[~, ~, ~, ~, ~, L] = unpack_mee(y);

%% Data processing
ind_orbits = find(diff(mod(L, 2*pi)) < 0);
Expand All @@ -21,14 +21,14 @@ function plot_osculating_mee(y, save_path)
th = title(sprintf("Orbit 1 of %d", num_orbits));

% plot initial trace
cart_sample = mee2cartesian(p(1), f(1), g(1), h(1), k(1), L_sample);
cart_sample = mee2cartesian([repmat(y(1:5, 1), 1, numel(L_sample)); L_sample]);
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(1, :), "DisplayName", "Initial Orbit", "LineWidth", 1, "LineStyle", "--");

% plot main orbit
main_orbit = plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", "black", "DisplayName", "Current Orbit", "LineWidth", 1);

% plot final trace
cart_sample = mee2cartesian(p(end), f(end), g(end), h(end), k(end), L_sample);
cart_sample = mee2cartesian([repmat(y(1:5, end), 1, numel(L_sample)); L_sample]);
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(end, :), "DisplayName", "Final Orbit", "LineWidth", 1, "LineStyle", "--");

axis equal
Expand All @@ -41,20 +41,25 @@ function plot_osculating_mee(y, save_path)

%% Animation
F(num_orbits) = struct('cdata', [], 'colormap', []);
for j = [1:3:num_orbits, num_orbits]

% spacing; never plot more than 300 frames (10 seconds at 30fps)
stride = max(1, ceil(num_orbits/300));

% ensure we always plot the last orbit
for j = [1:stride:num_orbits, num_orbits]
% Update plots
idx = ind_orbits(j);
cart_sample = mee2cartesian(p(idx), f(idx), g(idx), h(idx), k(idx), L_sample);
cart_sample = mee2cartesian([repmat(y(1:5, idx), 1, numel(L_sample)); L_sample]);
main_orbit.XData = cart_sample(1, :);
main_orbit.YData = cart_sample(2, :);
main_orbit.ZData = cart_sample(3, :);

% Add shadow of previous orbits
colour_idx = ceil(j/num_orbits*length(cm));
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(colour_idx, :), "DisplayName", "Current Orbit", "LineWidth", 0.5);

plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(colour_idx, :), "LineWidth", 0.5);
th.String = sprintf("Orbit %d of %d", j, num_orbits);

% Draw and get frame
drawnow
F(j) = getframe(fh);
Expand Down
74 changes: 74 additions & 0 deletions postprocessing/plotting/imseq_fancy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function imseq_fancy(y, save_path, nfmax, view_dim)
% Expect y to be (6, N)
% no need to interpolate vectors unless you have VERY big skips in L
% Reference: https://www.mathworks.com/help/matlab/ref/getframe.html
% Splits by orbit number

[~, ~, ~, ~, ~, L] = unpack_mee(y);

if nargin < 3
nfmax = 20;
view_dim = 3;
end

%% Data processing
ind_orbits = find(diff(mod(L, 2*pi)) < 0);
num_orbits = length(ind_orbits);

%% Initial plot stuff
L_sample = linspace(0, 2*pi, 100);
plot_sphere(0, 0, 0, 6378e3, [0.3010, 0.7450, 0.9330]);
hold on

cm = colormap("turbo");
th = title(sprintf("Orbit 1 of %d", num_orbits));

% plot initial trace
cart_sample = mee2cartesian([repmat(y(1:5, 1), 1, numel(L_sample)); L_sample]);
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(1, :), "DisplayName", "Initial Orbit", "LineWidth", 1, "LineStyle", "--");

% plot main orbit
main_orbit = plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", "black", "DisplayName", "Current Orbit", "LineWidth", 1);

% plot final trace
cart_sample = mee2cartesian([repmat(y(1:5, end), 1, numel(L_sample)); L_sample]);
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(end, :), "DisplayName", "Final Orbit", "LineWidth", 1, "LineStyle", "--");

% colorbar
colorbar;
clim([1,num_orbits]);

axis equal
view(view_dim)

%% Initialize path
workingDir = save_path;
mkdir(workingDir)
mkdir(workingDir,"images")

%% Animation
% spacing; never plot more than 20 frames
stride = max(1, ceil(num_orbits/nfmax));

% ensure we always plot the last orbit
ii = 1; % counter
for j = [1:stride:num_orbits, num_orbits]
% Update plots
idx = ind_orbits(j);
cart_sample = mee2cartesian([repmat(y(1:5, idx), 1, numel(L_sample)); L_sample]);
main_orbit.XData = cart_sample(1, :);
main_orbit.YData = cart_sample(2, :);
main_orbit.ZData = cart_sample(3, :);

% Add shadow of previous orbits
colour_idx = ceil(j/num_orbits*length(cm));
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(colour_idx, :), "LineWidth", 1);

th.String = sprintf("Orbit %d of %d", j, num_orbits);

% Draw and get frame
drawnow
exportgraphics(gcf, fullfile(workingDir,"images",sprintf("anim-%d.png", ii)))
ii = ii + 1; % JANK but works
end
end
68 changes: 68 additions & 0 deletions postprocessing/plotting/imseq_osculating_mee.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function imseq_osculating_mee(y, save_path, view_dim)
% Expect y to be (6, N)
% no need to interpolate vectors unless you have VERY big skips in L
% Reference: https://www.mathworks.com/help/matlab/ref/getframe.html
% Splits by orbit number

[~, ~, ~, ~, ~, L] = unpack_mee(y);

if nargin < 3
view_dim = 3;
end

%% Data processing
ind_orbits = find(diff(mod(L, 2*pi)) < 0);
num_orbits = length(ind_orbits);

%% Initial plot stuff
L_sample = linspace(0, 2*pi, 100);
plot_sphere(0, 0, 0, 6378e3, [0.3010, 0.7450, 0.9330]);
hold on

cm = colormap("winter");

% plot initial trace
cart_sample = mee2cartesian([repmat(y(1:5, 1), 1, numel(L_sample)); L_sample]);
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(1, :), "DisplayName", "Initial Orbit", "LineWidth", 1, "LineStyle", "--");

% plot main orbit
main_orbit = plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", "black", "DisplayName", "Current Orbit", "LineWidth", 1);

% plot final trace
cart_sample = mee2cartesian([repmat(y(1:5, end), 1, numel(L_sample)); L_sample]);
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(end, :), "DisplayName", "Final Orbit", "LineWidth", 1, "LineStyle", "--");

axis equal
axis off
view(view_dim)

%% Initialize path
workingDir = save_path;
mkdir(workingDir)
mkdir(workingDir,"images")

%% Animation
% spacing; never plot more than 20 frames
stride = max(1, ceil(num_orbits/20));

% ensure we always plot the last orbit
ii = 1; % counter
for j = [1:stride:num_orbits, num_orbits]
% Update plots
idx = ind_orbits(j);
cart_sample = mee2cartesian([repmat(y(1:5, idx), 1, numel(L_sample)); L_sample]);
main_orbit.XData = cart_sample(1, :);
main_orbit.YData = cart_sample(2, :);
main_orbit.ZData = cart_sample(3, :);

% Add shadow of previous orbits
colour_idx = ceil(j/num_orbits*length(cm));
plot3(cart_sample(1, :), cart_sample(2, :), cart_sample(3, :), "Color", cm(colour_idx, :), "LineWidth", 0.5);


% Draw and get frame
drawnow
exportgraphics(gcf, fullfile(workingDir,"images",sprintf("anim-%d.png", ii)))
ii = ii + 1; % JANK but works
end
end
18 changes: 0 additions & 18 deletions postprocessing/plotting/plot_animated_mee.m

This file was deleted.

57 changes: 42 additions & 15 deletions postprocessing/plotting/plot_elements_ke.m
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
function plot_elements_ke(y, t, y_target)
[p, f, g, h, k, L] = unpack_mee(y);
[a, e, i, Omega, omega, theta] = mee2keplerian(p, f, g, h, k, L);
[a, e, i, Omega, omega, ~] = mee2keplerian(p, f, g, h, k, L);

ra = a .* (1 + e);
rp = a .* (1 - e);

days = t/86400;

% size
fh = gcf();
fh.Position(3:4) = [560, 600];

% Plots orbital elements in stacked plots
tiledlayout(2, 1, 'TileSpacing', 'tight');

% Plots orbital elements in stacked plots
subplot(211)
plot(t/86400, a, "Color", [0, 0.4470, 0.7410], "LineWidth", 1);
ax1 = nexttile;
plot(days, a, "Color", [0, 0.4470, 0.7410], "LineWidth", 1);
hold on
plot(t/86400, ra, "LineWidth", 1);
plot(t/86400, rp, "LineWidth", 1);
plot(days, ra, "LineWidth", 1);
plot(days, rp, "LineWidth", 1);
legend("SMA", "AP Radius", "PE Radius", "Location", "best")
title("Evolution of Orbital Elements");
ylabel("Radius")
grid
ylabel("Orbit Size (m)")
grid on
grid minor

subplot(212)
plot(t/86400, i, "LineWidth", 1)
ax2 = nexttile;
plot(days, i, "LineWidth", 1)
hold on
plot(t/86400, Omega, "LineWidth", 1)
plot(t/86400, omega, "LineWidth", 1);
legend("Inc", "\Omega", "\omega", "Location", "best");
ylabel("Orientation")
grid
plot(days, Omega, "LineWidth", 1)
plot(days, omega, "LineWidth", 1);
legend("i", "\Omega", "\omega", "Location", "best");
ylabel("Orientation (deg)")
grid on
grid minor

xlabel("Elapsed Time (Days)")

% Link x
linkaxes([ax1, ax2],'x')

% Tight xlim and final
for aa = [ax1, ax2]
xlim(aa, [min(days), max(days)])
xticks(aa, [xticks, round(max(days))])
end

% Top label
set(ax1,'XAxisLocation','top')
converted_values = floor(interp1(t, L, xticks*86400, "linear", "extrap") /(2 * pi));
set(ax1, "XTickLabels", converted_values);
xlabel(ax1,'Orbit Number')

end
55 changes: 40 additions & 15 deletions postprocessing/plotting/plot_elements_mee.m
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
function plot_elements_mee(y, t, y_target)
[p, f, g, h, k, ~] = unpack_mee(y);
[p, f, g, h, k, L] = unpack_mee(y);

days = t/86400;

% size
fh = gcf();
fh.Position(3:4) = [560, 600];

% Plots orbital elements in stacked plots
subplot(311)
plot(t/86400, p, "Color", [0, 0.4470, 0.7410], "LineWidth", 1);
tiledlayout(3, 1, 'TileSpacing', 'tight');

ax1 = nexttile;
plot(days, p, "Color", [0, 0.4470, 0.7410], "LineWidth", 1);
yline(y_target(1), "--", "Color", [0, 0.4470, 0.7410], "LineWidth", 1);
legend("p", "Location", "best")
title("Evolution of Orbital Elements");
ylabel("Semi-Latus Rect.")
grid
ylabel("Orbit Size (m)")
grid on
grid minor

subplot(312)
plot(t/86400, f, "Color", [0.8500, 0.3250, 0.0980], "LineWidth", 1)
ax2 = nexttile;
plot(days, f, "Color", [0.8500, 0.3250, 0.0980], "LineWidth", 1)
hold on
plot(t/86400, g, "Color", [0.4660, 0.6740, 0.1880], "LineWidth", 1)
plot(days, g, "Color", [0.4660, 0.6740, 0.1880], "LineWidth", 1)
yline(y_target(2), "--", "Color", [0.8500, 0.3250, 0.0980], "LineWidth", 1)
yline(y_target(3), "--", "Color", [0.4660, 0.6740, 0.1880], "LineWidth", 1)
legend("f", "g", "Location", "best");
ylabel("Ecc. Vector")
grid
ylabel("Eccentricity Vector")
set(gca,'XTickLabel',[]);
grid on
grid minor

subplot(313)
plot(t/86400, h, "Color", [0.9290, 0.6940, 0.1250], "LineWidth", 1)
ax3 = nexttile;
plot(days, h, "Color", [0.9290, 0.6940, 0.1250], "LineWidth", 1)
hold on
plot(t/86400, k, "Color", [0.4940, 0.1840, 0.5560], "LineWidth", 1);
plot(days, k, "Color", [0.4940, 0.1840, 0.5560], "LineWidth", 1);
yline(y_target(4), "--", "Color", [0.9290, 0.6940, 0.1250], "LineWidth", 1)
yline(y_target(5), "--", "Color", [0.4940, 0.1840, 0.5560], "LineWidth", 1)
legend("h", "k", "Location", "best");
ylabel("Nodal Position")
grid
grid on
grid minor

xlabel("Elapsed Time (Days)")

% Link x
linkaxes([ax1, ax2, ax3],'x')

% Tight xlim and final
for aa = [ax1, ax2, ax3]
xlim(aa, [min(days), max(days)])
xticks(aa, [xticks, round(max(days))])
end

% Top label
set(ax1,'XAxisLocation','top')
converted_values = floor(interp1(t, L, xticks*86400, "linear", "extrap") /(2 * pi));
set(ax1, "XTickLabels", converted_values);
xlabel(ax1,'Orbit Number')
end
Loading

0 comments on commit fef7238

Please sign in to comment.