From ee8da5babe1f916cc12df824097f1978422b5f1a Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Mon, 18 Sep 2023 01:46:59 -0700 Subject: [PATCH 01/89] Fix indentation bugs in docs, improve attribute order in schema. PiperOrigin-RevId: 566230568 Change-Id: I0f536a2048d3e35d8ee510d86b6eba7a74c4e80a --- doc/XMLreference.rst | 42 +++++++++++++-------------- doc/XMLschema.rst | 56 ++++++++++++++++++------------------ src/xml/xml_native_reader.cc | 16 +++++------ 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/doc/XMLreference.rst b/doc/XMLreference.rst index fa2d63fe..0de9e1c3 100644 --- a/doc/XMLreference.rst +++ b/doc/XMLreference.rst @@ -1562,7 +1562,7 @@ The full list of processing steps applied by the compiler to each mesh is as fol .. _mesh-plugin: :el-prefix:`mesh/` |-| **plugin** (?) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +''''''''''''''''''''''''''''''''''''' Associate this mesh with an :ref:`engine plugin`. Either :at:`plugin` or :at:`instance` are required. @@ -2246,24 +2246,6 @@ defined. Its body name is automatically defined as "world". See :ref:`CUser`. -.. _body-plugin: - -:el-prefix:`body/` |-| **plugin** (?) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Associate this body with an :ref:`engine plugin`. Either :at:`plugin` or :at:`instance` are required. - -.. _body-plugin-plugin: - -:at:`plugin`: :at-val:`string, optional` - Plugin identifier, used for implicit plugin instantiation. - -.. _body-plugin-instance: - -:at:`instance`: :at-val:`string, optional` - Instance name, used for explicit plugin instantiation. - - .. _body-inertial: :el-prefix:`body/` |-| **inertial** (?) @@ -2898,7 +2880,7 @@ helps clarify the role of bodies and geoms in MuJoCo. .. _geom-plugin: :el-prefix:`geom/` |-| **plugin** (?) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +''''''''''''''''''''''''''''''''''''' Associate this geom with an :ref:`engine plugin`. Either :at:`plugin` or :at:`instance` are required. @@ -3200,6 +3182,24 @@ the direction specified by the dir attribute. It does not have a full spatial fr The specular color of the light. +.. _body-plugin: + +:el-prefix:`body/` |-| **plugin** (?) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Associate this body with an :ref:`engine plugin`. Either :at:`plugin` or :at:`instance` are required. + +.. _body-plugin-plugin: + +:at:`plugin`: :at-val:`string, optional` + Plugin identifier, used for implicit plugin instantiation. + +.. _body-plugin-instance: + +:at:`instance`: :at-val:`string, optional` + Instance name, used for explicit plugin instantiation. + + .. _body-composite: :el-prefix:`body/` |-| **composite** (*) @@ -3650,7 +3650,7 @@ handle where the composite object is attached. For other composite types this su .. _composite-plugin: :el-prefix:`composite/` |-| **plugin** (?) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +'''''''''''''''''''''''''''''''''''''''''' Associate this composite with an :ref:`engine plugin`. Either :at:`plugin` or :at:`instance` are required. diff --git a/doc/XMLschema.rst b/doc/XMLschema.rst index 6cc3590a..2a890c51 100644 --- a/doc/XMLschema.rst +++ b/doc/XMLschema.rst @@ -260,20 +260,6 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| body |br| |_| |L| | | .. table:: | -| :ref:`plugin | \* | :class: mjcf-attributes | -| ` | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`plugin` | :ref:`instance` | | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| |_2| plugin |br| |_2| |L| | | .. table:: | -| :ref:`config | \* | :class: mjcf-attributes | -| ` | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`key` | :ref:`value` | | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| |_| body |br| |_| |L| | | .. table:: | | :ref:`inertial | ? | :class: mjcf-attributes | | ` | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | @@ -385,6 +371,20 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| body |br| |_| |L| | | .. table:: | +| :ref:`plugin | \* | :class: mjcf-attributes | +| ` | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +| | | | :ref:`plugin` | :ref:`instance` | | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | ++------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| |_2| plugin |br| |_2| |L| | | .. table:: | +| :ref:`config | \* | :class: mjcf-attributes | +| ` | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +| | | | :ref:`key` | :ref:`value` | | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | ++------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| |_| body |br| |_| |L| | | .. table:: | | :ref:`composite | \* | :class: mjcf-attributes | | ` | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | @@ -398,20 +398,6 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_2| composite |br| |_2| |L| | | .. table:: | -| :ref:`plugin | \* | :class: mjcf-attributes | -| ` | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`plugin` | :ref:`instance` | | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| |_3| plugin |br| |_3| |L| | | .. table:: | -| :ref:`config | \* | :class: mjcf-attributes | -| ` | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`key` | :ref:`value` | | | | -| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| |_2| composite |br| |_2| |L| | | .. table:: | | :ref:`joint | \* | :class: mjcf-attributes | | ` | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | @@ -479,6 +465,20 @@ | | | | :ref:`coord` | | | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| |_2| composite |br| |_2| |L| | | .. table:: | +| :ref:`plugin | \* | :class: mjcf-attributes | +| ` | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +| | | | :ref:`plugin` | :ref:`instance` | | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | ++------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| |_3| plugin |br| |_3| |L| | | .. table:: | +| :ref:`config | \* | :class: mjcf-attributes | +| ` | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +| | | | :ref:`key` | :ref:`value` | | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | ++------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | mujoco |br| |L| | | *no attributes* | | :ref:`contact` | | | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index 8e244550..2aba5f79 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -239,10 +239,6 @@ static const char* MJCF[nMJCF][mjXATTRNUM] = { {"body", "R", "11", "name", "childclass", "pos", "quat", "mocap", "axisangle", "xyaxes", "zaxis", "euler", "gravcomp", "user"}, {"<"}, - {"plugin", "*", "2", "plugin", "instance"}, - {"<"}, - {"config", "*", "2", "key", "value"}, - {">"}, {"inertial", "?", "9", "pos", "quat", "mass", "diaginertia", "axisangle", "xyaxes", "zaxis", "euler", "fullinertia"}, {"joint", "*", "23", "name", "class", "type", "group", "pos", "axis", @@ -270,14 +266,14 @@ static const char* MJCF[nMJCF][mjXATTRNUM] = { {"light", "*", "15", "name", "class", "directional", "castshadow", "active", "pos", "dir", "attenuation", "cutoff", "exponent", "ambient", "diffuse", "specular", "mode", "target"}, + {"plugin", "*", "2", "plugin", "instance"}, + {"<"}, + {"config", "*", "2", "key", "value"}, + {">"}, {"composite", "*", "13", "prefix", "type", "count", "spacing", "offset", "flatinertia", "solrefsmooth", "solimpsmooth", "vertex", "face", "initial", "curve", "size"}, {"<"}, - {"plugin", "*", "2", "plugin", "instance"}, - {"<"}, - {"config", "*", "2", "key", "value"}, - {">"}, {"joint", "*", "17", "kind", "group", "stiffness", "damping", "armature", "solreffix", "solimpfix", "type", "axis", "limited", "range", "margin", "solreflimit", "solimplimit", @@ -293,6 +289,10 @@ static const char* MJCF[nMJCF][mjXATTRNUM] = { "density", "solmix", "solref", "solimp", "margin", "gap"}, {"site", "?", "4", "group", "size", "material", "rgba"}, {"pin", "*", "1", "coord"}, + {"plugin", "*", "2", "plugin", "instance"}, + {"<"}, + {"config", "*", "2", "key", "value"}, + {">"}, {">"}, {">"}, From 6ca8a7bdf718feb44f2c7a4ce4daad0eed1cb74c Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 18 Sep 2023 08:26:56 -0700 Subject: [PATCH 02/89] Make SdfLib dependency on `args` and `stb_image` optional. PiperOrigin-RevId: 566309916 Change-Id: I74880781848b7e5235cdf5d723b0c8805827a4c8 --- cmake/sdflib-optional-dependencies.patch | 61 ++++++++++++++++++++---- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/cmake/sdflib-optional-dependencies.patch b/cmake/sdflib-optional-dependencies.patch index 2ec2ed04..46f44931 100644 --- a/cmake/sdflib-optional-dependencies.patch +++ b/cmake/sdflib-optional-dependencies.patch @@ -1,8 +1,8 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 20551cf..9145032 100644 +index 20551cf..0d2a364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -70,14 +70,21 @@ add_custom_target(copyShaders ALL SOURCES ${SHADER_FILES}) +@@ -70,15 +70,25 @@ add_custom_target(copyShaders ALL SOURCES ${SHADER_FILES}) # Add dependencies add_subdirectory(libs) @@ -16,19 +16,25 @@ index 20551cf..9145032 100644 + target_link_libraries(${PROJECT_NAME} PUBLIC assimp) + target_compile_definitions(${PROJECT_NAME} PUBLIC -DASSIMP_AVAILABLE) +endif() ++ ++if(SDFLIB_BUILD_APPS OR SDFLIB_BUILD_DEBUG_APPS) ++ target_link_libraries(${PROJECT_NAME} PUBLIC args) ++ target_link_libraries(${PROJECT_NAME} PUBLIC stb_image) ++endif() + target_link_libraries(${PROJECT_NAME} PUBLIC glm) -target_link_libraries(${PROJECT_NAME} PUBLIC assimp) - target_link_libraries(${PROJECT_NAME} PUBLIC args) +-target_link_libraries(${PROJECT_NAME} PUBLIC args) target_link_libraries(${PROJECT_NAME} PUBLIC spdlog) target_link_libraries(${PROJECT_NAME} PUBLIC cereal) -target_link_libraries(${PROJECT_NAME} PUBLIC enoki) -target_link_libraries(${PROJECT_NAME} PUBLIC eigen) -target_link_libraries(${PROJECT_NAME} PUBLIC fcpw) - target_link_libraries(${PROJECT_NAME} PUBLIC stb_image) +-target_link_libraries(${PROJECT_NAME} PUBLIC stb_image) target_link_libraries(${PROJECT_NAME} PUBLIC icg) -@@ -86,17 +93,22 @@ if(CMAKE_CXX_COMPILER_ID MATCHES GNU) + if(CMAKE_CXX_COMPILER_ID MATCHES GNU) +@@ -86,17 +96,22 @@ if(CMAKE_CXX_COMPILER_ID MATCHES GNU) endif() # Add openMP @@ -62,7 +68,7 @@ index 20551cf..9145032 100644 # Add executable if (NOT UNIX) -@@ -160,6 +172,7 @@ if(SDFLIB_BUILD_DEBUG_APPS) +@@ -160,6 +175,7 @@ if(SDFLIB_BUILD_DEBUG_APPS) add_executable(GJKtest src/tools/GJKtest/main.cpp) target_link_libraries(GJKtest PUBLIC ${PROJECT_NAME}) @@ -269,10 +275,10 @@ index 9f930ed..6ee2304 100644 \ No newline at end of file +#endif diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt -index b48bf39..3f143c8 100644 +index b48bf39..ea22b9a 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt -@@ -14,23 +14,25 @@ if(NOT glm_lib_POPULATED) +@@ -14,37 +14,41 @@ if(NOT glm_lib_POPULATED) endif() # assimp @@ -314,7 +320,34 @@ index b48bf39..3f143c8 100644 endif() # args -@@ -76,43 +78,47 @@ if(NOT cereal_lib_POPULATED) +-FetchContent_Declare(args_lib +- GIT_REPOSITORY https://github.com/Taywee/args.git +- GIT_TAG a48e1f880813b367d2354963a58dedbf2b708584 # 6.3.0 +-) +- +-FetchContent_GetProperties(args_lib) +-if(NOT args_lib_POPULATED) +- FetchContent_Populate(args_lib) +- add_library(args INTERFACE) +- target_include_directories(args INTERFACE ${args_lib_SOURCE_DIR}) +-endif() ++if(SDFLIB_BUILD_APPS OR SDFLIB_BUILD_DEBUG_APPS) ++ FetchContent_Declare(args_lib ++ GIT_REPOSITORY https://github.com/Taywee/args.git ++ GIT_TAG a48e1f880813b367d2354963a58dedbf2b708584 # 6.3.0 ++ ) ++ ++ FetchContent_GetProperties(args_lib) ++ if(NOT args_lib_POPULATED) ++ FetchContent_Populate(args_lib) ++ add_library(args INTERFACE) ++ target_include_directories(args INTERFACE ${args_lib_SOURCE_DIR}) ++ endif() ++ endif() + + # spdlog + FetchContent_Declare(spdlog_lib +@@ -76,47 +80,53 @@ if(NOT cereal_lib_POPULATED) endif() # Enoki @@ -395,7 +428,15 @@ index b48bf39..3f143c8 100644 + endif() # stb - add_library(stb_image INTERFACE) +-add_library(stb_image INTERFACE) +-target_include_directories(stb_image INTERFACE stb) ++if(SDFLIB_BUILD_APPS OR SDFLIB_BUILD_DEBUG_APPS) ++ add_library(stb_image INTERFACE) ++ target_include_directories(stb_image INTERFACE stb) ++ endif() + + # icg + add_library(icg INTERFACE) diff --git a/src/sdf/OctreeSdf.cpp b/src/sdf/OctreeSdf.cpp index ef8ed4d..0e1eb97 100644 --- a/src/sdf/OctreeSdf.cpp From 812e617fe9ab9047201171a6b8a2d86f0a46a0f1 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Mon, 18 Sep 2023 09:26:15 -0700 Subject: [PATCH 03/89] Clear `mjData.actuator_moment` more selectively. PiperOrigin-RevId: 566324919 Change-Id: Ie453f8de059d39fa1ebd5248f33a18758ee748af --- src/engine/engine_core_smooth.c | 17 +++++++++++------ src/engine/engine_io.c | 3 +++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/engine/engine_core_smooth.c b/src/engine/engine_core_smooth.c index b175c495..6e8a4008 100644 --- a/src/engine/engine_core_smooth.c +++ b/src/engine/engine_core_smooth.c @@ -632,7 +632,6 @@ void mj_transmission(const mjModel* m, mjData* d) { jac = mj_stackAllocNum(d, 3*nv); jacA = mj_stackAllocNum(d, 3*nv); jacS = mj_stackAllocNum(d, 3*nv); - mju_zero(moment, nu*nv); // define variables required for body transmission, don't allocate int issparse = mj_isSparse(m); @@ -773,6 +772,9 @@ void mj_transmission(const mjModel* m, mjData* d) { // moment: sparse or dense if (mj_isSparse(m)) { + // clear moment + mju_zero(moment+i*nv, nv); + int end = d->ten_J_rowadr[id] + d->ten_J_rownnz[id]; for (int j=d->ten_J_rowadr[id]; j < end; j++) { moment[i*nv + d->ten_J_colind[j]] = d->ten_J[j] * gear[0]; @@ -786,11 +788,11 @@ void mj_transmission(const mjModel* m, mjData* d) { // get site translation (jac) and rotation (jacS) Jacobians in global frame mj_jacSite(m, d, jac, jacS, id); + // clear length + length[i] = 0; + // reference site undefined if (m->actuator_trnid[2*i+1] == -1) { - // cannot compute meaningful length, set to 0 - length[i] = 0; - // wrench: gear expressed in global frame mju_rotVecMat(wrench, gear, d->site_xmat+9*id); // translation mju_rotVecMat(wrench+3, gear+3, d->site_xmat+9*id); // rotation @@ -806,8 +808,8 @@ void mj_transmission(const mjModel* m, mjData* d) { int refid = m->actuator_trnid[2*i+1]; if (!jacref) jacref = mj_stackAllocNum(d, 3*nv); - // clear length - length[i] = 0; + // clear moment + mju_zero(moment+i*nv, nv); // translational transmission if (!mju_isZero(gear, 3)) { @@ -867,6 +869,9 @@ void mj_transmission(const mjModel* m, mjData* d) { // cannot compute meaningful length, set to 0 length[i] = 0; + // clear moment + mju_zero(moment+i*nv, nv); + // moment is average of all contact normal Jacobians { // allocate stack variables for the first mjTRN_BODY diff --git a/src/engine/engine_io.c b/src/engine/engine_io.c index a47a02fd..b27815ae 100644 --- a/src/engine/engine_io.c +++ b/src/engine/engine_io.c @@ -1487,6 +1487,9 @@ static void _resetData(const mjModel* m, mjData* d, unsigned char debug_value) { mju_zero(d->mocap_pos, 3*m->nmocap); mju_zero(d->mocap_quat, 4*m->nmocap); + // zero out actuator_moment, mj_transmission touches it selectively + mju_zero(d->actuator_moment, m->nv*m->nu); + // copy qpos0 from model if (m->qpos0) { memcpy(d->qpos, m->qpos0, m->nq*sizeof(mjtNum)); From 9902b73502d7dff0ebf20f3881b8dbbb3d95147d Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Mon, 18 Sep 2023 10:52:46 -0700 Subject: [PATCH 04/89] Rename `mj_stackAlloc` to `mj_stackAllocByte`. PiperOrigin-RevId: 566351365 Change-Id: I91541168e83b05a730113661cc9f07985ac9ff0c --- doc/APIreference/functions.rst | 8 ++++---- doc/changelog.rst | 6 +++--- doc/includes/references.h | 2 +- doc/programming/simulation.rst | 2 +- include/mujoco/mujoco.h | 2 +- introspect/functions.py | 4 ++-- python/mujoco/functions.cc | 16 ++++++++-------- python/mujoco/private.h | 2 +- python/mujoco/structs.cc | 10 +++++----- src/engine/engine_collision_driver.c | 8 ++++---- src/engine/engine_collision_sdf.c | 2 +- src/engine/engine_core_constraint.c | 16 ++++++++-------- src/engine/engine_io.c | 4 ++-- src/engine/engine_io.h | 4 ++-- src/engine/engine_island.c | 12 ++++++------ src/engine/engine_util_container.c | 4 ++-- test/engine/engine_io_test.cc | 4 ++-- unity/Runtime/Bindings/MjBindings.cs | 2 +- 18 files changed, 54 insertions(+), 54 deletions(-) diff --git a/doc/APIreference/functions.rst b/doc/APIreference/functions.rst index 1f33d81b..abc123ea 100644 --- a/doc/APIreference/functions.rst +++ b/doc/APIreference/functions.rst @@ -1251,12 +1251,12 @@ mj_freeStack Free the current :ref:`mjData` stack frame. All pointers returned by mj_stackAlloc since the last call to mj_markStack must no longer be used afterwards. -.. _mj_stackAlloc: +.. _mj_stackAllocByte: -mj_stackAlloc -~~~~~~~~~~~~~ +mj_stackAllocByte +~~~~~~~~~~~~~~~~~ -.. mujoco-include:: mj_stackAlloc +.. mujoco-include:: mj_stackAllocByte Allocate a number of bytes on :ref:`mjData` stack at a specific alignment. Call mju_error on stack overflow. diff --git a/doc/changelog.rst b/doc/changelog.rst index 77c6fae3..1945d26d 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -43,10 +43,10 @@ General :ref:`mj_freeStack`. These functions manage the :ref:`mjData stack` in a fully encapsulated way (i.e., without introducing a local variable at the call site). - 5. Changed the function :ref:`mj_stackAlloc` to allocate an arbitrary number of bytes, rather than in multiples of - ``sizeof(mjtNum)``, and added an additional argument for specifying the alignment of the returned pointer. + 5. Renamed ``mj_stackAlloc`` to :ref:`mj_stackAllocNum`. The new function :ref:`mj_stackAllocByte` allocates an + arbitrary number of bytes and has an additional argument for specifying the alignment of the returned pointer. - **Migration:** The functionality for allocating ``mjtNum`` arrays is available via :ref:`mj_stackAllocNum`. + **Migration:** The functionality for allocating ``mjtNum`` arrays is now available via :ref:`mj_stackAllocNum`. 6. Renamed the ``nstack`` field in :ref:`mjModel` and :ref:`mjData` to ``narena``. Changed ``narena``, ``pstack``, and ``maxuse_stack`` to count number of bytes rather than number of :ref:`mjtNum` |-| s. diff --git a/doc/includes/references.h b/doc/includes/references.h index e4b932b8..2c3ba4d3 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -2233,7 +2233,7 @@ void mj_resetDataDebug(const mjModel* m, mjData* d, unsigned char debug_value); void mj_resetDataKeyframe(const mjModel* m, mjData* d, int key); void mj_markStack(mjData* d); void mj_freeStack(mjData* d); -void* mj_stackAlloc(mjData* d, size_t bytes, size_t alignment); +void* mj_stackAllocByte(mjData* d, size_t bytes, size_t alignment); mjtNum* mj_stackAllocNum(mjData* d, int size); int* mj_stackAllocInt(mjData* d, int size); void mj_deleteData(mjData* d); diff --git a/doc/programming/simulation.rst b/doc/programming/simulation.rst index b63ab55b..6ff67094 100644 --- a/doc/programming/simulation.rst +++ b/doc/programming/simulation.rst @@ -721,7 +721,7 @@ The function :ref:`mj_stackAllocNum` checks if there is enough space, and if so otherwise it triggers an error. It also keeps track of the maximum stack allocation; see :ref:`diagnostics ` below. Note that :ref:`mj_stackAllocNum` is only used for allocating ``mjtNum`` arrays, the most common type of array. :ref:`mj_stackAllocInt` is provided for integer array allocation, -and :ref:`mj_stackAlloc` is provided for allocation of arbitrary number of bytes and alignment. +and :ref:`mj_stackAllocByte` is provided for allocation of arbitrary number of bytes and alignment. .. _siError: diff --git a/include/mujoco/mujoco.h b/include/mujoco/mujoco.h index c7964c73..26bf0567 100644 --- a/include/mujoco/mujoco.h +++ b/include/mujoco/mujoco.h @@ -194,7 +194,7 @@ MJAPI void mj_freeStack(mjData* d); // Allocate a number of bytes on mjData stack at a specific alignment. // Call mju_error on stack overflow. -MJAPI void* mj_stackAlloc(mjData* d, size_t bytes, size_t alignment); +MJAPI void* mj_stackAllocByte(mjData* d, size_t bytes, size_t alignment); // Allocate array of mjtNums on mjData stack. Call mju_error on stack overflow. MJAPI mjtNum* mj_stackAllocNum(mjData* d, int size); diff --git a/introspect/functions.py b/introspect/functions.py index a27e95db..69b74de7 100644 --- a/introspect/functions.py +++ b/introspect/functions.py @@ -705,9 +705,9 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([ ), doc='Free the current mjData stack frame. All pointers returned by mj_stackAlloc since the last call to mj_markStack must no longer be used afterwards.', # pylint: disable=line-too-long )), - ('mj_stackAlloc', + ('mj_stackAllocByte', FunctionDecl( - name='mj_stackAlloc', + name='mj_stackAllocByte', return_type=PointerType( inner_type=ValueType(name='void'), ), diff --git a/python/mujoco/functions.cc b/python/mujoco/functions.cc index d1e00d9b..768b2568 100644 --- a/python/mujoco/functions.cc +++ b/python/mujoco/functions.cc @@ -126,7 +126,7 @@ PYBIND11_MODULE(_functions, pymodule) { Def(pymodule); Def(pymodule); Def(pymodule); - // Skipped: mj_stackAlloc (doesn't make sense in Python) + // Skipped: mj_stackAllocByte (doesn't make sense in Python) // Skipped: mj_deleteData (have MjData.__del__) Def(pymodule); Def(pymodule); @@ -1356,7 +1356,7 @@ PYBIND11_MODULE(_functions, pymodule) { data->ncon = ncon; data->nefc = nefc; data->contact = - static_cast(InterceptMjErrors(::mj_arenaAlloc)( + static_cast(InterceptMjErrors(::mj_arenaAllocByte)( data, ncon * sizeof(raw::MjContact), alignof(raw::MjContact))); if (!data->contact) { cleanup(data); @@ -1367,12 +1367,12 @@ PYBIND11_MODULE(_functions, pymodule) { #define MJ_M(x) d.metadata().x #undef MJ_D #define MJ_D(x) data->x -#define X(type, name, nr, nc) \ - data->name = static_cast(InterceptMjErrors(::mj_arenaAlloc)( \ - data, sizeof(type) * (nr) * (nc), alignof(type))); \ - if (!data->name) { \ - cleanup(data); \ - throw FatalError("insufficient arena memory available"); \ +#define X(type, name, nr, nc) \ + data->name = static_cast(InterceptMjErrors(::mj_arenaAllocByte)( \ + data, sizeof(type) * (nr) * (nc), alignof(type))); \ + if (!data->name) { \ + cleanup(data); \ + throw FatalError("insufficient arena memory available"); \ } MJDATA_ARENA_POINTERS_PRIMAL diff --git a/python/mujoco/private.h b/python/mujoco/private.h index abaad3a0..13a71b61 100644 --- a/python/mujoco/private.h +++ b/python/mujoco/private.h @@ -22,7 +22,7 @@ // They should be regarded as part of MuJoCo's internal implementation detail. extern "C" { MJAPI void _mjPRIVATE__set_tls_error_fn(void (*h)(const char*)); -MJAPI void* mj_arenaAlloc(mjData* d, int bytes, int alignment); +MJAPI void* mj_arenaAllocByte(mjData* d, int bytes, int alignment); } #endif // MUJOCO_PYTHON_PRIVATE_H_ diff --git a/python/mujoco/structs.cc b/python/mujoco/structs.cc index 94eb8c3a..6c54f3b5 100644 --- a/python/mujoco/structs.cc +++ b/python/mujoco/structs.cc @@ -820,11 +820,11 @@ MjDataWrapper MjDataWrapper::Deserialize(std::istream& input) { #define MJ_M(x) m.x #undef MJ_D #define MJ_D(x) d->x -#define X(type, name, nr, nc) \ - if ((nr) * (nc)) { \ - d->name = static_castname)>( \ - mj_arenaAlloc(d, sizeof(type) * (nr) * (nc), alignof(type))); \ - ReadBytes(input, d->name, sizeof(type) * (nr) * (nc)); \ +#define X(type, name, nr, nc) \ + if ((nr) * (nc)) { \ + d->name = static_castname)>( \ + mj_arenaAllocByte(d, sizeof(type) * (nr) * (nc), alignof(type))); \ + ReadBytes(input, d->name, sizeof(type) * (nr) * (nc)); \ } MJDATA_ARENA_POINTERS_CONTACT diff --git a/src/engine/engine_collision_driver.c b/src/engine/engine_collision_driver.c index 3a887c7f..bc5d787c 100644 --- a/src/engine/engine_collision_driver.c +++ b/src/engine/engine_collision_driver.c @@ -223,7 +223,7 @@ int mj_collideOBB(const mjtNum aabb1[6], const mjtNum aabb2[6], } static mjCollisionTree* mj_stackAllocTree(mjData* d, int max_stack) { - return (mjCollisionTree*) mj_stackAlloc( + return (mjCollisionTree*) mj_stackAllocByte( d, max_stack * sizeof(mjCollisionTree), _Alignof(mjCollisionTree)); } @@ -770,9 +770,9 @@ int mj_broadphase(const mjModel* m, mjData* d, int* pair, int maxpair) { } // allocate sort buffer - sortbuf = (mjtBroadphase*) mj_stackAlloc( + sortbuf = (mjtBroadphase*) mj_stackAllocByte( d, 2 * bufcnt * sizeof(mjtBroadphase), _Alignof(mjtBroadphase)); - activebuf = (mjtBroadphase*) mj_stackAlloc( + activebuf = (mjtBroadphase*) mj_stackAllocByte( d, 2 * bufcnt * sizeof(mjtBroadphase), _Alignof(mjtBroadphase)); // init sortbuf with axis0 @@ -955,7 +955,7 @@ static void collideGeoms(const mjModel* m, mjData* d, // allocate mjContact[mjMAXCONPAIR] on the arena mjContact* con = - (mjContact*) mj_arenaAlloc(d, sizeof(mjContact) * mjMAXCONPAIR, _Alignof(mjContact)); + (mjContact*) mj_arenaAllocByte(d, sizeof(mjContact) * mjMAXCONPAIR, _Alignof(mjContact)); if (!con) { mj_warning(d, mjWARN_CONTACTFULL, d->ncon); return; diff --git a/src/engine/engine_collision_sdf.c b/src/engine/engine_collision_sdf.c index bdf16679..4e17eebb 100644 --- a/src/engine/engine_collision_sdf.c +++ b/src/engine/engine_collision_sdf.c @@ -459,7 +459,7 @@ static void collideBVH(const mjModel* m, mjData* d, int g, int node; }; typedef struct CollideTreeArgs_ CollideTreeArgs; - CollideTreeArgs* stack = (CollideTreeArgs*) mj_stackAlloc( + CollideTreeArgs* stack = (CollideTreeArgs*) mj_stackAllocByte( d, max_stack * sizeof(CollideTreeArgs), _Alignof(CollideTreeArgs)); int nstack = 0; diff --git a/src/engine/engine_core_constraint.c b/src/engine/engine_core_constraint.c index 1ffe5b99..4d8bfa61 100644 --- a/src/engine/engine_core_constraint.c +++ b/src/engine/engine_core_constraint.c @@ -61,13 +61,13 @@ static int arenaAllocEfc(const mjModel* m, mjData* d) { (char*)d->arena + d->parena, d->narena - d->pstack - d->parena); #endif -#define X(type, name, nr, nc) \ - d->name = mj_arenaAlloc(d, sizeof(type) * (nr) * (nc), _Alignof(type)); \ - if (!d->name) { \ - mj_warning(d, mjWARN_CNSTRFULL, d->narena); \ - mj_clearEfc(d); \ - d->parena = d->ncon * sizeof(mjContact); \ - return 0; \ +#define X(type, name, nr, nc) \ + d->name = mj_arenaAllocByte(d, sizeof(type) * (nr) * (nc), _Alignof(type)); \ + if (!d->name) { \ + mj_warning(d, mjWARN_CNSTRFULL, d->narena); \ + mj_clearEfc(d); \ + d->parena = d->ncon * sizeof(mjContact); \ + return 0; \ } MJDATA_ARENA_POINTERS_PRIMAL @@ -171,7 +171,7 @@ int mj_addContact(const mjModel* m, mjData* d, const mjContact* con) { mj_clearEfc(d); // copy contact - mjContact* dst = mj_arenaAlloc(d, sizeof(mjContact), _Alignof(mjContact)); + mjContact* dst = mj_arenaAllocByte(d, sizeof(mjContact), _Alignof(mjContact)); if (!dst) { mj_warning(d, mjWARN_CONTACTFULL, d->ncon); return 1; diff --git a/src/engine/engine_io.c b/src/engine/engine_io.c index b27815ae..7ce8cafe 100644 --- a/src/engine/engine_io.c +++ b/src/engine/engine_io.c @@ -1217,7 +1217,7 @@ mjData* mj_copyData(mjData* dest, const mjModel* m, const mjData* src) { // allocate memory from the mjData arena -void* mj_arenaAlloc(mjData* d, size_t bytes, size_t alignment) { +void* mj_arenaAllocByte(mjData* d, size_t bytes, size_t alignment) { size_t misalignment = fastmod(d->parena, alignment); size_t padding = misalignment ? alignment - misalignment : 0; @@ -1374,7 +1374,7 @@ void mj_freeStack(mjData* d) { #endif } -void* mj_stackAlloc(mjData* d, size_t bytes, size_t alignment) { +void* mj_stackAllocByte(mjData* d, size_t bytes, size_t alignment) { return stackalloc(d, bytes, alignment); } diff --git a/src/engine/engine_io.h b/src/engine/engine_io.h index b0595747..3fcf695f 100644 --- a/src/engine/engine_io.h +++ b/src/engine/engine_io.h @@ -104,7 +104,7 @@ MJAPI void mj_resetDataDebug(const mjModel* m, mjData* d, unsigned char debug_va MJAPI void mj_resetDataKeyframe(const mjModel* m, mjData* d, int key); // mjData arena allocate -MJAPI void* mj_arenaAlloc(mjData* d, size_t bytes, size_t alignment); +MJAPI void* mj_arenaAllocByte(mjData* d, size_t bytes, size_t alignment); // mjData mark stack frame MJAPI void mj_markStack(mjData* d); @@ -113,7 +113,7 @@ MJAPI void mj_markStack(mjData* d); MJAPI void mj_freeStack(mjData* d); // mjData stack allocate -MJAPI void* mj_stackAlloc(mjData* d, size_t bytes, size_t alignment); +MJAPI void* mj_stackAllocByte(mjData* d, size_t bytes, size_t alignment); // mjData stack allocate for array of mjtNums MJAPI mjtNum* mj_stackAllocNum(mjData* d, int size); diff --git a/src/engine/engine_island.c b/src/engine/engine_island.c index c7bba3b9..827bd88d 100644 --- a/src/engine/engine_island.c +++ b/src/engine/engine_island.c @@ -113,12 +113,12 @@ static int arenaAllocIsland(const mjModel* m, mjData* d) { size_t parena_old = d->parena; -#define X(type, name, nr, nc) \ - d->name = mj_arenaAlloc(d, sizeof(type) * (nr) * (nc), _Alignof(type)); \ - if (!d->name) { \ - mj_warning(d, mjWARN_CNSTRFULL, d->narena); \ - clearIsland(d, parena_old); \ - return 0; \ +#define X(type, name, nr, nc) \ + d->name = mj_arenaAllocByte(d, sizeof(type) * (nr) * (nc), _Alignof(type)); \ + if (!d->name) { \ + mj_warning(d, mjWARN_CNSTRFULL, d->narena); \ + clearIsland(d, parena_old); \ + return 0; \ } MJDATA_ARENA_POINTERS_ISLAND diff --git a/src/engine/engine_util_container.c b/src/engine/engine_util_container.c index a14a717d..f3daab8c 100644 --- a/src/engine/engine_util_container.c +++ b/src/engine/engine_util_container.c @@ -24,7 +24,7 @@ // stack allocate and initialize new mjArrayList mjArrayList* mju_arrayListCreate(mjData* d, size_t element_size, size_t initial_capacity) { - mjArrayList* array_list = (mjArrayList*) mj_stackAlloc( + mjArrayList* array_list = (mjArrayList*) mj_stackAllocByte( d, sizeof(mjArrayList), _Alignof(mjArrayList)); initial_capacity = mjMAX(1, initial_capacity); array_list->d = d; @@ -34,7 +34,7 @@ mjArrayList* mju_arrayListCreate(mjData* d, size_t element_size, size_t initial_ array_list->next_segment = NULL; // allocate array list buffer - array_list->buffer = (void*) mj_stackAlloc( + array_list->buffer = (void*) mj_stackAllocByte( d, element_size * initial_capacity, _Alignof(mjtMaxAlign)); return array_list; } diff --git a/test/engine/engine_io_test.cc b/test/engine/engine_io_test.cc index b9f723cb..4c6443a4 100644 --- a/test/engine/engine_io_test.cc +++ b/test/engine/engine_io_test.cc @@ -830,8 +830,8 @@ TEST_F(EngineIoTest, RedZoneAlignmentTest) { ASSERT_THAT(data, NotNull()); mj_markStack(data); - mj_stackAlloc(data, 1, 1); - mj_stackAlloc(data, 1, 1); + mj_stackAllocByte(data, 1, 1); + mj_stackAllocByte(data, 1, 1); mj_freeStack(data); mj_deleteData(data); diff --git a/unity/Runtime/Bindings/MjBindings.cs b/unity/Runtime/Bindings/MjBindings.cs index 7984df84..fddc661e 100644 --- a/unity/Runtime/Bindings/MjBindings.cs +++ b/unity/Runtime/Bindings/MjBindings.cs @@ -6110,7 +6110,7 @@ public static unsafe extern void mj_markStack(mjData_* d); public static unsafe extern void mj_freeStack(mjData_* d); [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] -public static unsafe extern void* mj_stackAlloc(mjData_* d, UIntPtr bytes, UIntPtr alignment); +public static unsafe extern void* mj_stackAllocByte(mjData_* d, UIntPtr bytes, UIntPtr alignment); [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] public static unsafe extern double* mj_stackAllocNum(mjData_* d, int size); From 9cf1f6eba42516bee1a051d193d7f511e3bce932 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Mon, 18 Sep 2023 15:14:33 -0700 Subject: [PATCH 05/89] Remove `mjOption.collision` and associated `option/collision` attribute. PiperOrigin-RevId: 566427090 Change-Id: I6e5873b8db707586820b17b53c7ab4bbff0f0b2b --- doc/APIreference/APItypes.rst | 12 -- doc/XMLreference.rst | 8 - doc/XMLschema.rst | 6 +- doc/changelog.rst | 33 ++-- doc/computation.rst | 27 ++-- doc/includes/references.h | 6 - include/mujoco/mjmodel.h | 8 - include/mujoco/mjxmacro.h | 1 - introspect/enums.py | 10 -- introspect/structs.py | 5 - simulate/simulate.cc | 2 - src/engine/engine_collision_driver.c | 157 +++++++++----------- src/engine/engine_io.c | 1 - src/xml/xml_native_reader.cc | 15 +- src/xml/xml_native_writer.cc | 2 - test/engine/engine_collision_driver_test.cc | 16 -- test/header_test.cc | 1 - unity/Runtime/Bindings/MjBindings.cs | 6 - 18 files changed, 108 insertions(+), 208 deletions(-) diff --git a/doc/APIreference/APItypes.rst b/doc/APIreference/APItypes.rst index 2fd10428..706a6e28 100644 --- a/doc/APIreference/APItypes.rst +++ b/doc/APIreference/APItypes.rst @@ -174,18 +174,6 @@ Numerical integrator types. These values are used in ``m->opt.integrator``. .. mujoco-include:: mjtIntegrator - -.. _mjtCollision: - -mjtCollision -~~~~~~~~~~~~ - -Collision modes specifying how candidate geom pairs are generated for near-phase collision checking. These values are -used in ``m->opt.collision``. - -.. mujoco-include:: mjtCollision - - .. _mjtCone: mjtCone diff --git a/doc/XMLreference.rst b/doc/XMLreference.rst index 0de9e1c3..aff1d69a 100644 --- a/doc/XMLreference.rst +++ b/doc/XMLreference.rst @@ -1931,14 +1931,6 @@ adjust it properly through the XML. Implicit-in-velocity Euler method, and :at:`implicitfast`, which drops the Coriolis and centrifugal terms. See :ref:`Numerical Integration` for more details. -.. _option-collision: - -:at:`collision`: :at-val:`[all, predefined, dynamic], "all"` - This attribute specifies which geom pairs should be checked for collision; recall :ref:`Collision` in the Computation - chapter. "predefined" means that only the explicitly-defined contact :ref:`pairs ` are checked. - "dynamic" means that only the contact pairs generated dynamically are checked. "all" means that the contact pairs - from both sources are checked. - .. _option-cone: :at:`cone`: :at-val:`[pyramidal, elliptic], "pyramidal"` diff --git a/doc/XMLschema.rst b/doc/XMLschema.rst index 2a890c51..0bdc4640 100644 --- a/doc/XMLschema.rst +++ b/doc/XMLschema.rst @@ -224,11 +224,11 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | | | | | :ref:`o_margin` | :ref:`o_solref` | :ref:`o_solimp` | :ref:`integrator` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`collision` | :ref:`cone` | :ref:`jacobian` | :ref:`solver` | | +| | | | :ref:`cone` | :ref:`jacobian` | :ref:`solver` | :ref:`iterations` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`iterations` | :ref:`ls_iterations` | :ref:`noslip_iterations` | :ref:`mpr_iterations` | | +| | | | :ref:`ls_iterations` | :ref:`noslip_iterations` | :ref:`mpr_iterations` | :ref:`sdf_iterations` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`sdf_iterations` | :ref:`sdf_initpoints` | | | | +| | | | :ref:`sdf_initpoints` | | | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| option |br| |_| |L| | | .. table:: | diff --git a/doc/changelog.rst b/doc/changelog.rst index 1945d26d..20e8110c 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -62,35 +62,46 @@ General - Renamed ``mjData.solver_iter`` to ``solver_niter``. Both this member and ``mjData.solver_nnz`` are now integer vectors of length ``mjNISLAND``. -8. Added a new :ref:`dyntype`, ``filterexact``, which updates first-order filter states with + 8. Removed ``mjOption.collision`` and the associated ``option/collision`` attribute. + + **Migration:** + + - For models which have ``