I think I've finished my first revision

This commit is contained in:
Connor
2022-02-28 15:29:02 -07:00
parent 445c1398ac
commit 9e3a720c49
17 changed files with 224 additions and 68 deletions

View File

@@ -2,6 +2,7 @@ using Thesis
using SPICE
using LinearAlgebra
using Dates
using PlotlyJS
try
furnsh("../../spice_files/naif0012.tls")
@@ -48,16 +49,59 @@ end
sorted_missions1 = sort(missions, by=cost_1)
sorted_missions2 = sort(missions, by=cost_2)
println(get_id.(sorted_missions1[1:10]))
println(get_id.(sorted_missions2[1:10]))
println(get_id.(sorted_missions1[1:5]))
println(get_id.(sorted_missions2[1:5]))
display_mission = improve(sorted_missions2[1], n=7)
# display(plot(display_mission,
# long, short = improve.(sorted_missions2[1:2], n=7)#, use_cost=true)
display_mission = long
# Display Orbit Plot
# display(Thesis.plot(long,
# title="Sample Algorithm Result Mission",
# mode="light",
# planet_colors=false,
# phase_colors=["#F00","#F0F","#6AF"],
# markers=false));
display(plot_thrust(display_mission, title="Thrust Magnitude vs Time", mode="light"))
display(plot_thrust_components(display_mission, title="Thrust Components vs Time", mode="light"))
# markers=false,
# camera=((-0.2, -0.3, -0.2),(1.75,-1.75,1.5))));
# Save Orbit Plot
savefig(Thesis.plot(short, title="EMS Mission Profile", mode="light", planet_colors=false,
phase_colors=["#F00","#F0F","#6AF"], markers=false,
camera=((-0.2, 0.1, -0.3),(-2.,-2.,1.))),
"/home/connor/projects/thesis/LaTeX/fig/EMS_plot.png",
width=850, height=400)
savefig(Thesis.plot(short, title="EMS Mission Profile", mode="light", planet_colors=false,
phase_colors=["#F00","#F0F","#6AF"], markers=false, planets=false,
camera=((-0.2, 0.1, -0.3),(-2.,-2.,1.))),
"/home/connor/projects/thesis/LaTeX/fig/EMS_plot_noplanets.png",
width=850, height=400)
savefig(Thesis.plot(long, title="EMS Mission Profile", mode="light", planet_colors=false,
phase_colors=["#F00","#F0F","#6AF"], markers=false,
camera=((-0.2, -0.3, -0.2),(1.75,-1.75,1.5))),
"/home/connor/projects/thesis/LaTeX/fig/EMJS_plot.png",
width=850, height=400)
savefig(Thesis.plot(long, title="EMS Mission Profile", mode="light", planet_colors=false,
phase_colors=["#F00","#F0F","#6AF"], markers=false, planets=false,
camera=((-0.2, -0.3, -0.2),(2.,-2.,1.5))),
"/home/connor/projects/thesis/LaTeX/fig/EMJS_plot_noplanets.png",
width=850, height=400)
# Display Thrust Plots
# display(plot_thrust(display_mission, title="Thrust Magnitude vs Time", mode="light"))
# display(plot_thrust_components(display_mission, title="Thrust Components vs Time", mode="light"))
# Save Thrust Plots
savefig(plot_thrust(short, title="Thrust Magnitude vs Time", mode="light"),
"/home/connor/projects/thesis/LaTeX/fig/EMS_thrust_mag.png",
width=850, height=400)
savefig(plot_thrust_components(short, title="Thrust Components vs Time", mode="light"),
"/home/connor/projects/thesis/LaTeX/fig/EMS_thrust_components.png",
width=850, height=400)
savefig(plot_thrust(long, title="Thrust Magnitude vs Time", mode="light"),
"/home/connor/projects/thesis/LaTeX/fig/EMJS_thrust_mag.png",
width=850, height=400)
savefig(plot_thrust_components(long, title="Thrust Components vs Time", mode="light"),
"/home/connor/projects/thesis/LaTeX/fig/EMJS_thrust_components.png",
width=850, height=400)
# Save mission
# store(display_mission, "/home/connor/projects/thesis/archive/best/long_mission")

7
julia/porkchop.jl Normal file
View File

@@ -0,0 +1,7 @@
using Dates
using Thesis
departures = collect(DateTime(2023,7,1):Dates.Day(1):DateTime(2023,12,1))
arrivals = collect(DateTime(2025,6,1):Dates.Day(1):DateTime(2026,1,1))
p = porkchop(Earth, Mars, departures, arrivals)
display(p);

View File

@@ -344,7 +344,7 @@ end
"""
Increases the fidelity of a mission by using it as a base and resolving with increased number of points
"""
function improve(mission::Mission; n::Int=5)
function improve(mission::Mission; n::Int=5, use_cost=false)
new_phases = Vector{Phase}()
for phase in mission.phases
new_thrusts = repeat(phase.thrust_profile, inner=(n,1))
@@ -366,7 +366,8 @@ function improve(mission::Mission; n::Int=5)
arrival + Dates.Day(7),
200.,
20.,
CPU_multiplier = 30.
CPU_multiplier = 60.,
use_cost=use_cost,
)
new_mission.converged || error("Mission improvement failed")
return new_mission

