Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4098b8a816b4
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d6da6cabbaf0
Choose a head ref
  • 6 commits
  • 5 files changed
  • 1 contributor

Commits on Apr 1, 2020

  1. Copy the full SHA
    4b29b5b View commit details
  2. Copy the full SHA
    72c7972 View commit details
  3. Copy the full SHA
    9a45e37 View commit details

Commits on Apr 2, 2020

  1. Copy the full SHA
    0007ba5 View commit details
  2. Fix the test.

    pleroy committed Apr 2, 2020
    Copy the full SHA
    1ee27cd View commit details

Commits on Apr 3, 2020

  1. Merge pull request #2518 from pleroy/852

    Extend the flight plan when the last manœuvre is moved forward or extended
    pleroy authored Apr 3, 2020
    Copy the full SHA
    d6da6ca View commit details
Showing with 32 additions and 18 deletions.
  1. +11 −2 ksp_plugin/flight_plan.cpp
  2. +3 −0 ksp_plugin/manœuvre.hpp
  3. +10 −5 ksp_plugin/manœuvre_body.hpp
  4. +7 −4 ksp_plugin_adapter/flight_planner.cs
  5. +1 −7 ksp_plugin_test/flight_plan_test.cpp
13 changes: 11 additions & 2 deletions ksp_plugin/flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -173,8 +173,17 @@ Status FlightPlan::Replace(NavigationManœuvre::Burn const& burn,
if (manœuvre.IsSingular()) {
return Singular();
}
if (!manœuvre.FitsBetween(start_of_previous_coast(index),
start_of_next_burn(index))) {
if (index == number_of_manœuvres() - 1) {
// This is the last manœuvre. If it doesn't fit just because the flight
// plan is too short, extend the flight plan.
if (manœuvre.IsAfter(start_of_previous_coast(index))) {
desired_final_time_ =
std::max(desired_final_time_, manœuvre.final_time());
} else {
return DoesNotFit();
}
} else if (!manœuvre.FitsBetween(start_of_previous_coast(index),
start_of_next_burn(index))) {
return DoesNotFit();
}

3 changes: 3 additions & 0 deletions ksp_plugin/manœuvre.hpp
Original file line number Diff line number Diff line change
@@ -119,6 +119,9 @@ class Manœuvre {
// Returns true if ‖Δv‖ is NaN or infinite.
bool IsSingular() const;

// Returrns true if and only if time < initial_time;
bool IsAfter(Instant const& time) const;

// Returns true if and only if [initial_time, final_time] ⊆ ]begin, end[.
bool FitsBetween(Instant const& begin, Instant const& end) const;

15 changes: 10 additions & 5 deletions ksp_plugin/manœuvre_body.hpp
Original file line number Diff line number Diff line change
@@ -153,14 +153,19 @@ Instant Manœuvre<InertialFrame, Frame>::final_time() const {
}

template<typename InertialFrame, typename Frame>
bool Manœuvre<InertialFrame, Frame>::FitsBetween(Instant const& begin,
Instant const& end) const {
return begin < initial_time() && final_time() < end;
bool Manœuvre<InertialFrame, Frame>::IsSingular() const {
return !IsFinitev().Norm²());
}

template<typename InertialFrame, typename Frame>
bool Manœuvre<InertialFrame, Frame>::IsSingular() const {
return !IsFinitev().Norm²());
bool Manœuvre<InertialFrame, Frame>::IsAfter(Instant const& time) const {
return time < initial_time();
}

template<typename InertialFrame, typename Frame>
bool Manœuvre<InertialFrame, Frame>::FitsBetween(Instant const& begin,
Instant const& end) const {
return begin < initial_time() && final_time() < end;
}

template<typename InertialFrame, typename Frame>
11 changes: 7 additions & 4 deletions ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ protected override void RenderWindow(int window_id) {
RenderFlightPlan(vessel_guid);
} else if (UnityEngine.GUILayout.Button("Create flight plan")) {
plugin.FlightPlanCreate(vessel_guid,
plugin.CurrentTime() + 1000,
plugin.CurrentTime() + 3600,
vessel_.GetTotalMass());
final_time_.value = plugin.FlightPlanGetDesiredFinalTime(vessel_guid);
Shrink();
@@ -149,9 +149,11 @@ private void RenderFlightPlan(string vessel_guid) {
var status = plugin.FlightPlanSetDesiredFinalTime(vessel_guid,
final_time_.value);
UpdateStatus(status, null);
final_time_.value =
plugin.FlightPlanGetDesiredFinalTime(vessel_guid);
}
// Always refresh the final time from C++ as it may have changed because
// the last burn changed.
final_time_.value =
plugin.FlightPlanGetDesiredFinalTime(vessel_guid);

FlightPlanAdaptiveStepParameters parameters =
plugin.FlightPlanGetAdaptiveStepParameters(vessel_guid);
@@ -244,7 +246,8 @@ private void RenderFlightPlan(string vessel_guid) {
plugin.FlightPlanGetManoeuvre(vessel_guid, i + 1).
burn.initial_time);
}
final_times.Add(plugin.FlightPlanGetActualFinalTime(vessel_guid));
// Allow extending the flight plan.
final_times.Add(double.PositiveInfinity);
int number_of_anomalous_manœuvres =
plugin.FlightPlanNumberOfAnomalousManoeuvres(vessel_guid);

8 changes: 1 addition & 7 deletions ksp_plugin_test/flight_plan_test.cpp
Original file line number Diff line number Diff line change
@@ -411,18 +411,12 @@ TEST_F(FlightPlanTest, Replace) {
flight_plan_->GetManœuvre(flight_plan_->number_of_manœuvres() - 1).
final_mass();
EXPECT_EQ(1, flight_plan_->number_of_manœuvres());
EXPECT_THAT(flight_plan_->Replace(MakeThirdBurn(), /*index=*/0),
StatusIs(FlightPlan::does_not_fit));
EXPECT_EQ(old_final_mass,
flight_plan_->GetManœuvre(flight_plan_->number_of_manœuvres() - 1).
final_mass());
EXPECT_EQ(1, flight_plan_->number_of_manœuvres());
flight_plan_->SetDesiredFinalTime(t0_ + 42 * Second);
EXPECT_OK(flight_plan_->Replace(MakeThirdBurn(), /*index=*/0));
EXPECT_GT(old_final_mass,
flight_plan_->GetManœuvre(flight_plan_->number_of_manœuvres() - 1).
final_mass());
EXPECT_EQ(1, flight_plan_->number_of_manœuvres());
EXPECT_LT(t0_ + 1.7 * Second, flight_plan_->desired_final_time());
}

TEST_F(FlightPlanTest, Segments) {