Add plugins to flex parent body if there are pinned vertices.

Fixes #1270.

PiperOrigin-RevId: 595429578
Change-Id: Ifc61d4bde4dd3c6b4d4a09106152de1d24e71ef0
This commit is contained in:
Alessio Quaglino
2024-01-03 09:52:30 -08:00
committed by Copybara-Service
parent 2940b934fe
commit 63ec34f9f8
4 changed files with 71 additions and 26 deletions
+5 -2
View File
@@ -7,9 +7,12 @@ Upcoming version (not yet released)
MJX
^^^
1. Added :ref:`dyntype<actuator-general-dyntype>` ``filterexact``.
2. Added :at:`site` transmission.
1. Add :ref:`dyntype<actuator-general-dyntype>` ``filterexact``.
2. Add :at:`site` transmission.
Bug fixes
^^^^^^^^^
3. Fixed a bug that prevented the use of pins with plugins if flexes are not in the worldbody. Fixes :github:issue:`1270`.
Version 3.1.1 (December 18, 2023)
+3
View File
@@ -133,6 +133,9 @@ inline void ComputeForce(mjtNum* qfrc_passive,
if (vertbodyid) {
body_dofnum = m->body_dofnum[vertbodyid[v[i]]];
body_dofadr = m->body_dofadr[vertbodyid[v[i]]];
if (body_dofnum && m->body_simple[vertbodyid[v[i]]] != 2) {
mju_error("Non-simple or non-static bodies are not yet supported");
}
}
for (int x = 0; x < body_dofnum; x++) {
qfrc_passive[body_dofadr+x] -= force[3*i+x];
+8
View File
@@ -399,6 +399,14 @@ bool mjCFlexcomp::Make(mjCModel* model, mjCBody* body, char* error, int error_sz
// pinned: parent body
if (pinned[i]) {
pf->vertbody.push_back(body->name);
// add plugin
if (plugin_instance) {
body->is_plugin = true;
body->plugin_name = plugin_name;
body->plugin_instance = plugin_instance;
body->plugin_instance_name = plugin_instance_name;
}
}
// not pinned: new body
+55 -24
View File
@@ -31,6 +31,38 @@ namespace {
using ElasticityTest = PluginTest;
// -------------------------------- flex ------------------------------------
TEST_F(ElasticityTest, FlexCompatibility) {
static constexpr char flex_xml[] = R"(
<mujoco>
<extension>
<plugin plugin="mujoco.elasticity.solid"/>
</extension>
<worldbody>
<body name="parent">
<flexcomp name="soft" type="grid" count="3 3 3"
radius="0.01" dim="3"mass="1">
<pin id="2"/>
<plugin plugin="mujoco.elasticity.solid">
<config key="poisson" value="0.2"/>
<config key="young" value="5e4"/>
</plugin>
</flexcomp>
</body>
</worldbody>
</mujoco>
)";
char error[1024] = {0};
mjModel* m = LoadModelFromString(flex_xml, error, sizeof(error));
ASSERT_THAT(m, testing::NotNull()) << error;
mjData* d = mj_makeData(m);
mj_deleteData(d);
mj_deleteModel(m);
}
// -------------------------------- shell -----------------------------------
TEST_F(ElasticityTest, ElasticEnergyShell) {
static constexpr char cantilever_xml[] = R"(
@@ -144,6 +176,29 @@ TEST_F(PluginTest, ElasticEnergyMembrane) {
mj_deleteModel(m);
}
TEST_F(ElasticityTest, InvalidThickness) {
static constexpr char xml[] = R"(
<mujoco>
<extension>
<plugin plugin="mujoco.elasticity.shell"/>
</extension>
<worldbody>
<composite type="particle" count="2 2 1" spacing="1">
<geom size=".025"/>
<plugin plugin="mujoco.elasticity.shell">
<config key="thickness" value="hello"/>
</plugin>
</composite>
</worldbody>
</mujoco>
)";
char error[1024] = {0};
mjModel* m = LoadModelFromString(xml, error, sizeof(error));
ASSERT_THAT(m, testing::IsNull());
}
// -------------------------------- solid -----------------------------------
TEST_F(ElasticityTest, ElasticEnergySolid) {
static constexpr char cantilever_xml[] = R"(
@@ -202,7 +257,6 @@ TEST_F(ElasticityTest, ElasticEnergySolid) {
}
// -------------------------------- cable -----------------------------------
TEST_F(ElasticityTest, CantileverIntoCircle) {
static constexpr char cantilever_xml[] = R"(
<mujoco>
@@ -303,29 +357,6 @@ TEST_F(ElasticityTest, InvalidMixedAttribute) {
ASSERT_THAT(m, testing::IsNull());
}
TEST_F(ElasticityTest, InvalidThickness) {
static constexpr char xml[] = R"(
<mujoco>
<extension>
<plugin plugin="mujoco.elasticity.shell"/>
</extension>
<worldbody>
<composite type="particle" count="2 2 1" spacing="1">
<geom size=".025"/>
<plugin plugin="mujoco.elasticity.shell">
<config key="thickness" value="hello"/>
</plugin>
</composite>
</worldbody>
</mujoco>
)";
char error[1024] = {0};
mjModel* m = LoadModelFromString(xml, error, sizeof(error));
ASSERT_THAT(m, testing::IsNull());
}
TEST_F(ElasticityTest, ValidAttributes) {
static constexpr char cantilever_xml[] = R"(
<mujoco>