Fix bugs in adhesion default parsing.

- `gain` was not inherited, either from `<adhesion gain>` default or from `<general gainprm>` default.
- `dyntype` was not inherited from `<general dyntype>` default.
- Reported by @vaxenburg.

PiperOrigin-RevId: 480707156
Change-Id: I0160531d48186e7658952e72923ceb6cb034be9b
This commit is contained in:
Yuval Tassa
2022-10-12 13:44:17 -07:00
committed by Copybara-Service
parent 106a3fc0bb
commit 6e004d7413
2 changed files with 35 additions and 9 deletions
-6
View File
@@ -1818,11 +1818,6 @@ void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) {
// adhesion
else if (type=="adhesion") {
// clear bias, set default gain
mjuu_zerovec(pact->biasprm, mjNBIAS);
mjuu_zerovec(pact->gainprm, mjNGAIN);
pact->gainprm[0] = 1;
// explicit attributes
ReadAttr(elem, "gain", 1, pact->gainprm, text);
if (pact->gainprm[0]<0)
@@ -1836,7 +1831,6 @@ void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) {
// implied parameters
pact->ctrllimited = 1;
pact->dyntype = mjDYN_NONE;
pact->gaintype = mjGAIN_FIXED;
pact->biastype = mjBIAS_NONE;
}
+35 -3
View File
@@ -804,9 +804,6 @@ TEST_F(ActuatorParseTest, IntvelocityDefaultsPropagate) {
mj_deleteModel(model);
}
// ------------- test adhesion parsing -----------------------------------------
TEST_F(ActuatorParseTest, AdhesionDefaultsPropagate) {
static constexpr char xml[] = R"(
<mujoco>
@@ -880,6 +877,41 @@ TEST_F(ActuatorParseTest, DampersDontRequireRange) {
mj_deleteModel(model);
}
// make sure range requirement is not enforced at parse time
TEST_F(ActuatorParseTest, AdhesionInheritsFromGeneral) {
static constexpr char xml[] = R"(
<mujoco>
<default>
<general dyntype="filter" dynprm="123" gainprm="5"/>
<adhesion ctrlrange="0 2"/>
</default>
<worldbody>
<body name="sphere">
<geom name="sphere" size="1"/>
</body>
</worldbody>
<actuator>
<adhesion name="adhere" body="sphere"/>
</actuator>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, NotNull()) << error.data();
// expect that gainprm was inherited from the general default
EXPECT_EQ(model->actuator_gainprm[0], 5);
// expect that dynprm was inherited from the general default
EXPECT_EQ(model->actuator_dynprm[0], 123);
// expect that dyntype was inherited from the general default
EXPECT_EQ(model->actuator_dyntype[0], mjDYN_FILTER);
mj_deleteModel(model);
}
// ------------- test general parsing ------------------------------------------
TEST_F(XMLReaderTest, ZnearZeroNotAllowed) {
static constexpr char xml[] = R"(
<mujoco>