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: c0c9a3434e59
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b2a80b5f2be8
Choose a head ref
  • 10 commits
  • 9 files changed
  • 1 contributor

Commits on Jun 6, 2019

  1. Copy the full SHA
    8a469f5 View commit details
  2. Copy the full SHA
    6c59749 View commit details
  3. Full edition of manœuvres.

    pleroy committed Jun 6, 2019
    Copy the full SHA
    fcd976a View commit details
  4. Spelling.

    pleroy committed Jun 6, 2019
    Copy the full SHA
    51bbf61 View commit details

Commits on Jun 7, 2019

  1. Fix test.

    pleroy committed Jun 7, 2019
    Copy the full SHA
    bbfb493 View commit details

Commits on Jun 8, 2019

  1. Copy the full SHA
    0d83600 View commit details

Commits on Jun 9, 2019

  1. Better remedy.

    pleroy committed Jun 9, 2019
    Copy the full SHA
    2f8329c View commit details
  2. Cleanup.

    pleroy committed Jun 9, 2019
    Copy the full SHA
    493102a View commit details
  3. Support partial disablement.

    pleroy committed Jun 9, 2019
    Copy the full SHA
    39e093d View commit details
  4. Merge pull request #2197 from pleroy/ReplaceLast

    Support edition of all manœuvres in a flight plan
    pleroy authored Jun 9, 2019
    Copy the full SHA
    b2a80b5 View commit details
4 changes: 0 additions & 4 deletions ksp_plugin/flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -200,10 +200,6 @@ Status FlightPlan::Replace(NavigationManœuvre::Burn const& burn,
return ComputeSegments(manœuvres_.begin() + index, manœuvres_.end());
}

Status FlightPlan::ReplaceLast(NavigationManœuvre::Burn const& burn) {
return Replace(burn, manœuvres_.size() - 1);
}

Status FlightPlan::SetDesiredFinalTime(Instant const& desired_final_time) {
if (desired_final_time < start_of_last_coast()) {
return BadDesiredFinalTime();
4 changes: 0 additions & 4 deletions ksp_plugin/flight_plan.hpp
Original file line number Diff line number Diff line change
@@ -97,10 +97,6 @@ class FlightPlan {
// Otherwise, updates the flight plan and returns the integration status.
virtual Status Replace(NavigationManœuvre::Burn const& burn, int index);

// Same as above, but for the last manœuvre. |number_of_manœuvres()| must be
// at least one..
virtual Status ReplaceLast(NavigationManœuvre::Burn const& burn);

// Updates the desired final time of the flight plan. Returns an error and
// has no effect |desired_final_time| is before the beginning of the last
// coast.
12 changes: 0 additions & 12 deletions ksp_plugin/interface_flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -469,18 +469,6 @@ Status principia__FlightPlanReplace(Plugin const* const plugin,
index)));
}

Status principia__FlightPlanReplaceLast(Plugin const* const plugin,
char const* const vessel_guid,
Burn const burn) {
journal::Method<journal::FlightPlanReplaceLast> m({plugin,
vessel_guid,
burn});
CHECK_NOTNULL(plugin);
auto& flight_plan = GetFlightPlan(*plugin, vessel_guid);
return m.Return(ToStatus(GetFlightPlan(*plugin, vessel_guid).
ReplaceLast(FromInterfaceBurn(*plugin, burn))));
}

