From c1ecc500819683bb6fee06963f4f2431c8d3d180 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Fri, 7 Feb 2025 03:54:35 -0800 Subject: [PATCH] Store joint damping and stiffness in the private spec when springdamper is used in the public spec. PiperOrigin-RevId: 724288204 Change-Id: I7341d5d804e1ea73ded48b8b447addd4e124ab97 --- src/user/user_model.cc | 4 ++++ test/user/user_model_test.cc | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/user/user_model.cc b/src/user/user_model.cc index db330026..fc4f4e67 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -1867,6 +1867,10 @@ void mjCModel::AutoSpringDamper(mjModel* m) { mjtNum stiffness = inertia / std::max(mjMINVAL, timeconst*timeconst*dampratio*dampratio); mjtNum damping = 2 * inertia / std::max(mjMINVAL, timeconst); + // save stiffness and damping in the private mjsJoints + joints_[n]->stiffness = stiffness; + joints_[n]->damping = damping; + // assign m->jnt_stiffness[n] = stiffness; for (int i=0; i + + + + + + + + )"; + std::array err; + mjSpec* spec = mj_parseXMLString(xml, 0, err.data(), err.size()); + ASSERT_THAT(spec, NotNull()) << err.data(); + mjModel* model = mj_compile(spec, 0); + ASSERT_THAT(model, NotNull()) << err.data(); + std::array str; + mj_saveXMLString(spec, str.data(), str.size(), err.data(), err.size()); + EXPECT_THAT(str.data(), HasSubstr("damping")); + EXPECT_THAT(str.data(), HasSubstr("stiffness")); + mj_deleteModel(model); +} + } // namespace } // namespace mujoco