diff --git a/doc/APIreference/functions.rst b/doc/APIreference/functions.rst index 3ecf8df8..d47ca1d7 100644 --- a/doc/APIreference/functions.rst +++ b/doc/APIreference/functions.rst @@ -235,6 +235,15 @@ mj_setState Copy concatenated state components specified by ``spec`` from ``state`` into ``d``. The bits of the integer ``spec`` correspond to element fields of :ref:`mjtState`. Fails with :ref:`mju_error` if ``spec`` is invalid. +.. _mj_setKeyframe: + +mj_setKeyframe +~~~~~~~~~~~~~~ + +.. mujoco-include:: mj_setKeyframe + +Copy current state to the k-th model keyframe. + .. _mj_addContact: mj_addContact @@ -1866,7 +1875,15 @@ mju_sigmoid .. mujoco-include:: mju_sigmoid -Sigmoid function over 0<=x<=1 using quintic polynomial. +Twice continuously differentiable sigmoid function using a quintic polynomial: + +.. math:: + s(x) = + \begin{cases} + 0, & & x \le 0 \\ + 6x^5 - 15x^4 + 10x^3, & 0 \lt & x \lt 1 \\ + 1, & 1 \le & x \qquad + \end{cases} .. _Interaction: diff --git a/doc/APIreference/functions_override.rst b/doc/APIreference/functions_override.rst index cb212686..cdc4593e 100644 --- a/doc/APIreference/functions_override.rst +++ b/doc/APIreference/functions_override.rst @@ -533,6 +533,18 @@ Symmetrize square matrix :math:`R = \frac{1}{2}(M + M^T)`. .. _Miscellaneous: +.. _mju_sigmoid: + +Twice continuously differentiable sigmoid function using a quintic polynomial: + +.. math:: + s(x) = + \begin{cases} + 0, & & x \le 0 \\ + 6x^5 - 15x^4 + 10x^3, & 0 \lt & x \lt 1 \\ + 1, & 1 \le & x \qquad + \end{cases} + .. _Derivatives-api: The functions below provide useful derivatives of various functions, both analytic and diff --git a/doc/changelog.rst b/doc/changelog.rst index 72025f13..f643f499 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -21,13 +21,14 @@ General :ref:`camera/orthographic` and :ref:`global/orthographic` attributes, respectively. 3. Added :ref:`maxhullvert`, the maximum number of vertices in a mesh's convex hull. -4. Add support for ``ball`` joints in the URDF parser. +4. Added :ref:`mj_setKeyframe` for saving the current state into a model keyframe. +5. Added support for ``ball`` joints in the URDF parser ("spherical" in URDF). MJX ~~~ -5. Added support for :ref:`elliptic friction cones`. -6. Fixed a bug that resulted in less-optimal linesearch solutions for some difficult constraint settings. -7. Fixed a bug in the Newton solver that sometimes resulted in less-optimal gradients. +6. Added support for :ref:`elliptic friction cones`. +7. Fixed a bug that resulted in less-optimal linesearch solutions for some difficult constraint settings. +8. Fixed a bug in the Newton solver that sometimes resulted in less-optimal gradients. Version 3.1.6 (Jun 3, 2024) --------------------------- diff --git a/doc/includes/references.h b/doc/includes/references.h index 105b03d2..2f1fb622 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -3171,6 +3171,7 @@ void mj_constraintUpdate(const mjModel* m, mjData* d, const mjtNum* jar, int mj_stateSize(const mjModel* m, unsigned int spec); void mj_getState(const mjModel* m, const mjData* d, mjtNum* state, unsigned int spec); void mj_setState(const mjModel* m, mjData* d, const mjtNum* state, unsigned int spec); +void mj_setKeyframe(mjModel* m, const mjData* d, int k); int mj_addContact(const mjModel* m, mjData* d, const mjContact* con); int mj_isPyramidal(const mjModel* m); int mj_isSparse(const mjModel* m); diff --git a/include/mujoco/mujoco.h b/include/mujoco/mujoco.h index 4166543c..5c90a152 100644 --- a/include/mujoco/mujoco.h +++ b/include/mujoco/mujoco.h @@ -418,6 +418,9 @@ MJAPI void mj_getState(const mjModel* m, const mjData* d, mjtNum* state, unsigne // Set state. MJAPI void mj_setState(const mjModel* m, mjData* d, const mjtNum* state, unsigned int spec); +// Copy current state to the k-th model keyframe. +MJAPI void mj_setKeyframe(mjModel* m, const mjData* d, int k); + // Add contact to d->contact list; return 0 if success; 1 if buffer full. MJAPI int mj_addContact(const mjModel* m, mjData* d, const mjContact* con); diff --git a/introspect/functions.py b/introspect/functions.py index a4cb5820..1e5875aa 100644 --- a/introspect/functions.py +++ b/introspect/functions.py @@ -2244,6 +2244,30 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([ ), doc='Set state.', )), + ('mj_setKeyframe', + FunctionDecl( + name='mj_setKeyframe', + return_type=ValueType(name='void'), + parameters=( + FunctionParameterDecl( + name='m', + type=PointerType( + inner_type=ValueType(name='mjModel'), + ), + ), + FunctionParameterDecl( + name='d', + type=PointerType( + inner_type=ValueType(name='mjData', is_const=True), + ), + ), + FunctionParameterDecl( + name='k', + type=ValueType(name='int'), + ), + ), + doc='Copy current state to the k-th model keyframe.', + )), ('mj_addContact', FunctionDecl( name='mj_addContact', diff --git a/python/mujoco/bindings_test.py b/python/mujoco/bindings_test.py index 8faa6db6..4ea6b3a9 100644 --- a/python/mujoco/bindings_test.py +++ b/python/mujoco/bindings_test.py @@ -27,6 +27,7 @@ import numpy as np TEST_XML = r""" +