Remove the Shell plugin and integrate it into the engine.
PiperOrigin-RevId: 760688502 Change-Id: Ia70988d42b7edf571d7cb4a4f48f8fc50b51667d
This commit is contained in:
committed by
Copybara-Service
parent
45fc15b844
commit
7edbdd0ad6
@@ -116,9 +116,50 @@ static void mj_springdamper(const mjModel* m, mjData* d) {
|
||||
// flex elasticity
|
||||
for (int f=0; f < m->nflex; f++) {
|
||||
mjtNum* k = m->flex_stiffness + 21*m->flex_elemadr[f];
|
||||
mjtNum* b = m->flex_bending + 16*m->flex_edgeadr[f];
|
||||
int dim = m->flex_dim[f];
|
||||
|
||||
if (dim == 1 || m->flex_rigid[f] || k[0] == 0) {
|
||||
if (dim == 1 || m->flex_rigid[f]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// add bending forces to qfrc_spring
|
||||
if (dim == 2) {
|
||||
mjtNum* xpos = d->flexvert_xpos + 3*m->flex_vertadr[f];
|
||||
int* bodyid = m->flex_vertbodyid + m->flex_vertadr[f];
|
||||
|
||||
for (int e = 0; e < m->flex_edgenum[f]; e++) {
|
||||
const int* edge = m->flex_edge + 2*(e+m->flex_edgeadr[f]);
|
||||
const int* flap = m->flex_edgeflap + 2*(e+m->flex_edgeadr[f]);
|
||||
int v[4] = {edge[0], edge[1], flap[0], flap[1]};
|
||||
if (v[3] == -1) {
|
||||
// skip boundary edges
|
||||
continue;
|
||||
}
|
||||
mjtNum force[12] = {0};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
for (int x = 0; x < 3; x++) {
|
||||
force[3*i+x] += b[16*e+4*i+j] * xpos[3*v[j]+x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add damping
|
||||
|
||||
// insert into global force
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int bid = bodyid[v[i]];
|
||||
int body_dofnum = m->body_dofnum[bid];
|
||||
int body_dofadr = m->body_dofadr[bid];
|
||||
for (int x = 0; x < body_dofnum; x++) {
|
||||
d->qfrc_spring[body_dofadr+x] -= force[3*i+x];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (k[0] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,6 @@ void mjs_defaultFlex(mjsFlex* flex) {
|
||||
flex->rgba[0] = flex->rgba[1] = flex->rgba[2] = 0.5f;
|
||||
flex->rgba[3] = 1.0f;
|
||||
flex->thickness = -1;
|
||||
flex->elastic2d = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-5
@@ -3382,9 +3382,13 @@ void mjCFlex::ResolveReferences(const mjCModel* m) {
|
||||
vertbodyid.clear();
|
||||
nodebodyid.clear();
|
||||
for (const auto& vertbody : vertbody_) {
|
||||
mjCBase* pbody = m->FindObject(mjOBJ_BODY, vertbody);
|
||||
mjCBody* pbody = static_cast<mjCBody*>(m->FindObject(mjOBJ_BODY, vertbody));
|
||||
if (pbody) {
|
||||
vertbodyid.push_back(pbody->id);
|
||||
if (pbody->joints.size() != 3 && dim == 2 && (elastic2d == 1 || elastic2d == 3)) {
|
||||
// TODO(quaglino): add support for pins
|
||||
throw mjCError(this, "pins are not supported for bending");
|
||||
}
|
||||
} else {
|
||||
throw mjCError(this, "unknown body '%s' in flex", vertbody.c_str());
|
||||
}
|
||||
@@ -3658,7 +3662,10 @@ void mjCFlex::Compile(const mjVFS* vfs) {
|
||||
}
|
||||
|
||||
// bending stiffness (2D only)
|
||||
if (dim == 2 && (elastic2d == 1 || elastic2d == 3) && thickness > 0) {
|
||||
if (dim == 2 && (elastic2d == 1 || elastic2d == 3)) {
|
||||
if (thickness < 0) {
|
||||
throw mjCError(this, "thickness must be positive for bending stiffness");
|
||||
}
|
||||
bending.assign(nedge*16, 0);
|
||||
|
||||
for (unsigned int e = 0; e < nedge; e++) {
|
||||
@@ -3668,7 +3675,7 @@ void mjCFlex::Compile(const mjVFS* vfs) {
|
||||
}
|
||||
}
|
||||
|
||||
// add plugins
|
||||
// placeholder for setting plugins parameters, currently not used
|
||||
for (const auto& vbodyid : vertbodyid) {
|
||||
if (vbodyid < 0) {
|
||||
continue;
|
||||
@@ -3676,8 +3683,8 @@ void mjCFlex::Compile(const mjVFS* vfs) {
|
||||
if (model->Bodies()[vbodyid]->plugin.element) {
|
||||
mjCPlugin* plugin_instance =
|
||||
static_cast<mjCPlugin*>(model->Bodies()[vbodyid]->plugin.element);
|
||||
if (damping > 0) {
|
||||
plugin_instance->config_attribs["damping"] = std::to_string(damping);
|
||||
if (!plugin_instance) {
|
||||
throw mjCError(this, "plugin instance not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3165,7 +3165,7 @@ void mjCModel::CopyObjects(mjModel* m) {
|
||||
for (int k=0; k < pfl->nedge; k++) {
|
||||
m->flex_edge[2*(edge_adr+k)] = pfl->edge[k].first;
|
||||
m->flex_edge[2*(edge_adr+k)+1] = pfl->edge[k].second;
|
||||
if (pfl->dim == 2) {
|
||||
if (pfl->dim == 2 && (pfl->elastic2d == 1 || pfl->elastic2d == 3)) {
|
||||
m->flex_edgeflap[2*(edge_adr+k)+0] = pfl->flaps[k].vertices[2];
|
||||
m->flex_edgeflap[2*(edge_adr+k)+1] = pfl->flaps[k].vertices[3];
|
||||
} else {
|
||||
|
||||
@@ -71,6 +71,7 @@ extern const mjMap datatype_map[];
|
||||
extern const mjMap meshtype_map[];
|
||||
extern const mjMap meshinertia_map[];
|
||||
extern const mjMap flexself_map[];
|
||||
extern const mjMap elastic2d_map[];
|
||||
|
||||
|
||||
//---------------------------------- Base XML class ------------------------------------------------
|
||||
|
||||
@@ -807,6 +807,15 @@ const mjMap flexself_map[5] = {
|
||||
};
|
||||
|
||||
|
||||
// flex elastic 2d type
|
||||
const mjMap elastic2d_map[5] = {
|
||||
{"none", 0},
|
||||
{"bend", 1},
|
||||
{"stretch", 2},
|
||||
{"both", 3},
|
||||
};
|
||||
|
||||
|
||||
|
||||
//---------------------------------- class mjXReader implementation --------------------------------
|
||||
|
||||
@@ -1401,7 +1410,7 @@ void mjXReader::OneFlex(XMLElement* elem, mjsFlex* flex) {
|
||||
ReadAttr(elasticity, "poisson", 1, &flex->poisson, text);
|
||||
ReadAttr(elasticity, "thickness", 1, &flex->thickness, text);
|
||||
ReadAttr(elasticity, "damping", 1, &flex->damping, text);
|
||||
ReadAttr(elasticity, "elastic2d", 1, &flex->elastic2d, text);
|
||||
MapValue(elasticity, "elastic2d", &flex->elastic2d, elastic2d_map, 4);
|
||||
}
|
||||
|
||||
// write error info
|
||||
@@ -2665,7 +2674,7 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjsBody* body, const mjVFS* vfs) {
|
||||
ReadAttr(elasticity, "poisson", 1, &dflex.poisson, text);
|
||||
ReadAttr(elasticity, "damping", 1, &dflex.damping, text);
|
||||
ReadAttr(elasticity, "thickness", 1, &dflex.thickness, text);
|
||||
ReadAttr(elasticity, "elastic2d", 1, &dflex.elastic2d, text);
|
||||
MapValue(elasticity, "elastic2d", &dflex.elastic2d, elastic2d_map, 4);
|
||||
}
|
||||
|
||||
// check errors
|
||||
|
||||
@@ -194,7 +194,7 @@ void mjXWriter::OneFlex(XMLElement* elem, const mjCFlex* flex) {
|
||||
WriteAttr(elastic, "poisson", 1, &flex->poisson, &defflex.poisson);
|
||||
WriteAttr(elastic, "thickness", 1, &flex->thickness, &defflex.thickness);
|
||||
WriteAttr(elastic, "damping", 1, &flex->damping, &defflex.damping);
|
||||
WriteAttr(elastic, "elastic2d", 1, &flex->elastic2d, &defflex.elastic2d);
|
||||
WriteAttrKey(elastic, "elastic2d", elastic2d_map, 2, flex->elastic2d, defflex.elastic2d);
|
||||
|
||||
// edge subelement
|
||||
XMLElement* edge = InsertEnd(elem, "edge");
|
||||
|
||||
Reference in New Issue
Block a user