Status principia__FlightPlanSetAdaptiveStepParameters(
Plugin const* const plugin,
char const* const vessel_guid,
34 changes: 21 additions & 13 deletions ksp_plugin_adapter/burn_editor.cs
Original file line number Diff line number Diff line change
@@ -59,12 +59,11 @@ public BurnEditor(PrincipiaPluginAdapter adapter,

// Renders the |BurnEditor|. Returns true if and only if the settings were
// changed.
public bool Render(string header,
bool enabled,
double? actual_final_time = null) {
public bool Render(string header,
bool anomalous,
double final_time) {
bool changed = false;
previous_coast_duration_.max_value =
(actual_final_time ?? double.PositiveInfinity) - time_base;
previous_coast_duration_.max_value = final_time - time_base;
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label(header);
string frame_info = "";
@@ -86,7 +85,12 @@ public bool Render(string header,
engine_warning_ = "";
ComputeEngineCharacteristics();
}
if (enabled) {

// The frame selector is disabled for an anomalous manœuvre as is has no
// effect.
if (anomalous) {
reference_frame_selector_.Hide();
} else {
using (new UnityEngine.GUILayout.HorizontalScope()) {
if (UnityEngine.GUILayout.Button("Active Engines")) {
engine_warning_ = "";
@@ -103,8 +107,6 @@ public bool Render(string header,
}
}
reference_frame_selector_.RenderButton();
} else {
reference_frame_selector_.Hide();
}
if (is_inertially_fixed_ !=
UnityEngine.GUILayout.Toggle(is_inertially_fixed_,
@@ -113,13 +115,19 @@ public bool Render(string header,
is_inertially_fixed_ = !is_inertially_fixed_;
}
changed |= changed_reference_frame_;
changed |= Δv_tangent_.Render(enabled);
changed |= Δv_normal_.Render(enabled);
changed |= Δv_binormal_.Render(enabled);

// The Δv controls are disabled for an anomalous manœuvre as they have no
// effect.
changed |= Δv_tangent_.Render(enabled : !anomalous);
changed |= Δv_normal_.Render(enabled : !anomalous);
changed |= Δv_binormal_.Render(enabled : !anomalous);
{
var render_time_base = time_base;
previous_coast_duration_.value = initial_time_ - render_time_base;
if (previous_coast_duration_.Render(enabled)) {

// The duration of the previous coast is always enabled as it can make
// a manœuvre non-anomalous.
if (previous_coast_duration_.Render(enabled : true)) {
changed = true;
initial_time_ = previous_coast_duration_.value + render_time_base;
}
@@ -140,7 +148,7 @@ public bool Render(string header,
Style.Warning(UnityEngine.GUI.skin.label));
changed_reference_frame_ = false;
}
return changed && enabled;
return changed;
}

public double Δv() {
119 changes: 63 additions & 56 deletions ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -132,12 +132,12 @@ private void UpdateVesselAndBurnEditors() {
if (burn_editors_ != null) {
string vessel_guid = vessel_?.id.ToString();
double current_time = plugin.CurrentTime();
first_future_manoeuvre_ = null;
first_future_manœuvre_ = null;
for (int i = 0; i < burn_editors_.Count; ++i) {
NavigationManoeuvre manoeuvre =
NavigationManoeuvre manœuvre =
plugin.FlightPlanGetManoeuvre(vessel_guid, i);
if (current_time < manoeuvre.final_time) {
first_future_manoeuvre_ = i;
if (current_time < manœuvre.final_time) {
first_future_manœuvre_ = i;
break;
}
}
@@ -238,25 +238,32 @@ private void RenderFlightPlan(string vessel_guid) {
if (burn_editors_.Count > 0) {
RenderUpcomingEvents();
}

// Compute the final times for each manœuvre before displaying them.
var final_times = new List<double>();
for (int i = 0; i < burn_editors_.Count - 1; ++i) {
Style.HorizontalLine();
burn_editors_[i].Render(header: "Manœuvre #" + (i + 1),
enabled : false);
final_times.Add(
plugin.FlightPlanGetManoeuvre(vessel_guid, i + 1).
burn.initial_time);
}
if (burn_editors_.Count > 0) {
final_times.Add(plugin.FlightPlanGetActualFinalTime(vessel_guid));
int number_of_anomalous_manœuvres =
plugin.FlightPlanNumberOfAnomalousManoeuvres(vessel_guid);

for (int i = 0; i < burn_editors_.Count; ++i) {
Style.HorizontalLine();
BurnEditor last_burn = burn_editors_.Last();
if (last_burn.Render(header : "Editing manœuvre #" +
(burn_editors_.Count),
enabled : true,
actual_final_time : actual_final_time)) {
var status = plugin.FlightPlanReplaceLast(vessel_guid,
last_burn.Burn());
UpdateStatus(status, burn_editors_.Count - 1);
last_burn.Reset(
plugin.FlightPlanGetManoeuvre(vessel_guid,
burn_editors_.Count - 1));
BurnEditor burn = burn_editors_[i];
if (burn.Render(header : "Manœuvre #" + (i + 1),
anomalous : i >= (burn_editors_.Count -
number_of_anomalous_manœuvres),
final_time : final_times[i])) {
var status = plugin.FlightPlanReplace(vessel_guid, burn.Burn(), i);
UpdateStatus(status, i);
burn.Reset(plugin.FlightPlanGetManoeuvre(vessel_guid, i));
}
}

if (burn_editors_.Count > 0) {
if (UnityEngine.GUILayout.Button(
"Delete last manœuvre",
UnityEngine.GUILayout.ExpandWidth(true))) {
@@ -301,26 +308,26 @@ private void RenderUpcomingEvents() {
double current_time = plugin.CurrentTime();

Style.HorizontalLine();
if (first_future_manoeuvre_.HasValue) {
int first_future_manoeuvre = first_future_manoeuvre_.Value;
NavigationManoeuvre manoeuvre =
plugin.FlightPlanGetManoeuvre(vessel_guid, first_future_manoeuvre);
if (manoeuvre.burn.initial_time > current_time) {
if (first_future_manœuvre_.HasValue) {
int first_future_manœuvre = first_future_manœuvre_.Value;
NavigationManoeuvre manœuvre =
plugin.FlightPlanGetManoeuvre(vessel_guid, first_future_manœuvre);
if (manœuvre.burn.initial_time > current_time) {
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label("Upcoming manœuvre #" +
(first_future_manoeuvre + 1) + ":");
(first_future_manœuvre + 1) + ":");
UnityEngine.GUILayout.Label(
"Ignition " + FormatTimeSpan(TimeSpan.FromSeconds(
current_time - manoeuvre.burn.initial_time)),
current_time - manœuvre.burn.initial_time)),
style : Style.RightAligned(UnityEngine.GUI.skin.label));
}
} else {
using (new UnityEngine.GUILayout.HorizontalScope()) {
UnityEngine.GUILayout.Label("Ongoing manœuvre #" +
(first_future_manoeuvre + 1) + ":");
(first_future_manœuvre + 1) + ":");
UnityEngine.GUILayout.Label(
"Cutoff " + FormatTimeSpan(TimeSpan.FromSeconds(
current_time - manoeuvre.final_time)),
current_time - manœuvre.final_time)),
style : Style.RightAligned(UnityEngine.GUI.skin.label));
}
}
@@ -334,7 +341,7 @@ private void RenderUpcomingEvents() {
show_guidance_ =
UnityEngine.GUILayout.Toggle(show_guidance_, "Show on navball");
if (UnityEngine.GUILayout.Button("Warp to manœuvre")) {
TimeWarp.fetch.WarpTo(manoeuvre.burn.initial_time - 60);
TimeWarp.fetch.WarpTo(manœuvre.burn.initial_time - 60);
}
}
}
@@ -411,25 +418,25 @@ internal bool TryParsePlanLength(string str, out double value) {
return true;
}

private void UpdateStatus(Status status, int? error_manoeuvre) {
private void UpdateStatus(Status status, int? error_manœuvre) {
if (message_was_displayed_) {
status_ = Status.OK;
first_error_manoeuvre_ = null;
first_error_manœuvre_ = null;
message_was_displayed_ = false;
}
if (status_.ok() && !status.ok()) {
status_ = status;
first_error_manoeuvre_ = error_manoeuvre;
first_error_manœuvre_ = error_manœuvre;
}
}

private string GetStatusMessage() {
string vessel_guid = vessel_?.id.ToString();
string message = "";
if (vessel_guid != null && !status_.ok()) {
int anomalous_manoeuvres =
int anomalous_manœuvres =
plugin.FlightPlanNumberOfAnomalousManoeuvres(vessel_guid);
int manoeuvres = plugin.FlightPlanNumberOfManoeuvres(vessel_guid);
int manœuvres = plugin.FlightPlanNumberOfManoeuvres(vessel_guid);
double actual_final_time =
plugin.FlightPlanGetActualFinalTime(vessel_guid);
bool timed_out = actual_final_time < final_time_.value;
@@ -452,41 +459,41 @@ private string GetStatusMessage() {
"centre of a celestial)" + time_out_message;
remedy_message = "avoiding collisions with a celestial";
} else if (status_.is_invalid_argument()) {
status_message = "manoeuvre #" + (first_error_manoeuvre_.Value + 1) +
status_message = "manœuvre #" + (first_error_manœuvre_.Value + 1) +
" would result in an infinite or indeterminate " +
"velocity";
remedy_message = "adjusting the duration of manoeuvre #" +
(first_error_manoeuvre_.Value + 1);
remedy_message = "adjusting the duration of manœuvre #" +
(first_error_manœuvre_.Value + 1);
} else if (status_.is_out_of_range()) {
if (first_error_manoeuvre_.HasValue) {
status_message = "manoeuvre #" + (first_error_manoeuvre_.Value + 1) +
if (first_error_manœuvre_.HasValue) {
status_message = "manœuvre #" + (first_error_manœuvre_.Value + 1) +
" overlaps with " +
((first_error_manoeuvre_.Value == 0)
((first_error_manœuvre_.Value == 0)
? "the start of the flight plan"
: "manoeuvre #" +
first_error_manoeuvre_.Value) + " or " +
((first_error_manoeuvre_.Value == manoeuvres - 1)
: "manœuvre #" +
first_error_manœuvre_.Value) + " or " +
((first_error_manœuvre_.Value == manœuvres - 1)
? "the end of the flight plan"
: "manoeuvre #" +
(first_error_manoeuvre_.Value + 2));
remedy_message = ((first_error_manoeuvre_.Value == manoeuvres - 1)
: "manœuvre #" +
(first_error_manœuvre_.Value + 2));
remedy_message = ((first_error_manœuvre_.Value == manœuvres - 1)
? "extending the flight plan or "
: "") +
"increasing the initial time or reducing the " +
"duration of manoeuvre #" +
(first_error_manoeuvre_.Value + 1);
"adjusting the initial time or reducing the " +
"duration of manœuvre #" +
(first_error_manœuvre_.Value + 1);
} else {
status_message = "flight plan final time overlaps the last " +
"manoeuvre";
"manœuvre";
remedy_message = "increasing the flight plan duration";
}
}

if (anomalous_manoeuvres > 0) {
message = "The last " + anomalous_manoeuvres + " manoeuvres could " +
if (anomalous_manœuvres > 0) {
message = "The last " + anomalous_manœuvres + " manœuvres could " +
"not be drawn because the " + status_message + "; try " +
remedy_message + " or adjusting manoeuvre " +
(manoeuvres - anomalous_manoeuvres - 1) + ".";
remedy_message + " or adjusting manœuvre " +
(manœuvres - anomalous_manœuvres - 1) + ".";
} else {
message = "The " + status_message + "; try " + remedy_message + ".";
}
@@ -501,13 +508,13 @@ private string GetStatusMessage() {
private Vessel vessel_;
private List<BurnEditor> burn_editors_;
private DifferentialSlider final_time_;
private int? first_future_manoeuvre_;
private int? first_future_manœuvre_;

private bool show_guidance_ = false;
private float warning_height_ = 1;

private Status status_ = Status.OK;
private int? first_error_manoeuvre_;
private int? first_error_manœuvre_;
private bool message_was_displayed_ = false;

private const double log10_time_lower_rate = 0.0;
13 changes: 7 additions & 6 deletions ksp_plugin_test/flight_plan_test.cpp
Original file line number Diff line number Diff line change
@@ -277,11 +277,12 @@ TEST_F(FlightPlanTest, Singular) {
// analytic expression for the time at which we reach the singularity, are
// left as an exercise to the reader.
EXPECT_THAT(
flight_plan_->ReplaceLast(
flight_plan_->Replace(
MakeTangentBurn(/*thrust=*/10 * Newton,
/*specific_impulse=*/1 * Newton * Second / Kilogram,
/*initial_time=*/t0_ + 0.5 * Second,
/*Δv=*/-1 * Metre / Second)),
/*Δv=*/-1 * Metre / Second),
/*index=*/0),
StatusIs(integrators::termination_condition::VanishingStepSize));
EXPECT_EQ(0, flight_plan_->number_of_anomalous_manœuvres());

@@ -397,21 +398,21 @@ TEST_F(FlightPlanTest, RemoveLast) {
EXPECT_EQ(1, flight_plan_->number_of_manœuvres());
}

TEST_F(FlightPlanTest, ReplaceLast) {
TEST_F(FlightPlanTest, Replace) {
flight_plan_->SetDesiredFinalTime(t0_ + 1.7 * Second);
EXPECT_OK(flight_plan_->Append(MakeFirstBurn()));
Mass const 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_THAT(flight_plan_->ReplaceLast(MakeThirdBurn()),
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_->ReplaceLast(MakeThirdBurn()));
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());
@@ -527,7 +528,7 @@ TEST_F(FlightPlanTest, GuidedBurn) {
auto guided_burn = MakeFirstBurn();
guided_burn.thrust /= 10;
guided_burn.is_inertially_fixed = false;
EXPECT_OK(flight_plan_->ReplaceLast(std::move(guided_burn)));
EXPECT_OK(flight_plan_->Replace(std::move(guided_burn), /*index=*/0));
flight_plan_->GetAllSegments(begin, end);
last = --end;
Speed const guided_final_speed = last.degrees_of_freedom().velocity().Norm();
Loading