Skip to content

Commit

Permalink
Merge pull request #2650 from eggrobin/reference-part-offset
Browse files Browse the repository at this point in the history
Reference part offset
  • Loading branch information
eggrobin committed Jul 15, 2020
2 parents cbfc1bd + 2b38495 commit a567784
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
4 changes: 0 additions & 4 deletions ksp_plugin/part.cpp
Expand Up @@ -161,10 +161,6 @@ RigidMotion<RigidPart, Barycentric> const& Part::rigid_motion() const {
return rigid_motion_;
}

DegreesOfFreedom<Barycentric> Part::degrees_of_freedom() const {
return rigid_motion_({RigidPart::origin, RigidPart::unmoving});
}

DiscreteTrajectory<Barycentric>::Iterator Part::history_begin() {
// Make sure that we skip the point of the prehistory.
auto it = history_->Fork();
Expand Down
4 changes: 0 additions & 4 deletions ksp_plugin/part.hpp
Expand Up @@ -110,10 +110,6 @@ class Part final {
RigidMotion<RigidPart, Barycentric> const& rigid_motion);
RigidMotion<RigidPart, Barycentric> const& rigid_motion() const;

// A convenience selector.
// TODO(phl): Should probably be eliminated at some point.
DegreesOfFreedom<Barycentric> degrees_of_freedom() const;

// Return iterators to the beginning and end of the history and psychohistory
// of the part, respectively. Either trajectory may be empty, but they are
// not both empty.
Expand Down
8 changes: 5 additions & 3 deletions ksp_plugin/plugin.cpp
Expand Up @@ -715,10 +715,12 @@ RigidMotion<Barycentric, World> Plugin::BarycentricToWorld(
main_body_frame.ToThisFrameAtTime(current_time_);
auto const barycentric_to_main_body_rotation =
barycentric_to_main_body_motion.rigid_transformation().linear_map();
Part const& reference_part = *FindOrDie(part_id_to_vessel_, reference_part_id)
->part(reference_part_id);
auto const reference_part_degrees_of_freedom =
barycentric_to_main_body_motion(
FindOrDie(part_id_to_vessel_, reference_part_id)->
part(reference_part_id)->degrees_of_freedom());
barycentric_to_main_body_motion(reference_part.rigid_motion()(
reference_part.MakeRigidToEccentricMotion().Inverse()(
{EccentricPart::origin, EccentricPart::unmoving})));

RigidTransformation<MainBodyCentred, World> const
main_body_to_world_rigid_transformation = [&]() {
Expand Down
4 changes: 3 additions & 1 deletion ksp_plugin/vessel.cpp
Expand Up @@ -169,7 +169,9 @@ void Vessel::PrepareHistory(Instant const& t) {
<< " at " << t;
BarycentreCalculator<DegreesOfFreedom<Barycentric>, Mass> calculator;
ForAllParts([&calculator](Part& part) {
calculator.Add(part.degrees_of_freedom(), part.mass());
calculator.Add(
part.rigid_motion()({RigidPart::origin, RigidPart::unmoving}),
part.mass());
});
CHECK(psychohistory_ == nullptr);
history_->SetDownsampling(max_dense_intervals, downsampling_tolerance);
Expand Down
5 changes: 4 additions & 1 deletion ksp_plugin_test/part_test.cpp
Expand Up @@ -147,7 +147,10 @@ TEST_F(PartTest, Serialization) {
auto const p = Part::ReadFromMessage(message, /*deletion_callback=*/nullptr);
EXPECT_EQ(part_.inertia_tensor(), p->inertia_tensor());
EXPECT_EQ(part_.intrinsic_force(), p->intrinsic_force());
EXPECT_EQ(part_.degrees_of_freedom(), p->degrees_of_freedom());
EXPECT_EQ(part_.rigid_motion()({RigidPart::origin, RigidPart::unmoving}),
p->rigid_motion()({RigidPart::origin, RigidPart::unmoving}));
EXPECT_EQ(part_.rigid_motion().angular_velocity_of<RigidPart>(),
p->rigid_motion().angular_velocity_of<RigidPart>());

serialization::Part second_message;
p->WriteToMessage(&second_message,
Expand Down
12 changes: 7 additions & 5 deletions ksp_plugin_test/pile_up_test.cpp
Expand Up @@ -626,12 +626,13 @@ TEST_F(PileUpTest, MidStepIntrinsicForce) {
&ephemeris,
deletion_callback_.AsStdFunction());
Velocity<Barycentric> const old_velocity =
p1_.degrees_of_freedom().velocity();
p1_.rigid_motion()({RigidPart::origin, RigidPart::unmoving}).velocity();

pile_up.AdvanceTime(astronomy::J2000 + 1.5 * fixed_step);
pile_up.NudgeParts();
EXPECT_THAT(p1_.degrees_of_freedom().velocity(),
AlmostEquals(old_velocity, 2));
EXPECT_THAT(
p1_.rigid_motion()({RigidPart::origin, RigidPart::unmoving}).velocity(),
AlmostEquals(old_velocity, 2));

Vector<Acceleration, Barycentric> const a{{1729 * Metre / Pow<2>(Second),
-168 * Metre / Pow<2>(Second),
Expand All @@ -640,8 +641,9 @@ TEST_F(PileUpTest, MidStepIntrinsicForce) {
pile_up.RecomputeFromParts();
pile_up.AdvanceTime(astronomy::J2000 + 2 * fixed_step);
pile_up.NudgeParts();
EXPECT_THAT(p1_.degrees_of_freedom().velocity(),
AlmostEquals(old_velocity + 0.5 * fixed_step * a, 1));
EXPECT_THAT(
p1_.rigid_motion()({RigidPart::origin, RigidPart::unmoving}).velocity(),
AlmostEquals(old_velocity + 0.5 * fixed_step * a, 1));
}

TEST_F(PileUpTest, Serialization) {
Expand Down

0 comments on commit a567784

Please sign in to comment.