diff --git a/doc/includes/references.h b/doc/includes/references.h index 71f9b4ef..0139c349 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -159,6 +159,7 @@ struct mjData_ { // variable sizes int ne; // number of equality constraints int nf; // number of friction constraints + int nl; // number of limit constraints int nefc; // number of constraints int nnzJ; // number of non-zeros in constraint Jacobian int ncon; // number of detected contacts diff --git a/include/mujoco/mjdata.h b/include/mujoco/mjdata.h index 4a47d8af..17f0c24c 100644 --- a/include/mujoco/mjdata.h +++ b/include/mujoco/mjdata.h @@ -186,6 +186,7 @@ struct mjData_ { // variable sizes int ne; // number of equality constraints int nf; // number of friction constraints + int nl; // number of limit constraints int nefc; // number of constraints int nnzJ; // number of non-zeros in constraint Jacobian int ncon; // number of detected contacts diff --git a/include/mujoco/mjxmacro.h b/include/mujoco/mjxmacro.h index f13bddae..dfa3547d 100644 --- a/include/mujoco/mjxmacro.h +++ b/include/mujoco/mjxmacro.h @@ -637,6 +637,7 @@ X( int, ngeompair_narrow ) \ X( int, ne ) \ X( int, nf ) \ + X( int, nl ) \ X( int, nefc ) \ X( int, nnzJ ) \ X( int, ncon ) \ diff --git a/introspect/structs.py b/introspect/structs.py index 58fd605d..55fa8d57 100644 --- a/introspect/structs.py +++ b/introspect/structs.py @@ -3599,6 +3599,11 @@ STRUCTS: Mapping[str, StructDecl] = dict([ type=ValueType(name='int'), doc='number of friction constraints', ), + StructFieldDecl( + name='nl', + type=ValueType(name='int'), + doc='number of limit constraints', + ), StructFieldDecl( name='nefc', type=ValueType(name='int'), diff --git a/src/engine/engine_core_constraint.c b/src/engine/engine_core_constraint.c index 82a66012..ff0e8cb0 100644 --- a/src/engine/engine_core_constraint.c +++ b/src/engine/engine_core_constraint.c @@ -288,6 +288,8 @@ int mj_addConstraint(const mjModel* m, mjData* d, d->ne += size; } else if (type == mjCNSTR_FRICTION_DOF || type == mjCNSTR_FRICTION_TENDON) { d->nf += size; + } else if (type == mjCNSTR_LIMIT_JOINT || type == mjCNSTR_LIMIT_TENDON) { + d->nl += size; } return 0; @@ -1658,7 +1660,7 @@ static inline int mj_nc(const mjModel* m, mjData* d, int* nnz) { // driver: call all functions above void mj_makeConstraint(const mjModel* m, mjData* d) { // clear sizes - d->ne = d->nf = d->nefc = d->nnzJ = 0; + d->ne = d->nf = d->nl = d->nefc = d->nnzJ = 0; // disabled or Jacobian not allocated: return if (mjDISABLED(mjDSBL_CONSTRAINT)) { @@ -1669,7 +1671,8 @@ void mj_makeConstraint(const mjModel* m, mjData* d) { int *nnz = mj_isSparse(m) ? &(d->nnzJ) : NULL; int ne_allocated = mj_ne(m, d, nnz); int nf_allocated = mj_nf(m, d, nnz); - int nefc_allocated = ne_allocated + nf_allocated + mj_nl(m, d, nnz) + mj_nc(m, d, nnz); + int nl_allocated = mj_nl(m, d, nnz); + int nefc_allocated = ne_allocated + nf_allocated + nl_allocated + mj_nc(m, d, nnz); if (!mj_isSparse(m)) { d->nnzJ = nefc_allocated * m->nv; } @@ -1704,6 +1707,10 @@ void mj_makeConstraint(const mjModel* m, mjData* d) { mjERROR("nf mis-allocation: found nf=%d but allocated %d", d->nf, nf_allocated); } + if (d->nl != nl_allocated) { + mjERROR("nl mis-allocation: found nl=%d but allocated %d", d->nl, nl_allocated); + } + // check that nefc was computed correctly if (d->nefc != nefc_allocated) { mjERROR("nefc mis-allocation: found nefc=%d but allocated %d", d->nefc, nefc_allocated); diff --git a/src/engine/engine_io.c b/src/engine/engine_io.c index fc516930..796cf73f 100644 --- a/src/engine/engine_io.c +++ b/src/engine/engine_io.c @@ -1329,6 +1329,7 @@ static void _resetData(const mjModel* m, mjData* d, unsigned char debug_value) { // clear variable sizes d->ne = 0; d->nf = 0; + d->nl = 0; d->nefc = 0; d->nnzJ = 0; d->ncon = 0; diff --git a/unity/Runtime/Bindings/MjBindings.cs b/unity/Runtime/Bindings/MjBindings.cs index 311a80ce..4ccc8a78 100644 --- a/unity/Runtime/Bindings/MjBindings.cs +++ b/unity/Runtime/Bindings/MjBindings.cs @@ -1609,6 +1609,7 @@ public unsafe struct mjData_ { public int ngeompair_narrow; public int ne; public int nf; + public int nl; public int nefc; public int nnzJ; public int ncon;