diff --git a/CHANGELOG_MOCO.md b/CHANGELOG_MOCO.md index f114eff255..2f19bb1bec 100644 --- a/CHANGELOG_MOCO.md +++ b/CHANGELOG_MOCO.md @@ -3,6 +3,9 @@ Moco Change Log 1.4.0 ----- +- 2024-08-30: Added `MocoInverse::initializeKinematics()` to allow users to retrieve kinematics after + converting the `MocoInverse` to a `MocoStudy`. + - 2024-08-26: Changed all `printDescription()` and `printDescriptionImpl()` methods to log at level info instead of cout. diff --git a/OpenSim/Moco/MocoInverse.cpp b/OpenSim/Moco/MocoInverse.cpp index f26c949052..e0d092bec0 100644 --- a/OpenSim/Moco/MocoInverse.cpp +++ b/OpenSim/Moco/MocoInverse.cpp @@ -42,6 +42,10 @@ void MocoInverse::constructProperties() { MocoStudy MocoInverse::initialize() const { return initializeInternal().first; } +TimeSeriesTable MocoInverse::initializeKinematics() const { + return initializeInternal().second; +} + std::pair MocoInverse::initializeInternal() const { // Process inputs. diff --git a/OpenSim/Moco/MocoInverse.h b/OpenSim/Moco/MocoInverse.h index 41686bf047..f430bbde35 100644 --- a/OpenSim/Moco/MocoInverse.h +++ b/OpenSim/Moco/MocoInverse.h @@ -199,6 +199,7 @@ class OSIMMOCO_API MocoInverse : public MocoTool { } MocoStudy initialize() const; + TimeSeriesTable initializeKinematics() const; /// Solve the problem returned by initialize() and compute the outputs /// listed in output_paths. MocoInverseSolution solve() const; diff --git a/OpenSim/Moco/Test/testMocoInverse.cpp b/OpenSim/Moco/Test/testMocoInverse.cpp index 534f48621a..375d674dd6 100644 --- a/OpenSim/Moco/Test/testMocoInverse.cpp +++ b/OpenSim/Moco/Test/testMocoInverse.cpp @@ -207,7 +207,19 @@ TEST_CASE("MocoInverse Rajagopal2016, 18 muscles", "[casadi]") { CHECK(med_gas_l_excitation[i] <= Approx(0.1).margin(1e-6)); } + } + SECTION("initializeKinematics") { + auto kinematics = inverse.initializeKinematics(); + // check that some of the expected columns are there + CHECK_NOTHROW(kinematics.getColumnIndex( + "/jointset/hip_r/hip_rotation_r/value")); + CHECK_NOTHROW(kinematics.getColumnIndex( + "/jointset/ground_pelvis/pelvis_tilt/value")); + CHECK_NOTHROW(kinematics.getColumnIndex( + "/jointset/walker_knee_r/knee_angle_r/speed")); + CHECK_NOTHROW(kinematics.getColumnIndex( + "/jointset/back/lumbar_extension/speed")); } } // Next test_case fails on linux while parsing .sto file, disabling for now