Support pinned flex vertices with bending

The flexcomp compiler previously rejected pins on dim-2 flexes with
bending (elastic2d bend/both). Allow them: mj_flexPassiveBend treats a
pinned vertex (body without 3 free slide dofs) as static -- zero
velocity, and no bending force applied to it (the reaction is carried
by the pin) -- while its position still enters every neighbor's
bending force, which is exactly what the pin constrains.

PiperOrigin-RevId: 944410969
Change-Id: Ib0a69c8d5fb6f64d3e2a76af3b6b2c7be1898191
This commit is contained in:
Alessio Quaglino
2026-07-08 04:01:51 -07:00
committed by Copybara-Service
parent c4c2cad503
commit fb6d1cf18f
4 changed files with 107 additions and 11 deletions
+43
View File
@@ -1366,5 +1366,48 @@ TEST_F(UserFlexTest, Load1DFlexFromOBJ) {
mj_deleteModel(m);
}
TEST_F(UserFlexTest, PinBendingRejectsNonStaticBody) {
// pinned vertex inherits the flexcomp's parent body, which here has a joint
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body name="moving">
<joint type="hinge"/>
<geom size="0.1"/>
<flexcomp name="test" type="grid" count="3 3 1" spacing="1 1 1"
radius="0.01" dim="2">
<elasticity young="1" poisson="0" thickness="1" elastic2d="bend"/>
<pin id="0"/>
</flexcomp>
</body>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
MjModelPtr m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m.get(), IsNull());
EXPECT_THAT(error.data(), HasSubstr("static"));
}
TEST_F(UserFlexTest, PinBendingAcceptsStaticBody) {
// pinned vertex inherits the flexcomp's parent body (world), which is static
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body name="parent">
<flexcomp name="test" type="grid" count="3 3 1" spacing="1 1 1"
radius="0.01" dim="2">
<elasticity young="1" poisson="0" thickness="1" elastic2d="bend"/>
<pin id="0"/>
</flexcomp>
</body>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
MjModelPtr m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m.get(), NotNull()) << error.data();
}
} // namespace
} // namespace mujoco