Expose mj_makeM as a sub-component.

PiperOrigin-RevId: 763662068
Change-Id: I55ced456dca751c1de09fb35e2f73c60ffc0d626
This commit is contained in:
Yuval Tassa
2025-05-27 00:33:27 -07:00
committed by Copybara-Service
parent 4a102c37bc
commit 89e39dc0a7
12 changed files with 58 additions and 10 deletions
+13 -2
View File
@@ -748,8 +748,7 @@ Compare forward and inverse dynamics, save results in fwdinv.
Sub components Sub components
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
These are sub-components of the simulation pipeline, called internally from the components above. It is very unlikely These are sub-components of the simulation pipeline, called internally from the components above.
that the user will need to call them.
.. _mj_sensorPos: .. _mj_sensorPos:
@@ -886,6 +885,18 @@ Compute actuator transmission lengths and moments.
Run composite rigid body inertia algorithm (CRB). Run composite rigid body inertia algorithm (CRB).
.. _mj_makeM:
`mj_makeM <#mj_makeM>`__
~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mj_makeM
Compute the composite rigid body inertia with :ref:`mj_crb`, add terms due
to :ref:`tendon armature<tendon-spatial-armature>`. The joint-space inertia matrix is stored in both ``mjData.qM`` and
``mjData.M``. These arrays represent the same quantity using different layouts (parent-based and compressed sparse row,
respectively).
.. _mj_factorM: .. _mj_factorM:
`mj_factorM <#mj_factorM>`__ `mj_factorM <#mj_factorM>`__
+8 -2
View File
@@ -113,8 +113,14 @@ Integrates the simulation state using an implicit-in-velocity integrator (either
.. _Subcomponents: .. _Subcomponents:
These are sub-components of the simulation pipeline, called internally from the components above. It is very unlikely These are sub-components of the simulation pipeline, called internally from the components above.
that the user will need to call them.
.. _mj_makeM:
Compute the composite rigid body inertia with :ref:`mj_crb`, add terms due
to :ref:`tendon armature<tendon-spatial-armature>`. The joint-space inertia matrix is stored in both ``mjData.qM`` and
``mjData.M``. These arrays represent the same quantity using different layouts (parent-based and compressed sparse row,
respectively).
.. _mj_factorM: .. _mj_factorM:
+2 -2
View File
@@ -2918,8 +2918,8 @@ Attributes may be applied or ignored depending on the lighting model being used.
.. _body-light-directional: .. _body-light-directional:
:at:`directional`: :at-val:`[false, true], "false"` :at:`directional`: :at-val:`[false, true], "false"`
This is a deprecated legacy attribute. Please use :ref:`light <light-type>` type instead. If set to "true", and no This is a deprecated legacy attribute. Please use :ref:`light <body-light-type>` type instead. If set to "true", and
type is specified, this will change the light type to be directional. no type is specified, this will change the light type to be directional.
.. _body-light-castshadow: .. _body-light-castshadow:
+3
View File
@@ -14,6 +14,9 @@ General
- Replaced the :ref:`directional<body-light-directional>` (boolean) field for lights with a - Replaced the :ref:`directional<body-light-directional>` (boolean) field for lights with a
:ref:`type<body-light-type>` field (of type :ref:`mjtLightType<mjtLightType>`) to allow for additional lighting :ref:`type<body-light-type>` field (of type :ref:`mjtLightType<mjtLightType>`) to allow for additional lighting
types. types.
- Added new sub-component :ref:`mj_makeM` which combines the :ref:`mj_crb` call with additional logic to support the
introduction in 3.3.1 of :ref:`tendon armature<tendon-spatial-armature>`. In addition to the traditional
``mjData.qM``, :ref:`mj_makeM` also computes ``mjData.M``, a CSR representation of the same matrix.
Simulate Simulate
^^^^^^^^ ^^^^^^^^
+1 -1
View File
@@ -1692,7 +1692,7 @@ The stages below compute quantities that depend on the generalized positions ``m
4. Compute quantities related to :ref:`flex<deformable-flex>` objects: :ref:`mj_flex` 4. Compute quantities related to :ref:`flex<deformable-flex>` objects: :ref:`mj_flex`
5. Compute the tendon lengths and moment arms. This includes the computation of minimal-length paths for spatial 5. Compute the tendon lengths and moment arms. This includes the computation of minimal-length paths for spatial
tendons: :ref:`mj_tendon` tendons: :ref:`mj_tendon`
6. Compute the composite rigid body inertias and joint-space inertia matrix: :ref:`mj_crb` 6. Compute the composite rigid body inertias and joint-space inertia matrix: :ref:`mj_makeM`
7. Compute the sparse factorization of the joint-space inertia matrix: :ref:`mj_factorM` 7. Compute the sparse factorization of the joint-space inertia matrix: :ref:`mj_factorM`
8. Construct the list of active contacts. This includes both broad-phase and near-phase collision detection: 8. Construct the list of active contacts. This includes both broad-phase and near-phase collision detection:
:ref:`mj_collision` :ref:`mj_collision`
+2 -1
View File
@@ -267,7 +267,7 @@ struct mjData_ {
int* moment_colind; // column indices in sparse Jacobian (nJmom x 1) int* moment_colind; // column indices in sparse Jacobian (nJmom x 1)
mjtNum* actuator_moment; // actuator moments (nJmom x 1) mjtNum* actuator_moment; // actuator moments (nJmom x 1)
// computed by mj_fwdPosition/mj_crb // computed by mj_fwdPosition/mj_makeM
mjtNum* crb; // com-based composite inertia and mass (nbody x 10) mjtNum* crb; // com-based composite inertia and mass (nbody x 10)
mjtNum* qM; // inertia (sparse) (nM x 1) mjtNum* qM; // inertia (sparse) (nM x 1)
mjtNum* M; // reduced inertia (compressed sparse row) (nC x 1) mjtNum* M; // reduced inertia (compressed sparse row) (nC x 1)
@@ -3068,6 +3068,7 @@ void mj_flex(const mjModel* m, mjData* d);
void mj_tendon(const mjModel* m, mjData* d); void mj_tendon(const mjModel* m, mjData* d);
void mj_transmission(const mjModel* m, mjData* d); void mj_transmission(const mjModel* m, mjData* d);
void mj_crb(const mjModel* m, mjData* d); void mj_crb(const mjModel* m, mjData* d);
void mj_makeM(const mjModel* m, mjData* d);
void mj_factorM(const mjModel* m, mjData* d); void mj_factorM(const mjModel* m, mjData* d);
void mj_solveM(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n); void mj_solveM(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n);
void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y,
+1 -1
View File
@@ -295,7 +295,7 @@ struct mjData_ {
int* moment_colind; // column indices in sparse Jacobian (nJmom x 1) int* moment_colind; // column indices in sparse Jacobian (nJmom x 1)
mjtNum* actuator_moment; // actuator moments (nJmom x 1) mjtNum* actuator_moment; // actuator moments (nJmom x 1)
// computed by mj_fwdPosition/mj_crb // computed by mj_fwdPosition/mj_makeM
mjtNum* crb; // com-based composite inertia and mass (nbody x 10) mjtNum* crb; // com-based composite inertia and mass (nbody x 10)
mjtNum* qM; // inertia (sparse) (nM x 1) mjtNum* qM; // inertia (sparse) (nM x 1)
mjtNum* M; // reduced inertia (compressed sparse row) (nC x 1) mjtNum* M; // reduced inertia (compressed sparse row) (nC x 1)
+3
View File
@@ -364,6 +364,9 @@ MJAPI void mj_transmission(const mjModel* m, mjData* d);
// Run composite rigid body inertia algorithm (CRB). // Run composite rigid body inertia algorithm (CRB).
MJAPI void mj_crb(const mjModel* m, mjData* d); MJAPI void mj_crb(const mjModel* m, mjData* d);
// Make inertia matrix.
MJAPI void mj_makeM(const mjModel* m, mjData* d);
// Compute sparse L'*D*L factorizaton of inertia matrix. // Compute sparse L'*D*L factorizaton of inertia matrix.
MJAPI void mj_factorM(const mjModel* m, mjData* d); MJAPI void mj_factorM(const mjModel* m, mjData* d);
+1
View File
@@ -211,6 +211,7 @@ PYBIND11_MODULE(_functions, pymodule) {
Def<traits::mj_tendon>(pymodule); Def<traits::mj_tendon>(pymodule);
Def<traits::mj_transmission>(pymodule); Def<traits::mj_transmission>(pymodule);
Def<traits::mj_crb>(pymodule); Def<traits::mj_crb>(pymodule);
Def<traits::mj_makeM>(pymodule);
Def<traits::mj_factorM>(pymodule); Def<traits::mj_factorM>(pymodule);
DEF_WITH_OMITTED_PY_ARGS(traits::mj_solveM, "n")( DEF_WITH_OMITTED_PY_ARGS(traits::mj_solveM, "n")(
pymodule, pymodule,
+20
View File
@@ -1829,6 +1829,26 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
), ),
doc='Run composite rigid body inertia algorithm (CRB).', doc='Run composite rigid body inertia algorithm (CRB).',
)), )),
('mj_makeM',
FunctionDecl(
name='mj_makeM',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='m',
type=PointerType(
inner_type=ValueType(name='mjModel', is_const=True),
),
),
FunctionParameterDecl(
name='d',
type=PointerType(
inner_type=ValueType(name='mjData'),
),
),
),
doc='Make inertia matrix.',
)),
('mj_factorM', ('mj_factorM',
FunctionDecl( FunctionDecl(
name='mj_factorM', name='mj_factorM',
+1 -1
View File
@@ -55,7 +55,7 @@ MJAPI void mj_crb(const mjModel* m, mjData* d);
MJAPI void mj_tendonArmature(const mjModel* m, mjData* d); MJAPI void mj_tendonArmature(const mjModel* m, mjData* d);
// make inertia matrix // make inertia matrix
void mj_makeM(const mjModel* m, mjData* d); MJAPI void mj_makeM(const mjModel* m, mjData* d);
// sparse L'*D*L factorizaton of inertia-like matrix M, assumed spd (legacy implementation) // sparse L'*D*L factorizaton of inertia-like matrix M, assumed spd (legacy implementation)
MJAPI void mj_factorI_legacy(const mjModel* m, mjData* d, const mjtNum* M, MJAPI void mj_factorI_legacy(const mjModel* m, mjData* d, const mjtNum* M,
+3
View File
@@ -6511,6 +6511,9 @@ public static unsafe extern void mj_transmission(mjModel_* m, mjData_* d);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_crb(mjModel_* m, mjData_* d); public static unsafe extern void mj_crb(mjModel_* m, mjData_* d);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_makeM(mjModel_* m, mjData_* d);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_factorM(mjModel_* m, mjData_* d); public static unsafe extern void mj_factorM(mjModel_* m, mjData_* d);