View File

@@ -1,4 +1,4 @@
export oe_to_rθh, rθh_to_xyz, oe_to_xyz, xyz_to_oe, conv_T, spiral, gen_orbit
export oe_to_rθh, rθh_to_xyz, oe_to_xyz, xyz_to_oe, xyz_to_rθh, conv_T, spiral, gen_orbit
function oe_to_rθh(oe::Vector,μ::Real) :: Vector
@@ -25,6 +25,18 @@ function rθh_to_xyz(rθh_vec::Vector,oe::Vector)
end
function xyz_to_rθh(xyz_vec::Vector,oe::Vector)
a,e,i,Ω,ω,ν = oe
θ = ω+ν
,,ci,si,, = cos(Ω),sin(Ω),cos(i),sin(i),cos(θ),sin(θ)
DCM = [*-*ci* -*-*ci* *si;
*+*ci* -*+*ci* -*si;
si* si* ci]
return inv(DCM)*xyz_vec
end
function oe_to_xyz(oe::Vector,μ::Real)
return rθh_to_xyz(oe_to_rθh(oe,μ),oe)

View File

@@ -1,3 +1,5 @@
export lamberts, porkchop
"""
I didn't want to have to write this...I'm going to try to do this as quickly as possible from old,
bad code
@@ -68,3 +70,47 @@ function lamberts(planet1::Body,planet2::Body,leave::DateTime,arrive::DateTime)
return v0t - state1[4:6], vft - state2[4:6], tof_req
end
function porkchop(planet1::Body, planet2::Body, departures::Vector{DateTime}, arrivals::Vector{DateTime})
v∞_in = [ norm(lamberts(planet1, planet2, depart, arrive)[2]) for depart in departures, arrive in arrivals ]
v∞_out = [ norm(lamberts(planet1, planet2, depart, arrive)[1]) for depart in departures, arrive in arrivals ]
c3 = [ norm(lamberts(planet1, planet2, depart, arrive)[1])^2 for depart in departures, arrive in arrivals ]
traces = Vector{PlotlyJS.AbstractTrace}()
outputs = (v∞_in, v∞_out)
names = ("Earth Departure v∞", "Mars Arrival v∞")
colors = ("#0A0", "#A0A")
for (output, name, color) in zip(outputs, names, colors)
push!(traces, contour(x=departures,
y=arrivals,
z=output,
name=name,
contours_coloring="none",
contours_showlabels=true,
contours_start=12,
contours_end=20,
contours_size=2,
line_color=color,
line_width=2,
showscale=false,
))
push!(traces, contour(x=departures,
y=arrivals,
z=output,
showlegend=false,
contours_coloring="none",
contours_showlabels=true,
contours_start=0,
contours_end=10,
contours_size=1,
line_color=color,
line_width=2,
showscale=false,
))
end
layout = Layout(title_text="Sample Porkchop Earth->Mars Plot",
xaxis_title="Departure Date",
yaxis_title="Arrival Date",
margin_l=120,
)
return PlotlyJS.plot(traces, layout)
end

View File

@@ -309,7 +309,10 @@ function plot(m::Union{Mission, Mission_Guess};
mode::String="dark",
planet_colors=true,
phase_colors=nothing,
markers=true)
markers=true,
planets=true,
camera=nothing,
)
# First plot the earth
# Then plot phase plus planet phase
time = datetime2julian(m.launch_date)
@@ -325,7 +328,11 @@ function plot(m::Union{Mission, Mission_Guess};
end
end
start = state(current_planet, time, m.launch_v∞, mass)
traces = [ earth_trace... ]
if planets
traces = [ earth_trace... ]
else
traces = Vector{PlotlyJS.AbstractTrace}()
end
i = 1
for phase in m.phases
@@ -365,8 +372,10 @@ function plot(m::Union{Mission, Mission_Guess};
color="#000")
end
end
push!(traces, planet_trace...)
limit = max(limit, new_limit)
if planets
push!(traces, planet_trace...)
limit = max(limit, new_limit)
end
i += 1
end
@@ -376,6 +385,14 @@ function plot(m::Union{Mission, Mission_Guess};
# Determine layout details
layout = standard_layout(limit, title, mode=mode)
if camera !== nothing
layout["scene_camera_center_x"] = camera[1][1]
layout["scene_camera_center_y"] = camera[1][2]
layout["scene_camera_center_z"] = camera[1][3]
layout["scene_camera_eye_x"] = camera[2][1]
layout["scene_camera_eye_y"] = camera[2][2]
layout["scene_camera_eye_z"] = camera[2][3]
end
# Plot
PlotlyJS.plot( PlotlyJS.Plot( traces, layout ) )
@@ -410,30 +427,40 @@ function plot_thrust(m::Union{Mission, Mission_Guess};
title::String="Mission Plot",
mode::String="dark",
)
times = Vector{Float64}()
times = Vector{String}()
vals = Vector{Float64}()
time = datetime2julian(m.launch_date)
start = state(Earth, time, m.launch_v∞, m.start_mass)
traces = Vector{PlotlyJS.AbstractTrace}()
limits = Vector{Float64}()
for phase in m.phases
# First get the path
n = size(phase.thrust_profile)[1]
for i in 1:n
push!(times, format(julian2datetime(time + i*phase.tof/(86400n)),"yyyy-mm-dd HH:MM:SS"))
push!(vals, norm(phase.thrust_profile[i,:]))
end
path = prop(phase.thrust_profile, start, m.sc, phase.tof)
time += phase.tof/86400.
time_string = format(julian2datetime(time),"yyyy-mm-dd HH:MM:SS")
push!(traces, scatter(;x=[time_string, time_string],
y=[-1.0,1.0],
mode="lines",
line_color="#000",
name=phase.planet.name*" Flyby"))
mass = path[end,end]
start = state(phase.planet, time, phase.v∞_out, mass)
n = size(phase.thrust_profile)[1]
println(n)
for i in 1:n
push!(times, time + i*phase.tof/(86400n))
push!(vals, norm(phase.thrust_profile[i]))
end
end
trace = scatter(;x=times, y=vals)
push!(traces, scatter(;x=times, y=vals, name="Thrust Mag"))
# Determine layout details
layout = Layout(;title=title, xaxis_title="Time (JD)", yaxis_title="Thrust (% of Max)")
layout = Layout(;title=title,
xaxis_title="Year",
yaxis_title="Thrust (% of Max)",
yaxis_range=[0.0,maximum(vals)*1.02],
)
# Plot
PlotlyJS.plot( PlotlyJS.Plot( [trace], layout ) )
PlotlyJS.plot( PlotlyJS.Plot( traces, layout ) )
end
@@ -441,37 +468,50 @@ function plot_thrust_components(m::Union{Mission, Mission_Guess};
title::String="Mission Plot",
mode::String="dark",
)
times = Vector{Float64}()
vals1 = Vector{Float64}()
vals2 = Vector{Float64}()
vals3 = Vector{Float64}()
traces = Vector{PlotlyJS.AbstractTrace}()
times = Vector{String}()
xs = Vector{Float64}()
ys = Vector{Float64}()
zs = Vector{Float64}()
αs = Vector{Float64}()
βs = Vector{Float64}()
time = datetime2julian(m.launch_date)
start = state(Earth, time, m.launch_v∞, m.start_mass)
for phase in m.phases
# First get the path
n = size(phase.thrust_profile)[1]
path = prop(phase.thrust_profile, start, m.sc, phase.tof)
for i in 1:n
push!(times, format(julian2datetime(time + i*phase.tof/(86400n)),"yyyy-mm-dd HH:MM:SS"))
push!(xs, phase.thrust_profile[i,1])
push!(ys, phase.thrust_profile[i,2])
push!(zs, phase.thrust_profile[i,3])
r, θ, h = xyz_to_rθh(phase.thrust_profile[i,1:3], xyz_to_oe(path[i+1,1:6],Sun.μ))
β = asin(h)
α = atan(r/cos(β),θ/cos(β))
push!(αs, α)
push!(βs, β)
end
time += phase.tof/86400.
time_string = format(julian2datetime(time),"yyyy-mm-dd HH:MM:SS")
push!(traces, scatter(;x=[time_string, time_string],
y=[-10.0,10.0],
mode="lines",
line_color="#000",
name=phase.planet.name*" Flyby"))
mass = path[end,end]
start = state(phase.planet, time, phase.v∞_out, mass)
n = size(phase.thrust_profile)[1]
println(n)
for i in 1:n
push!(times, time + i*phase.tof/(86400n))
push!(vals1, phase.thrust_profile[i,1])
push!(vals2, phase.thrust_profile[i,2])
push!(vals3, phase.thrust_profile[i,3])
end
end
trace1 = scatter(;x=times, y=vals1, name="x component")
trace2 = scatter(;x=times, y=vals2, name="y component")
trace3 = scatter(;x=times, y=vals3, name="z component")
push!(traces, scatter(;x=times, y=αs, name="in-plane angle"))
push!(traces, scatter(;x=times, y=βs, name="out-of-plane angle"))
# Determine layout details
layout = Layout(;title=title,
xaxis_title="Time (JD)",
yaxis_title="Thrust (% of Max)")
xaxis_title="Year",
yaxis_title="Thrust Angle (Radians)",
yaxis_range=[min(minimum(αs),minimum(βs))*1.02,max(maximum(αs),maximum(βs))*1.02],
)
# Plot
PlotlyJS.plot( PlotlyJS.Plot( [trace1, trace2, trace3], layout ) )
PlotlyJS.plot( PlotlyJS.Plot( traces, layout ) )
end