From 79c74d7eae056a3fe04bb302af0bbf7ad62e6748 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Tue, 13 May 2025 13:27:01 -0700 Subject: [PATCH] Add `mjData.M`, not yet used. PiperOrigin-RevId: 758351796 Change-Id: I0786966b2f2c2e699db845cda6940a8821b23f49 --- doc/includes/references.h | 1 + include/mujoco/mjdata.h | 1 + include/mujoco/mjxmacro.h | 1 + mjx/mujoco/mjx/_src/io.py | 2 ++ mjx/mujoco/mjx/_src/types.py | 2 ++ python/mujoco/introspect/structs.py | 8 ++++++++ unity/Runtime/Bindings/MjBindings.cs | 1 + 7 files changed, 16 insertions(+) diff --git a/doc/includes/references.h b/doc/includes/references.h index ede6874f..eada1572 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -270,6 +270,7 @@ struct mjData_ { // computed by mj_fwdPosition/mj_crb mjtNum* crb; // com-based composite inertia and mass (nbody x 10) mjtNum* qM; // total inertia (sparse) (nM x 1) + mjtNum* M; // total inertia (compressed sparse row) (nC x 1) // computed by mj_fwdPosition/mj_factorM mjtNum* qLD; // L'*D*L factorization of M (sparse) (nC x 1) diff --git a/include/mujoco/mjdata.h b/include/mujoco/mjdata.h index de09cbce..3d7514a6 100644 --- a/include/mujoco/mjdata.h +++ b/include/mujoco/mjdata.h @@ -298,6 +298,7 @@ struct mjData_ { // computed by mj_fwdPosition/mj_crb mjtNum* crb; // com-based composite inertia and mass (nbody x 10) mjtNum* qM; // total inertia (sparse) (nM x 1) + mjtNum* M; // total inertia (compressed sparse row) (nC x 1) // computed by mj_fwdPosition/mj_factorM mjtNum* qLD; // L'*D*L factorization of M (sparse) (nC x 1) diff --git a/include/mujoco/mjxmacro.h b/include/mujoco/mjxmacro.h index 99cafaa2..aa55b3d7 100644 --- a/include/mujoco/mjxmacro.h +++ b/include/mujoco/mjxmacro.h @@ -653,6 +653,7 @@ X ( mjtNum, actuator_moment, nJmom, 1 ) \ X ( mjtNum, crb, nbody, 10 ) \ X ( mjtNum, qM, nM, 1 ) \ + X ( mjtNum, M, nC, 1 ) \ X ( mjtNum, qLD, nC, 1 ) \ X ( mjtNum, qLDiagInv, nv, 1 ) \ XMJV( mjtNum, bvh_aabb_dyn, nbvhdynamic, 6 ) \ diff --git a/mjx/mujoco/mjx/_src/io.py b/mjx/mujoco/mjx/_src/io.py index 664a7b8a..66919152 100644 --- a/mjx/mujoco/mjx/_src/io.py +++ b/mjx/mujoco/mjx/_src/io.py @@ -509,6 +509,7 @@ def _make_data_jax( 'actuator_moment': (m.nu, m.nv, float_), 'crb': (m.nbody, 10, float_), 'qM': (m.nM, float_) if support.is_sparse(m) else (m.nv, m.nv, float_), + 'M': (m.nC, float_), 'qLD': (m.nC, float_) if support.is_sparse(m) else (m.nv, m.nv, float_), 'qLDiagInv': (m.nv, float_) if support.is_sparse(m) else (0, float_), 'ten_velocity': (m.ntendon, float_), @@ -618,6 +619,7 @@ def _make_data_c( 'flexedge_velocity': (nflexedge, float_), 'crb': (m.nbody, 10, float_), 'qM': (m.nM, float_), + 'M': (m.nC, float_), 'qLD': (m.nC, float_), 'qH': (m.nC, float_), 'qHDiagInv': (m.nv, float_), diff --git a/mjx/mujoco/mjx/_src/types.py b/mjx/mujoco/mjx/_src/types.py index 38dbcd71..22211378 100644 --- a/mjx/mujoco/mjx/_src/types.py +++ b/mjx/mujoco/mjx/_src/types.py @@ -970,6 +970,7 @@ class DataC(PyTreeNode): actuator_moment: jax.Array crb: jax.Array qM: jax.Array # pylint:disable=invalid-name + M: jax.Array # pylint:disable=invalid-name qLD: jax.Array # pylint:disable=invalid-name qLDiagInv: jax.Array # pylint:disable=invalid-name bvh_aabb_dyn: jax.Array @@ -1037,6 +1038,7 @@ class DataJAX(PyTreeNode): actuator_moment: jax.Array crb: jax.Array qM: jax.Array # pylint:disable=invalid-name + M: jax.Array # pylint:disable=invalid-name qLD: jax.Array # pylint:disable=invalid-name qLDiagInv: jax.Array # pylint:disable=invalid-name ten_velocity: jax.Array diff --git a/python/mujoco/introspect/structs.py b/python/mujoco/introspect/structs.py index bbfc3998..e9e6f801 100644 --- a/python/mujoco/introspect/structs.py +++ b/python/mujoco/introspect/structs.py @@ -5392,6 +5392,14 @@ STRUCTS: Mapping[str, StructDecl] = dict([ doc='total inertia (sparse)', array_extent=('nM',), ), + StructFieldDecl( + name='M', + type=PointerType( + inner_type=ValueType(name='mjtNum'), + ), + doc='total inertia (compressed sparse row)', + array_extent=('nC',), + ), StructFieldDecl( name='qLD', type=PointerType( diff --git a/unity/Runtime/Bindings/MjBindings.cs b/unity/Runtime/Bindings/MjBindings.cs index 21a96fde..d26592a9 100644 --- a/unity/Runtime/Bindings/MjBindings.cs +++ b/unity/Runtime/Bindings/MjBindings.cs @@ -4929,6 +4929,7 @@ public unsafe struct mjData_ { public double* actuator_moment; public double* crb; public double* qM; + public double* M; public double* qLD; public double* qLDiagInv; public double* bvh_aabb_dyn;