Skip to content

Commit

Permalink
Merge pull request #2357 from pleroy/2331
Browse files Browse the repository at this point in the history
Extend the flight plan when it would end before the end of the last burn
pleroy authored Oct 17, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents cdccc60 + 070a154 commit ba9b8f9
Showing 3 changed files with 97 additions and 5 deletions.
24 changes: 19 additions & 5 deletions journal/player_test.cpp
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ TEST_F(PlayerTest, DISABLED_SECULAR_Debug) {
// An example of how journaling may be used for debugging. You must set
// |path| and fill the |method_in| and |method_out_return| protocol buffers.
std::string path =
R"(C:\Program Files\Kerbal Space Program\1.7.2\glog\Principia\JOURNAL.20191015-230454)"; // NOLINT
R"(C:\Program Files\Kerbal Space Program\1.7.2\glog\Principia\JOURNAL.20191015-230004)"; // NOLINT
Player player(path);
int count = 0;
while (player.Play(count)) {
@@ -106,19 +106,33 @@ TEST_F(PlayerTest, DISABLED_SECULAR_Debug) {
serialization::Method method_in;
{
auto* extension = method_in.MutableExtension(
serialization::FlightPlanGetGuidance::extension);
serialization::FlightPlanReplace::extension);
auto* in = extension->mutable_in();
in->set_plugin(2342492000);
in->set_plugin(1204843840);
in->set_vessel_guid("6615e657-7c13-4428-bb17-4d9009b4a458");
auto* const burn = in->mutable_burn();
burn->set_thrust_in_kilonewtons(250.00010393791362);
burn->set_specific_impulse_in_seconds_g0(350);
auto* const frame = burn->mutable_frame();
frame->set_extension(6000);
frame->set_centre_index(1);
frame->set_primary_index(0);
frame->set_secondary_index(0);
burn->set_initial_time(3894.6399999993528);
auto* const delta_v = burn->mutable_delta_v();
delta_v->set_x(0);
delta_v->set_y(0);
delta_v->set_z(0);
burn->set_is_inertially_fixed(true);
in->set_index(0);
}
serialization::Method method_out_return;
{
auto* extension = method_out_return.MutableExtension(
serialization::FlightPlanGetGuidance::extension);
serialization::FlightPlanReplace::extension);
}
LOG(ERROR) << "Running unpaired method:\n" << method_in.DebugString();
CHECK(RunIfAppropriate<FlightPlanGetGuidance>(
CHECK(RunIfAppropriate<FlightPlanReplace>(
method_in, method_out_return, player));
#endif
}
6 changes: 6 additions & 0 deletions ksp_plugin/flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -428,6 +428,12 @@ Status FlightPlan::ComputeSegments(
AddLastSegment();
}
if (anomalous_segments_ == 0) {
// If the desired end time is before the end of the last burn, move it to
// that point. Otherwise we might try to integrate towards the past in
// CoastSegment. Also, it's the user-friendly thing to do: no point in
// having to extend the flight plan by hand.
desired_final_time_ =
std::max(desired_final_time_, segments_.back()->t_max());
Status const status = CoastSegment(desired_final_time_, segments_.back());
if (!status.ok()) {
overall_status.Update(status);
72 changes: 72 additions & 0 deletions ksp_plugin_test/flight_plan_test.cpp
Original file line number Diff line number Diff line change
@@ -4,12 +4,14 @@
#include <limits>
#include <vector>

#include "astronomy/epoch.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "integrators/embedded_explicit_generalized_runge_kutta_nyström_integrator.hpp"
#include "integrators/embedded_explicit_runge_kutta_nyström_integrator.hpp"
#include "integrators/methods.hpp"
#include "integrators/symmetric_linear_multistep_integrator.hpp"
#include "ksp_plugin/integrators.hpp"
#include "physics/degrees_of_freedom.hpp"
#include "physics/discrete_trajectory.hpp"
#include "physics/massive_body.hpp"
@@ -24,7 +26,9 @@ namespace principia {
namespace ksp_plugin {
namespace internal_flight_plan {

using astronomy::J2000;
using base::Error;
using base::make_not_null_shared;
using base::make_not_null_unique;
using geometry::Barycentre;
using geometry::Displacement;
@@ -537,6 +541,74 @@ TEST_F(FlightPlanTest, GuidedBurn) {
EXPECT_THAT(guided_final_speed, IsNear(1.40_⑴ * unguided_final_speed));
}

TEST_F(FlightPlanTest, Issue2331) {
FlightPlan flight_plan(
11024.436950683594 * Kilogram,
J2000 + 1130.8399999993526 * Second,
DegreesOfFreedom<Barycentric>(
Barycentric::origin +
Displacement<Barycentric>({-13607881359.190962 * Metre,
-1183506.3832585660 * Metre,
-109366.09411247486 * Metre}),
Velocity<Barycentric>({-639.01032564318075 * Metre / Second,
-8663.2671328991710 * Metre / Second,
-129.00845706608661 * Metre / Second})),
J2000 + 4280.4599499295282 * Second,
ephemeris_.get(),
DefaultPredictionParameters(),
DefaultBurnParameters());

Force const thrust = 250000.10393791363 * Newton;
SpecificImpulse const specific_impulse = 3432.3274999999999 * Metre / Second;
auto const frame =
make_not_null_shared<TestNavigationFrame>(*navigation_frame_);
bool const inertially_fixed = true;

NavigationManœuvre::Intensity intensity0;
intensity0.Δv =
Velocity<Frenet<NavigationFrame>>({2035.0000000000005 * Metre / Second,
0 * Metre / Second,
0 * Metre / Second});
NavigationManœuvre::Timing timing0;
timing0.initial_time = J2000 + 3894.6399999993528 * Second;
NavigationManœuvre::Burn const burn0{intensity0,
timing0,
thrust,
specific_impulse,
frame,
inertially_fixed};
flight_plan.Append(burn0);

NavigationManœuvre::Intensity intensity1;
intensity1.Δv =
Velocity<Frenet<NavigationFrame>>({819.29427681721018 * Metre / Second,
0 * Metre / Second,
0 * Metre / Second});
NavigationManœuvre::Timing timing1;
timing1.initial_time = J2000 + 4258.1383894665723 * Second;
NavigationManœuvre::Burn const burn1{intensity1,
timing1,
thrust,
specific_impulse,
frame,
inertially_fixed};
flight_plan.Append(burn1);

NavigationManœuvre::Intensity intensity2;
intensity2.Δv = Velocity<Frenet<NavigationFrame>>();
NavigationManœuvre::Timing timing2;
timing2.initial_time = J2000 + 3894.6399999993528 * Second;
NavigationManœuvre::Burn const burn2{intensity2,
timing2,
thrust,
specific_impulse,
frame,
inertially_fixed};

// This call used to check-fail.
flight_plan.Replace(burn2, 0);
}

TEST_F(FlightPlanTest, Serialization) {
flight_plan_->SetDesiredFinalTime(t0_ + 42 * Second);
EXPECT_OK(flight_plan_->Append(MakeFirstBurn()));

0 comments on commit ba9b8f9

Please sign in to comment.