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

Commits on Oct 30, 2021

  1. Start open-heart surgery.

    pleroy committed Oct 30, 2021
    Copy the full SHA
    4a0ca1b View commit details
  2. FlightPlan compiles.

    pleroy committed Oct 30, 2021
    Copy the full SHA
    716ea3b View commit details
  3. The test compiles.

    pleroy committed Oct 30, 2021
    Copy the full SHA
    151c487 View commit details
  4. Copy the full SHA
    3422c87 View commit details
  5. Copy the full SHA
    03f22a6 View commit details
  6. Copy the full SHA
    e070374 View commit details
  7. Comment.

    pleroy committed Oct 30, 2021
    Copy the full SHA
    1ce0bc0 View commit details

Commits on Oct 31, 2021

  1. Merge pull request #3185 from pleroy/FlightPlan

    Convert FlightPlan and its test to DiscreteTraject0ry
    pleroy authored Oct 31, 2021
    Copy the full SHA
    0aa01c1 View commit details
Showing with 73 additions and 63 deletions.
  1. +29 −32 ksp_plugin/flight_plan.cpp
  2. +20 −16 ksp_plugin/flight_plan.hpp
  3. +24 −15 ksp_plugin_test/flight_plan_test.cpp
61 changes: 29 additions & 32 deletions ksp_plugin/flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -54,18 +54,16 @@ FlightPlan::FlightPlan(
initial_time_(initial_time),
initial_degrees_of_freedom_(std::move(initial_degrees_of_freedom)),
desired_final_time_(desired_final_time),
root_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
ephemeris_(ephemeris),
adaptive_step_parameters_(std::move(adaptive_step_parameters)),
generalized_adaptive_step_parameters_(
std::move(generalized_adaptive_step_parameters)) {
CHECK(desired_final_time_ >= initial_time_);

// Set the (single) point of the root.
root_->Append(initial_time_, initial_degrees_of_freedom_);
// Set the first point of the first coasting trajectory.
trajectory_.Append(initial_time_, initial_degrees_of_freedom_);
segments_.emplace_back(trajectory_.segments().begin());

// Create a fork for the first coasting trajectory.
segments_.emplace_back(root_->NewForkWithoutCopy(initial_time_));
coast_analysers_.push_back(make_not_null_unique<OrbitAnalyser>(
ephemeris_, DefaultHistoryParameters()));
CHECK(manœuvres_.empty());
@@ -202,18 +200,18 @@ int FlightPlan::number_of_segments() const {

void FlightPlan::GetSegment(
int const index,
DiscreteTrajectory<Barycentric>::Iterator& begin,
DiscreteTrajectory<Barycentric>::Iterator& end) const {
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const {
CHECK_LE(0, index);
CHECK_LT(index, number_of_segments());
begin = segments_[index]->Fork();
begin = segments_[index]->begin();
end = segments_[index]->end();
}

void FlightPlan::GetAllSegments(
DiscreteTrajectory<Barycentric>::Iterator& begin,
DiscreteTrajectory<Barycentric>::Iterator& end) const {
begin = segments_.back()->Find(segments_.front()->Fork()->time);
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const {
begin = segments_.front()->begin();
end = segments_.back()->end();
CHECK(begin != end);
}
@@ -314,7 +312,6 @@ std::unique_ptr<FlightPlan> FlightPlan::ReadFromMessage(

FlightPlan::FlightPlan()
: initial_degrees_of_freedom_(Barycentric::origin, Barycentric::unmoving),
root_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
ephemeris_(testing_utilities::make_not_null<Ephemeris<Barycentric>*>()),
adaptive_step_parameters_(
EmbeddedExplicitRungeKuttaNyströmIntegrator<
@@ -343,7 +340,7 @@ absl::Status FlightPlan::RecomputeAllSegments() {

absl::Status FlightPlan::BurnSegment(
NavigationManœuvre const& manœuvre,
not_null<DiscreteTrajectory<Barycentric>*> const segment) {
DiscreteTrajectorySegmentIterator<Barycentric> const segment) {
Instant const final_time = manœuvre.final_time();
if (manœuvre.initial_time() < final_time) {
// Make sure that the ephemeris covers the entire segment, reanimating and
@@ -356,14 +353,14 @@ absl::Status FlightPlan::BurnSegment(

if (manœuvre.is_inertially_fixed()) {
return ephemeris_->FlowWithAdaptiveStep(
segment,
&trajectory_,
manœuvre.InertialIntrinsicAcceleration(),
final_time,
adaptive_step_parameters_,
max_ephemeris_steps_per_frame);
} else {
return ephemeris_->FlowWithAdaptiveStep(
segment,
&trajectory_,
manœuvre.FrenetIntrinsicAcceleration(),
final_time,
generalized_adaptive_step_parameters_,
@@ -376,7 +373,7 @@ absl::Status FlightPlan::BurnSegment(

absl::Status FlightPlan::CoastSegment(
Instant const& desired_final_time,
not_null<DiscreteTrajectory<Barycentric>*> const segment) {
DiscreteTrajectorySegmentIterator<Barycentric> const segment) {
// Make sure that the ephemeris covers the entire segment, reanimating and
// waiting if necessary.
Instant const starting_time = segment->back().time;
@@ -386,7 +383,7 @@ absl::Status FlightPlan::CoastSegment(
}

return ephemeris_->FlowWithAdaptiveStep(
segment,
&trajectory_,
Ephemeris<Barycentric>::NoIntrinsicAcceleration,
desired_final_time,
adaptive_step_parameters_,
@@ -413,12 +410,12 @@ absl::Status FlightPlan::ComputeSegments(
anomalous_segments_ = 1;
anomalous_status_ = status;
}
auto const& [first_time, first_degrees_of_freedom] = coast->front();
coast_analysers_[it - manœuvres_.begin()]->RequestAnalysis(
{.first_time = coast->Fork()->time,
.first_degrees_of_freedom = coast->Fork()->degrees_of_freedom,
.mission_duration = coast->back().time - coast->Fork()->time,
.extended_mission_duration =
desired_final_time_ - coast->Fork()->time});
{.first_time = first_time,
.first_degrees_of_freedom = first_degrees_of_freedom,
.mission_duration = coast->back().time - first_time,
.extended_mission_duration = desired_final_time_ - first_time});
}

AddLastSegment();
@@ -442,12 +439,12 @@ absl::Status FlightPlan::ComputeSegments(
// having to extend the flight plan by hand.
desired_final_time_ =
std::max(desired_final_time_, segments_.back()->t_max());
auto const& [first_time, first_degrees_of_freedom] =
segments_.back()->front();
coast_analysers_.back()->RequestAnalysis(
{.first_time = segments_.back()->Fork()->time,
.first_degrees_of_freedom =
segments_.back()->Fork()->degrees_of_freedom,
.mission_duration =
desired_final_time_ - segments_.back()->Fork()->time});
{.first_time = first_time,
.first_degrees_of_freedom = first_degrees_of_freedom,
.mission_duration = desired_final_time_ - first_time});
absl::Status const status =
CoastSegment(desired_final_time_, segments_.back());
if (!status.ok()) {
@@ -460,23 +457,23 @@ absl::Status FlightPlan::ComputeSegments(
}

void FlightPlan::AddLastSegment() {
segments_.emplace_back(segments_.back()->NewForkAtLast());
segments_.emplace_back(trajectory_.NewSegment());
if (anomalous_segments_ > 0) {
++anomalous_segments_;
}
}

void FlightPlan::ResetLastSegment() {
segments_.back()->ForgetAfter(segments_.back()->Fork()->time);
auto const last_segment = segments_.back();
trajectory_.ForgetAfter(std::next(last_segment->begin()));
if (anomalous_segments_ == 1) {
anomalous_segments_ = 0;
}
}

void FlightPlan::PopLastSegment() {
DiscreteTrajectory<Barycentric>* trajectory = segments_.back();
CHECK(!trajectory->is_root());
trajectory->parent()->DeleteFork(trajectory);
auto last_segment = segments_.back();
trajectory_.DeleteSegments(last_segment);
segments_.pop_back();
if (anomalous_segments_ > 0) {
--anomalous_segments_;
36 changes: 20 additions & 16 deletions ksp_plugin/flight_plan.hpp
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@
#include "ksp_plugin/manœuvre.hpp"
#include "ksp_plugin/orbit_analyser.hpp"
#include "physics/degrees_of_freedom.hpp"
#include "physics/discrete_trajectory.hpp"
#include "physics/discrete_traject0ry.hpp"
#include "physics/discrete_trajectory_segment_iterator.hpp"
#include "physics/ephemeris.hpp"
#include "quantities/named_quantities.hpp"
#include "quantities/quantities.hpp"
@@ -25,7 +26,8 @@ using base::not_null;
using geometry::Instant;
using integrators::AdaptiveStepSizeIntegrator;
using physics::DegreesOfFreedom;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using physics::DiscreteTrajectorySegmentIterator;
using physics::Ephemeris;
using quantities::Length;
using quantities::Mass;
@@ -113,11 +115,11 @@ class FlightPlan {
// |index| must be in [0, number_of_segments()[. Sets the iterators to denote
// the given trajectory.
virtual void GetSegment(int index,
DiscreteTrajectory<Barycentric>::Iterator& begin,
DiscreteTrajectory<Barycentric>::Iterator& end) const;
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const;
virtual void GetAllSegments(
DiscreteTrajectory<Barycentric>::Iterator& begin,
DiscreteTrajectory<Barycentric>::Iterator& end) const;
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const;

// |coast_index| must be in [0, number_of_manœuvres()].
virtual OrbitAnalyser::Analysis* analysis(int coast_index);
@@ -150,13 +152,15 @@ class FlightPlan {

// Flows the given |segment| for the duration of |manœuvre| using its
// intrinsic acceleration.
absl::Status BurnSegment(NavigationManœuvre const& manœuvre,
not_null<DiscreteTrajectory<Barycentric>*> segment);
absl::Status BurnSegment(
NavigationManœuvre const& manœuvre,
DiscreteTrajectorySegmentIterator<Barycentric> segment);

// Flows the given |segment| until |desired_final_time| with no intrinsic
// acceleration.
absl::Status CoastSegment(Instant const& desired_final_time,
not_null<DiscreteTrajectory<Barycentric>*> segment);
absl::Status CoastSegment(
Instant const& desired_final_time,
DiscreteTrajectorySegmentIterator<Barycentric> segment);

// Computes new trajectories and appends them to |segments_|. This updates
// the last coast of |segments_| and then appends one coast and one burn for
@@ -202,14 +206,14 @@ class FlightPlan {
Instant initial_time_;
DegreesOfFreedom<Barycentric> initial_degrees_of_freedom_;
Instant desired_final_time_;
// The root of the flight plan. Contains a single point, not part of
// |segments_|. Owns all the |segments_|.
not_null<std::unique_ptr<DiscreteTrajectory<Barycentric>>> root_;

// The trajectory of the part, composed of any number of segments,
// alternatively coasts and burns.
DiscreteTraject0ry<Barycentric> trajectory_;

// Never empty; Starts and ends with a coast; coasts and burns alternate.
// Each trajectory is a fork of the previous one.
std::vector<not_null<DiscreteTrajectory<Barycentric>*>> segments_;
// The last |anomalous_segments_| of |segments_| are anomalous, i.e. they
std::vector<DiscreteTrajectorySegmentIterator<Barycentric>> segments_;
// The last |anomalous_segments_| of |segments_| are anomalous, i.e., they
// either end prematurely or follow an anomalous trajectory; in the latter
// case they are empty.
int anomalous_segments_ = 0;
39 changes: 24 additions & 15 deletions ksp_plugin_test/flight_plan_test.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
#include <vector>

#include "astronomy/epoch.hpp"
#include "base/not_null.hpp"
#include "geometry/named_quantities.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "integrators/embedded_explicit_generalized_runge_kutta_nyström_integrator.hpp"
@@ -13,9 +15,12 @@
#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/discrete_traject0ry.hpp"
#include "physics/ephemeris.hpp"
#include "physics/massive_body.hpp"
#include "physics/rotating_body.hpp"
#include "quantities/named_quantities.hpp"
#include "quantities/quantities.hpp"
#include "serialization/ksp_plugin.pb.h"
#include "testing_utilities/almost_equals.hpp"
#include "testing_utilities/approximate_quantity.hpp"
@@ -25,13 +30,14 @@

namespace principia {
namespace ksp_plugin {
namespace internal_flight_plan {

using astronomy::J2000;
using base::not_null;
using base::make_not_null_shared;
using base::make_not_null_unique;
using geometry::Barycentre;
using geometry::Displacement;
using geometry::Instant;
using geometry::Position;
using geometry::Velocity;
using integrators::EmbeddedExplicitGeneralizedRungeKuttaNyströmIntegrator;
@@ -42,13 +48,17 @@ using integrators::methods::Fine1987RKNG34;
using integrators::methods::QuinlanTremaine1990Order12;
using physics::BodyCentredNonRotatingDynamicFrame;
using physics::DegreesOfFreedom;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using physics::Ephemeris;
using physics::Frenet;
using physics::MassiveBody;
using physics::RotatingBody;
using quantities::Force;
using quantities::Length;
using quantities::Mass;
using quantities::Pow;
using quantities::SpecificImpulse;
using quantities::Speed;
using quantities::Sqrt;
using quantities::si::Kilogram;
using quantities::si::Metre;
@@ -185,7 +195,7 @@ class FlightPlanTest : public testing::Test {
Instant const t0_;
std::unique_ptr<TestNavigationFrame> navigation_frame_;
std::unique_ptr<Ephemeris<Barycentric>> ephemeris_;
DiscreteTrajectory<Barycentric> root_;
DiscreteTraject0ry<Barycentric> root_;
std::unique_ptr<FlightPlan> flight_plan_;
};

@@ -232,10 +242,10 @@ TEST_F(FlightPlanTest, Singular) {
/*max_steps=*/1,
/*length_integration_tolerance=*/1 * Metre,
/*speed_integration_tolerance=*/1 * Metre / Second));
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
DiscreteTraject0ry<Barycentric>::iterator begin;
DiscreteTraject0ry<Barycentric>::iterator end;
flight_plan_->GetSegment(0, begin, end);
DiscreteTrajectory<Barycentric>::Iterator back = end;
DiscreteTraject0ry<Barycentric>::iterator back = end;
--back;
EXPECT_THAT(AbsoluteError(singularity, back->time), Lt(1e-4 * Second));
// Attempting to put a burn past the singularity fails.
@@ -370,8 +380,8 @@ TEST_F(FlightPlanTest, Segments) {
EXPECT_EQ(5, flight_plan_->number_of_segments());

std::vector<Instant> times;
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
DiscreteTraject0ry<Barycentric>::iterator begin;
DiscreteTraject0ry<Barycentric>::iterator end;

int last_times_size = times.size();
Instant last_t = t0_ - 2 * π * Second;
@@ -389,8 +399,8 @@ TEST_F(FlightPlanTest, Segments) {
}

TEST_F(FlightPlanTest, SetAdaptiveStepParameter) {
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
DiscreteTraject0ry<Barycentric>::iterator begin;
DiscreteTraject0ry<Barycentric>::iterator end;
flight_plan_->SetDesiredFinalTime(t0_ + 42 * Second);
EXPECT_OK(flight_plan_->Insert(MakeFirstBurn(), 0));
EXPECT_OK(flight_plan_->Insert(MakeSecondBurn(), 1));
@@ -461,9 +471,9 @@ TEST_F(FlightPlanTest, GuidedBurn) {
auto unguided_burn = MakeFirstBurn();
unguided_burn.thrust /= 10;
EXPECT_OK(flight_plan_->Insert(std::move(unguided_burn), 0));
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
DiscreteTrajectory<Barycentric>::Iterator last;
DiscreteTraject0ry<Barycentric>::iterator begin;
DiscreteTraject0ry<Barycentric>::iterator end;
DiscreteTraject0ry<Barycentric>::iterator last;
flight_plan_->GetAllSegments(begin, end);
last = --end;
Speed const unguided_final_speed =
@@ -600,6 +610,5 @@ TEST_F(FlightPlanTest, Insertion) {
EXPECT_THAT(inserted_out_of_order, EqualsProto(inserted_in_order));
}

} // namespace internal_flight_plan
} // namespace ksp_plugin
} // namespace principia