Add tendon armature
PiperOrigin-RevId: 743939992 Change-Id: I587214f5d6fabbc0cc273c33d82decbe9ad8f919
This commit is contained in:
committed by
Copybara-Service
parent
e1f5ceb65a
commit
d05251af2a
+51
-25
@@ -2769,31 +2769,6 @@ void mjCModel::CopyTree(mjModel* m) {
|
||||
}
|
||||
}
|
||||
m->nB = nB;
|
||||
|
||||
// set dof_simplenum
|
||||
int count = 0;
|
||||
for (int i=nv-1; i >= 0; i--) {
|
||||
if (m->body_simple[m->dof_bodyid[i]]) {
|
||||
count++; // increment counter
|
||||
} else {
|
||||
count = 0; // reset
|
||||
}
|
||||
m->dof_simplenum[i] = count;
|
||||
}
|
||||
|
||||
// compute nC
|
||||
int nOD = 0; // number of off-diagonal (non-simple) parent dofs
|
||||
for (int i=0; i < nv; i++) {
|
||||
// count ancestor (off-diagonal) dofs
|
||||
if (!m->dof_simplenum[i]) {
|
||||
int j = i;
|
||||
while (j >= 0) {
|
||||
if (j != i) nOD++;
|
||||
j = m->dof_parentid[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
m->nC = nC = nOD + nv;
|
||||
}
|
||||
|
||||
// copy plugin data
|
||||
@@ -3564,6 +3539,54 @@ void mjCModel::CopyObjects(mjModel* m) {
|
||||
|
||||
|
||||
|
||||
// finalize simple bodies/dofs including tendon information
|
||||
void mjCModel::FinalizeSimple(mjModel* m) {
|
||||
// demote bodies affected by inertia-bearing tendon to non-simple
|
||||
for (int i=0; i < ntendon; i++) {
|
||||
if (m->tendon_armature[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
int adr = m->tendon_adr[i];
|
||||
int num = m->tendon_num[i];
|
||||
for (int j=adr; j < adr+num; j++) {
|
||||
int objid = m->wrap_objid[j];
|
||||
if (m->wrap_type[j] == mjWRAP_SITE) {
|
||||
m->body_simple[m->site_bodyid[objid]] = 0;
|
||||
}
|
||||
if (m->wrap_type[j] == mjWRAP_CYLINDER || m->wrap_type[j] == mjWRAP_SPHERE) {
|
||||
m->body_simple[m->geom_bodyid[objid]] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set dof_simplenum
|
||||
int count = 0;
|
||||
for (int i=nv-1; i >= 0; i--) {
|
||||
if (m->body_simple[m->dof_bodyid[i]]) {
|
||||
count++; // increment counter
|
||||
} else {
|
||||
count = 0; // reset
|
||||
}
|
||||
m->dof_simplenum[i] = count;
|
||||
}
|
||||
|
||||
// compute nC
|
||||
int nOD = 0; // number of off-diagonal (non-simple) parent dofs
|
||||
for (int i=0; i < nv; i++) {
|
||||
// count ancestor (off-diagonal) dofs
|
||||
if (!m->dof_simplenum[i]) {
|
||||
int j = i;
|
||||
while (j >= 0) {
|
||||
if (j != i) nOD++;
|
||||
j = m->dof_parentid[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
m->nC = nC = nOD + nv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// save the current state
|
||||
template <class T>
|
||||
void mjCModel::SaveState(const std::string& state_name, const T* qpos, const T* qvel, const T* act,
|
||||
@@ -4509,6 +4532,9 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
|
||||
// copy objects outsite kinematic tree (including keyframes)
|
||||
CopyObjects(m);
|
||||
|
||||
// finalize simple bodies/dofs including tendon information
|
||||
FinalizeSimple(m);
|
||||
|
||||
// compute non-zeros in actuator_moment
|
||||
m->nJmom = nJmom = CountNJmom(m);
|
||||
|
||||
|
||||
@@ -349,6 +349,7 @@ class mjCModel : public mjCModel_, private mjSpec {
|
||||
void CopyPaths(mjModel*); // copy paths, compute path addresses
|
||||
void CopyObjects(mjModel*); // copy objects outside kinematic tree
|
||||
void CopyTree(mjModel*); // copy objects inside kinematic tree
|
||||
void FinalizeSimple(mjModel* m); // finalize simple bodies/dofs including tendon information
|
||||
void CopyPlugins(mjModel*); // copy plugin data
|
||||
int CountNJmom(const mjModel* m); // compute number of non-zeros in actuator_moment matrix
|
||||
|
||||
|
||||
Reference in New Issue
Block a user