Fix damper kv inheritance from default classes in XML native reader

Ensured dampers correctly read inherited values from gainprm[2].

PiperOrigin-RevId: 945086959
Change-Id: I10900f3ad057036115da88ad6d649d3d058e7373
This commit is contained in:
Google DeepMind
2026-07-09 06:43:38 -07:00
committed by Copybara-Service
parent ac29b596fb
commit faf0dabc32
2 changed files with 25 additions and 1 deletions
+2 -1
View File
@@ -2561,7 +2561,8 @@ void mjXReader::OneActuator(XMLElement* elem, mjsActuator* actuator) {
// damper
else if (type == "damper") {
double kv = 0;
bool inherited = (actuator->gaintype == mjGAIN_AFFINE);
double kv = inherited ? -actuator->gainprm[2] : 0;
ReadAttr(elem, "kv", 1, &kv, text);
err = mjs_setToDamper(actuator, kv);
}
+23
View File
@@ -2984,6 +2984,29 @@ TEST_F(ActuatorParseTest, DampersDontRequireRange) {
EXPECT_EQ(model->actuator_ctrlrange[1], 2);
}
TEST_F(ActuatorParseTest, DamperInheritsKv) {
static constexpr char xml[] = R"(
<mujoco>
<default>
<damper kv="5" ctrlrange="0 2"/>
</default>
<worldbody>
<body name="sphere">
<joint name="hinge"/>
<geom size="1"/>
</body>
</worldbody>
<actuator>
<damper joint="hinge"/>
</actuator>
</mujoco>
)";
std::array<char, 1024> error;
MjModelPtr model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model.get(), NotNull()) << error.data();
EXPECT_EQ(model->actuator_gainprm[2], -5.0);
}
// adhesion actuators inherit from general defaults
TEST_F(ActuatorParseTest, AdhesionInheritsFromGeneral) {
static constexpr char xml[] = R"(