Improve pipeline documentation, expose mj_implicit function to public header.

PiperOrigin-RevId: 586380774
Change-Id: I3fafa563ebc852e17e1233288455b96f4499027b
This commit is contained in:
Yuval Tassa
2023-11-29 10:18:11 -08:00
committed by Copybara-Service
parent 2f37147fc0
commit 822b03446c
8 changed files with 97 additions and 37 deletions
+11
View File
@@ -583,6 +583,17 @@ mj_RungeKutta
Runge-Kutta explicit order-N integrator. Runge-Kutta explicit order-N integrator.
.. _mj_implicit:
mj_implicit
~~~~~~~~~~~
.. mujoco-include:: mj_implicit
Integrates the simulation state using an implicit-in-velocity integrator (either "implicit" or "implicitfast", see
:ref:`Numerical Integration<geIntegration>`), and advances simulation time. See `mjdata.h
<https://github.com/google-deepmind/mujoco/blob/main/include/mujoco/mjdata.h>`__ for fields computed by this function.
.. _mj_invPosition: .. _mj_invPosition:
mj_invPosition mj_invPosition
+6
View File
@@ -69,6 +69,12 @@ These functions can be used to print various quantities to the screen for debugg
These are components of the simulation pipeline, called internally from :ref:`mj_step`, :ref:`mj_forward` and These are components of the simulation pipeline, called internally from :ref:`mj_step`, :ref:`mj_forward` and
:ref:`mj_inverse`. It is unlikely that the user will need to call them. :ref:`mj_inverse`. It is unlikely that the user will need to call them.
.. _mj_implicit:
Integrates the simulation state using an implicit-in-velocity integrator (either "implicit" or "implicitfast", see
:ref:`Numerical Integration<geIntegration>`), and advances simulation time. See `mjdata.h
<https://github.com/google-deepmind/mujoco/blob/main/include/mujoco/mjdata.h>`__ for fields computed by this function.
.. _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. It is very unlikely
+52 -37
View File
@@ -1538,44 +1538,59 @@ be used to skip default steps and to enable optional steps respectively. Callbac
Forward dynamics Forward dynamics
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
The top-level function :ref:`mj_step` invokes the sequence of computations below. Alternatively one can call The source file `engine_forward.c <https://github.com/google-deepmind/mujoco/blob/main/src/engine/engine_forward.c>`__
:ref:`mj_forward` which invokes only steps 2-21. contains the high-level forward dynamics pipeline:
#. Check the positions and velocities for invalid or unacceptably large real values indicating divergence. If divergence - The top-level function :ref:`mj_step` invokes the entire sequence of computations below.
is detected, the state is automatically reset and the corresponding warning is raised. - :ref:`mj_forward` invokes only stages **2-22**, computing the continuous-time forward dynamics, ending with the
#. Compute the forward kinematics. This yields the global positions and orientations of all bodies, geoms, sites, acceleration ``mjData.qacc``.
cameras and lights. It also normalizes all quaternions, just in case. - :ref:`mj_step1` invokes stages **1-18** and :ref:`mj_step2` invokes stages **19-25**, breaking :ref:`mj_step` into two
#. Compute the body inertias and joint axes, in global frames centered at the centers of mass of the corresponding distinct phases. This allows the user to write controllers that depend on quantities derived from the positions and
kinematic subtrees (to improve floating-point accuracy). velocities (but not forces, since those have not yet been computed). Note that the :ref:`mj_step1` → :ref:`mj_step2`
#. Compute the actuator lengths and moment arms. pipeline does not support the Runge Kutta integrator.
#. Compute the composite rigid body inertias and construct the joint-space inertia matrix.
#. Compute the sparse factorization of the joint-space inertia matrix. 1. Check the positions and velocities for invalid or unacceptably large real values indicating divergence. If divergence
#. Construct the list of active contacts. This includes both broad-phase and near-phase collision detection. is detected, the state is automatically reset and the corresponding warning is raised:
#. Construct the constraint Jacobian and compute the constraint residuals. :ref:`mj_checkPos`, :ref:`mj_checkVel`
#. Compute the matrices and vectors needed by the constraint solvers. 2. Compute the forward kinematics. This yields the global positions and orientations of all bodies, geoms, sites,
#. Compute the tendon lengths and moment arms. This includes the computation of minimal-length paths for spatial cameras and lights. It also normalizes all quaternions: :ref:`mj_kinematics`, :ref:`mj_camLight`
tendons. 3. Compute the body inertias and joint axes, in global frames centered at the centers of mass of the corresponding
#. Compute sensor data that only depends on position, and the potential energy if enabled. kinematic subtrees: :ref:`mj_comPos`
#. Compute the tendon and actuator velocities. 4. Compute quantities related to :ref:`flex<deformable-flex>` objects: :ref:`mj_flex`
#. Compute the body velocities and rates of change of the joint axes, again in the global coordinate frames centered at 5. Compute the actuator lengths and moment arms: :ref:`mj_tendon`
the subtree centers of mass. 6. Compute the composite rigid body inertias and joint-space inertia matrix: :ref:`mj_crb`
#. Compute all passive forces: spring-dampers in joints and tendons, and fluid dynamics forces. 7. Compute the sparse factorization of the joint-space inertia matrix: :ref:`mj_factorM`
#. Compute sensor data that depends on velocity, and the kinetic energy if enabled. 8. Construct the list of active contacts. This includes both broad-phase and near-phase collision detection:
If required by sensors, call :ref:`mj_subtreeVel`. :ref:`mj_collision`
#. Compute the reference constraint acceleration. 9. Construct the constraint Jacobian and compute the constraint residuals: :ref:`mj_makeConstraint`
#. Compute the vector of Coriolis, centrifugal and gravitational forces. 10. Compute the matrices and vectors needed by the constraint solvers: :ref:`mj_projectConstraint`
#. Compute the actuator forces and activation dynamics if defined. 11. Compute the tendon lengths and moment arms. This includes the computation of minimal-length paths for spatial
#. Compute the joint acceleration resulting from all forces except for the (still unknown) constraint forces. tendons: :ref:`mj_transmission`
#. Compute the constraint forces with the selected solver, and update the joint acceleration so as to account for the 12. Compute sensor data that only depends on position, and the potential energy if enabled: :ref:`mj_sensorPos`,
constraint forces. This yields the vector ``mjData.qacc`` which is the main output of forward dynamics. :ref:`mj_energyPos`
#. Compute sensor data that depends on force and acceleration if enabled. 13. Compute the tendon, flex edge and actuator velocities: :ref:`mj_fwdVelocity`
If required by sensors, call :ref:`mj_rnePostConstraint`. 14. Compute the body velocities and rates of change of the joint axes, again in the global coordinate frames centered at
#. Check the acceleration for invalid or unacceptably large real values. If divergence is detected, the state is the subtree centers of mass: :ref:`mj_comVel`
automatically reset and the corresponding warning is raised. 15. Compute passive forces -- spring-dampers in joints and tendons, and fluid forces: :ref:`mj_passive`
#. Compare the results of forward and inverse dynamics, so as to diagnose poor solver convergence in the forward 16. Compute sensor data that depends on velocity, and the kinetic energy if enabled
dynamics. This is an optional step, and is performed only when enabled. (if required by sensors, call :ref:`mj_subtreeVel`): :ref:`mj_sensorVel`
#. Advance the simulation state by one time step, using the selected integrator. Note that the Runge-Kutta integrator 17. Compute the reference constraint acceleration: :ref:`mj_referenceConstraint`
repeats the above sequence three more times, except for the optional computations which are performed only once. 18. Compute the vector of Coriolis, centrifugal and gravitational forces: :ref:`mj_rne`
19. Compute the actuator forces and activation dynamics if defined: :ref:`mj_fwdActuation`
20. Compute the joint acceleration resulting from all forces except for the (still unknown) constraint forces:
:ref:`mj_fwdAcceleration`
21. Compute the constraint forces with the selected solver, and update the joint acceleration so as to account for the
constraint forces. This yields the vector ``mjData.qacc`` which is the main output of forward dynamics:
:ref:`mj_fwdConstraint`
22. Compute sensor data that depends on force and acceleration if enabled
(if required by sensors, call :ref:`mj_rnePostConstraint`): :ref:`mj_sensorAcc`
23. Check the acceleration for invalid or unacceptably large real values. If divergence is detected, the state is
automatically reset and the corresponding warning is raised: :ref:`mj_checkAcc`
24. Compare the results of forward and inverse dynamics, so as to diagnose poor solver convergence in the forward
dynamics. This is an optional step, and is performed only when enabled: :ref:`mj_compareFwdInv`
25. Advance the simulation state by one time step, using the selected integrator. Note that the Runge-Kutta integrator
repeats the above sequence three more times, except for the optional computations which are performed only once:
one of :ref:`mj_Euler`, :ref:`mj_RungeKutta`, :ref:`mj_implicit`
.. _piInverse: .. _piInverse:
+1
View File
@@ -2445,6 +2445,7 @@ void mj_fwdAcceleration(const mjModel* m, mjData* d);
void mj_fwdConstraint(const mjModel* m, mjData* d); void mj_fwdConstraint(const mjModel* m, mjData* d);
void mj_Euler(const mjModel* m, mjData* d); void mj_Euler(const mjModel* m, mjData* d);
void mj_RungeKutta(const mjModel* m, mjData* d, int N); void mj_RungeKutta(const mjModel* m, mjData* d, int N);
void mj_implicit(const mjModel* m, mjData* d);
void mj_invPosition(const mjModel* m, mjData* d); void mj_invPosition(const mjModel* m, mjData* d);
void mj_invVelocity(const mjModel* m, mjData* d); void mj_invVelocity(const mjModel* m, mjData* d);
void mj_invConstraint(const mjModel* m, mjData* d); void mj_invConstraint(const mjModel* m, mjData* d);
+3
View File
@@ -264,6 +264,9 @@ MJAPI void mj_Euler(const mjModel* m, mjData* d);
// Runge-Kutta explicit order-N integrator. // Runge-Kutta explicit order-N integrator.
MJAPI void mj_RungeKutta(const mjModel* m, mjData* d, int N); MJAPI void mj_RungeKutta(const mjModel* m, mjData* d, int N);
// Implicit-in-velocity integrators.
MJAPI void mj_implicit(const mjModel* m, mjData* d);
// Run position-dependent computations in inverse dynamics. // Run position-dependent computations in inverse dynamics.
MJAPI void mj_invPosition(const mjModel* m, mjData* d); MJAPI void mj_invPosition(const mjModel* m, mjData* d);
+20
View File
@@ -1156,6 +1156,26 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
), ),
doc='Runge-Kutta explicit order-N integrator.', doc='Runge-Kutta explicit order-N integrator.',
)), )),
('mj_implicit',
FunctionDecl(
name='mj_implicit',
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='Implicit-in-velocity integrators.',
)),
('mj_invPosition', ('mj_invPosition',
FunctionDecl( FunctionDecl(
name='mj_invPosition', name='mj_invPosition',
+1
View File
@@ -185,6 +185,7 @@ PYBIND11_MODULE(_functions, pymodule) {
Def<traits::mj_fwdConstraint>(pymodule); Def<traits::mj_fwdConstraint>(pymodule);
Def<traits::mj_Euler>(pymodule); Def<traits::mj_Euler>(pymodule);
Def<traits::mj_RungeKutta>(pymodule); Def<traits::mj_RungeKutta>(pymodule);
Def<traits::mj_implicit>(pymodule);
Def<traits::mj_invPosition>(pymodule); Def<traits::mj_invPosition>(pymodule);
Def<traits::mj_invVelocity>(pymodule); Def<traits::mj_invVelocity>(pymodule);
Def<traits::mj_invConstraint>(pymodule); Def<traits::mj_invConstraint>(pymodule);
+3
View File
@@ -6461,6 +6461,9 @@ public static unsafe extern void mj_Euler(mjModel_* m, mjData_* d);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_RungeKutta(mjModel_* m, mjData_* d, int N); public static unsafe extern void mj_RungeKutta(mjModel_* m, mjData_* d, int N);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_implicit(mjModel_* m, mjData_* d);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_invPosition(mjModel_* m, mjData_* d); public static unsafe extern void mj_invPosition(mjModel_* m, mjData_* d);