Store joint damping and stiffness in the private spec when springdamper is used in the public spec.

PiperOrigin-RevId: 724288204
Change-Id: I7341d5d804e1ea73ded48b8b447addd4e124ab97
This commit is contained in:
Alessio Quaglino
2025-02-07 03:54:35 -08:00
committed by Copybara-Service
parent c27d3758c2
commit c1ecc50081
2 changed files with 27 additions and 0 deletions
+4
View File
@@ -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<ndim; i++) {
+23
View File
@@ -648,5 +648,28 @@ TEST_F(MujocoTest, NestedMeshDir) {
mj_deleteVFS(vfs.get());
}
TEST_F(MujocoTest, ConvertSpringdamper) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body>
<joint axis="0 1 0" springdamper="1 1"/>
<geom size="0.2 0.2 0.2" type="box"/>
</body>
</worldbody>
</mujoco>
)";
std::array<char, 1024> 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<char, 1024> 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