@testset "Phase" begin using PlotlyJS: savefig println("Testing NLP solver") # Test the optimizer for a one-phase mission # The lambert's solver said this should be pretty valid launch_window = [DateTime(1992,11,1), DateTime(1992,12,1)] latest_arrival = DateTime(1993,6,1) leave, arrive = DateTime(1992,11,19), DateTime(1993,4,1) test_leave = DateTime(1992,11,12) earth_state = state(Earth, leave) venus_state = state(Venus, arrive) v∞_out, v∞_in, tof = Thesis.lamberts(Earth, Venus, leave, arrive) # We can get the thrust profile and tof pretty wrong and still be ok phase = Phase(Venus, 1.1v∞_in, v∞_in, 0.9*tof, 0.1*ones(20,3)) guess = Mission_Guess(bepi, 12_000., test_leave, 0.9*v∞_out, [phase]) m = solve_mission(guess, launch_window, latest_arrival, verbose=true) @test typeof(m) == Mission @test m.converged == true # Now we can plot the results to check visually p = plot(m, title="NLP Test Solution") savefig(p,"../plots/nlp_test_1_phase.html") # Now we can look at a more complicated trajectory flybys = [Earth, Venus, Mars] launch_window = [DateTime(2021,10,1), DateTime(2021,12,1)] latest_arrival = DateTime(2023,1,1) dates = [DateTime(2021,11,1), DateTime(2022,3,27), DateTime(2022,8,28)] phases = Vector{Phase}() launch_v∞, _, tof1 = Thesis.lamberts(flybys[1], flybys[2], dates[1], dates[2]) println(launch_v∞) for i in 1:length(dates)-2 v∞_out1, v∞_in1, tof1 = Thesis.lamberts(flybys[i], flybys[i+1], dates[i], dates[i+1]) v∞_out2, v∞_in2, tof2 = Thesis.lamberts(flybys[i+1], flybys[i+2], dates[i+1], dates[i+2]) push!(phases, Phase(flybys[i+1], v∞_in1, v∞_out2, tof1, 0.01*ones(20,3))) end v∞_out, v∞_in, tof = Thesis.lamberts(flybys[end-1], flybys[end], dates[end-1], dates[end]) push!(phases, Phase(flybys[end], v∞_in, v∞_in, tof, 0.01*ones(20,3))) # This isn't quite right. V∞ discrepancy is too big guess = Mission_Guess(bepi, 12_000., dates[1], launch_v∞, phases) m = solve_mission(guess, launch_window, latest_arrival, verbose=true) p = plot(m, title="NLP Test Solution (2 Phases)") savefig(p,"../plots/nlp_test_2_phase.html") end