Commit Graph

1095 Commits

Author SHA1 Message Date
Yuval Tassa cedaa47d61 Migrate tests to use MockWarningHandler for warning interception.
PiperOrigin-RevId: 933656759
Change-Id: Ia21514c302799034bf598445933dd90427284737
2026-06-17 05:06:57 -07:00
Yuval Tassa 410c73168c Add policies for global attribute conflict resolution upon attach
For example when loading parent_merge.xml:

```
WARNING: Attach conflict when attaching 'child' to 'parent_merge', policy is 'merge'
timestep: parent has 0.005, child has 0.002, taking the minimum
iterations: parent has 50, child has 100, taking the maximum
flag 'Damper': added from child
```

When loading parent_error.xml:

```
XML Error: Attach conflict when attaching 'child' to 'parent_error', policy is 'error'
timestep: parent has 0.005, child has 0.002
iterations: parent has 50, child has 100
Element 'attach', line 10
```
PiperOrigin-RevId: 933620810
Change-Id: Ib477863b5ef763474d27fb4be5a4148be1d5d500
2026-06-17 03:36:10 -07:00
Kyle Bayes 386b45fb75 Add tolerance to upper > lower bound check on first iteration of EPA.
PiperOrigin-RevId: 933615381
Change-Id: I175d3b97fa65f71a8f1cc34da5f6b9a23ab856d2
2026-06-17 03:19:19 -07:00
Yuval Tassa 6f8bb5ef55 Refactor compiler warning handling.
Compiler warnings are now accumulated in a vector of strings within the mjSpec object. New API functions `mjs_numWarnings` and `mjs_getWarning` are added to access these warnings. The compiler's log handler now chains warnings to the global log handler, ensuring they are still displayed immediately. Call sites in `mj_loadXML`, `mj_compile`, and the Python and WASM bindings have been updated to use the new warning API.

PiperOrigin-RevId: 933361650
Change-Id: I47cab98a460c57b0898c0a1a43fce2a5b9648eb1
2026-06-16 16:28:33 -07:00
Yuval Tassa 67a1ea6dca Track authored flags for global attributes
PiperOrigin-RevId: 931585539
Change-Id: Ifdc8c59de6c5a553daf6e0af09d8192aff6b0610
2026-06-13 02:58:32 -07:00
Yuval Tassa 8d42473ed0 Fix GCC -Wstringop-truncation in test fixture
Widen err_msg buffer in MjuErrorMessageFrom to 2048 and use snprintf
instead of strncpy to avoid truncation warnings.

PiperOrigin-RevId: 930932293
Change-Id: Iea43d28cf209356d66cf16be48e750e947242b14
2026-06-11 22:25:12 -07:00
Yuval Tassa 58f6d52491 Introduce new logging API, fixes #858
PiperOrigin-RevId: 930744288
Change-Id: I6ec1203b55c031390f3eef23192e2337508ce886
2026-06-11 14:36:57 -07:00
Kyle Bayes 6957966c7d Terminate early without contact in EPA if upper < lower on first iteration.
PiperOrigin-RevId: 929828707
Change-Id: Ide1106c14ae6eb003a9bbc238609b4bfdde221b0
2026-06-10 07:02:00 -07:00
Kyle Bayes 2c5b8cae6c Correct projected origin on face when the magnitude of face->v becomes very small in EPA.
PiperOrigin-RevId: 929768876
Change-Id: I5daf0203e998aa1489d9ce4c78cbf0764a8963e3
2026-06-10 04:48:18 -07:00
Adrian Collister 6f0246baf3 Add test for Flex contact and touch sensors.
The test verifies that contact sensors on subtrees and touch sensors on sites correctly register contacts involving Flex components.

PiperOrigin-RevId: 929109418
Change-Id: I1865311a6da838d75ef33989ac7f3c2d975cdbff
2026-06-09 04:29:40 -07:00
Yuval Tassa e349ea5834 Remove MJAPI from templated function declaration.
PiperOrigin-RevId: 928849785
Change-Id: I35ba63f599ba12a5d2bdb0d694240e39ca7d4174
2026-06-08 17:08:17 -07:00
Yuval Tassa 986d73c062 Fix non-unit normals in mesh convex hull compiler.
PiperOrigin-RevId: 928777934
Change-Id: I43d7adcf4c5781b57f0af9805a8ce01ebc2e3872
2026-06-08 14:40:11 -07:00
Alessio Quaglino 7a7dc7ccad Add support for loading 1D flex components from OBJ line segments.
The obj_decoder plugin is updated to parse line segments ('l') from OBJ files and represent them as degenerate triangles. The user_flexcomp compiler now supports flex dimensions of 1, using these parsed line segments to define the 1D flex elements. The compile sample's error reporting is also improved.

PiperOrigin-RevId: 928566870
Change-Id: I6920729d1b1d5aeb391401c3245ebb1d4784c190
2026-06-08 08:03:30 -07:00
Kyle Bayes ac7f198536 Tune constants for nativeccd to perform better with single precision.
PiperOrigin-RevId: 928549147
Change-Id: Ic28c60f73e92bb1b9578c56f790b6cda94875907
2026-06-08 07:21:17 -07:00
Yuval Tassa 6c33e16bf1 Canonicalize mjVisual macros to include type and dimension.
PiperOrigin-RevId: 928506110
Change-Id: If5d031f9d87892f13486ae9ccde23c16131212de
2026-06-08 05:30:57 -07:00
Yuval Tassa d80a847bae Move CompareModel to a separate library.
PiperOrigin-RevId: 927174846
Change-Id: Ia8b8b2c8593133d8910399be755e614282bf3252
2026-06-05 02:44:53 -07:00
Yuval Tassa 5ce9a0ad0b Split large parameterized tests into dedicated files.
PiperOrigin-RevId: 927159897
Change-Id: Ib0e11727c49195bc03d190b736c01b14c10268fe
2026-06-05 02:07:47 -07:00
Kyle Bayes 66156c7d9a Update tolerances on engine_collision_gjk_test.cc to run with single precision.
PiperOrigin-RevId: 926681633
Change-Id: I14f7b756fd3cf7b8f797b5f7b917efba00006b88
2026-06-04 07:37:15 -07:00
Kyle Bayes 558366f364 Always normalize in planeNormal to reduce rounding errors in single precision.
PiperOrigin-RevId: 926002329
Change-Id: I682f3b90249e60838c2432231b3181e57c565c28
2026-06-03 07:04:12 -07:00
Yuval Tassa 7b9b88060e Refactor mj_fullM. This change is part of the deprecation of mjData.qM.
PiperOrigin-RevId: 925669464
Change-Id: I4889c66591bc1df4c31135a13776052aad491f7a
2026-06-02 17:22:55 -07:00
Copybara-Service 15cbc8fb55 Merge pull request #3156 from andrewkaufman:newton-schemas
PiperOrigin-RevId: 925328794
Change-Id: If45b8659ea9b88785660331bca5ee837ac172f67
2026-06-02 07:06:59 -07:00
Yuval Tassa 062b0f1ea6 Remove deprecated mju_{error,warning}_{i,s} functions.
PiperOrigin-RevId: 925204136
Change-Id: Ia877d08a135092db8037d04e6a237e81325a1d7c
2026-06-02 01:59:05 -07:00
Kyle Bayes ad23db5942 Guard againsts NaNs in engine_collision_gjk_test.cc.
PiperOrigin-RevId: 924844839
Change-Id: I98d5acd8ee97881ebd17f7ba7a40fb378ca1fb2d
2026-06-01 12:17:42 -07:00
Alessio Quaglino 91c92279d2 Enable interior nodes for interpolated flex shell mode.
Previously shell mode required cellcount=1 along at least one axis. This CL
adds support for cellcount > 1 in all three axes by pinning interior grid nodes
to the parent body and reconstructing their positions from boundary nodes via
Transfinite Interpolation (TFI).

PiperOrigin-RevId: 924314800
Change-Id: I8c2438f4866dd4133feed65f535a1ab69f0c9188
2026-05-31 10:36:01 -07:00
Yuval Tassa 4548e81e4d Rename efc_diagApprox -> efc_diagA.
The field now stores either an approximate or exact diagonal of the constraint matrix A, so the name is made more general.

PiperOrigin-RevId: 924244954
Change-Id: I62b2f76531fb88b7b3bf96e6769940197596702b
2026-05-31 04:54:11 -07:00
Yuval Tassa cd6db9ebe2 Improve CG solver precision and stability under float32 via line search refactor
Fixes #2313

This CL combines two complementary improvements to the Conjugate Gradient (CG) solver, significantly improving numerical precision, stability, and efficiency, particularly in single precision (float32).

1. Line Search Cost Evaluation Refactor: Previously, solver improvement was calculated by subtracting absolute costs: cost(alpha) - cost(0). In highly converged states or single precision, this is susceptible to catastrophic cancellation. We refactor PrimalSearch to compute the cost delta directly, dramatically improving precision.

2. Improved Solver Termination Condition: Near the float32 precision limit, line search deltas can occasionally be slightly negative due to numerical noise. Previously, any value below m->opt.tolerance (including negative values) triggered termination, halting the solver and locking in destabilizing steps. We update the termination condition to require positive improvement (0 < improvement < m->opt.tolerance), allowing the solver to continue iterating and recover stability.

Together, these changes yield substantial improvements, see reduced tolerances herein.

PiperOrigin-RevId: 924229669
Change-Id: Ic0bbefaed090f3a8b1e79ab8d45422c3e86fb56c
2026-05-31 04:00:09 -07:00
Yuval Tassa 4358a102cd Add manual test for CG converence
Also add MJTOL_SCALE to fixture to allow tests to be run with zero tolerance. This is useful when assesing the impact of code changes (A/B comparison of failure values)

PiperOrigin-RevId: 924219083
Change-Id: Ifdd09ac850904ca8dd79179930ce738a4b37d284
2026-05-31 03:15:54 -07:00
Yuval Tassa 96bf8aea81 Move island-specific sparse matrices from arena to stack.
PiperOrigin-RevId: 923850345
Change-Id: I9683d7554b15b7cd8c45a8dce7814640aa266452
2026-05-30 03:09:46 -07:00
Copybara-Service 9af965f241 Merge pull request #3120 from Ashutosh0x:fix/safe-overflow-msvc
PiperOrigin-RevId: 923296001
Change-Id: I037dcc55c91d6eb68b3e63b34a0e059c796b5116
2026-05-29 03:12:40 -07:00
Kyle Bayes b935d4153c Add new mju_threadpool API function, and delete old threading API.
PiperOrigin-RevId: 922838541
Change-Id: Id9f7e0fb298ffde61fcc49a802dc78971858ce51
2026-05-28 10:11:44 -07:00
Ashutosh0x 50ec8e84de test: intercept mju_warning in overflow regression test 2026-05-28 21:46:15 +05:30
Copybara-Service f755d718d3 Merge pull request #3293 from kevinzakka:studio-live-parallel-prefetch
PiperOrigin-RevId: 922417778
Change-Id: Ia839747c4af0e705962308dc84e9a7c3926fc910
2026-05-27 16:47:18 -07:00
Kyle Bayes 4035c66428 Fix multiccd edge bug that occurs in certain situations.
PiperOrigin-RevId: 922251109
Change-Id: I74c08ae49d5dfd2a41b2dcd28eb9f2b5ba113216
2026-05-27 11:32:45 -07:00
Google DeepMind af4be63cd8 Add xmacros for MjSpec.
PiperOrigin-RevId: 922169069
Change-Id: I01426596e49196996dfa324d5ab3849a90de2e3a
2026-05-27 09:12:35 -07:00
Ashutosh0x 0607dc450c security: fix integer overflow in safeAddToBufferSize on MSVC
The MSVC fallback path in safeAddToBufferSize() performed unchecked
arithmetic (type_size*nr*nc) on attacker-controlled values read from
.mjb binary model files. This could cause integer overflow, leading
to an undersized heap allocation followed by a heap buffer overflow
when data is copied into the buffer.

The fix adds manual overflow detection using SIZE_MAX/INTPTR_MAX
comparisons, matching the behavior of the existing __builtin_*_overflow
path used on GCC/Clang.

Also adds a regression test that crafts a binary model buffer with
overflow-inducing size fields and asserts safe rejection.
2026-05-27 17:01:01 +05:30
Alessio Quaglino f6cd0234fd Change tactile sensor normal component to report penetration depth.
The normal component of the tactile sensor now reports the maximum penetration depth at each taxel, instead of a derived normal force. The depth is negated so that positive values indicate penetration.

PiperOrigin-RevId: 921980899
Change-Id: Ide4103c0aff465e25a81cfdda650f6a0e2da9e0b
2026-05-27 02:00:34 -07:00
Kevin Zakka 6f9725a1da Make mju_getXMLDependencies read XMLs through the resource provider.
The function called tinyxml2's LoadFile directly, which only works on
the OS file system. Reading through mju_openResource lets it work
against any registered backend (VFS, HTTP, github:, ...).
2026-05-26 16:01:48 -07:00
Yuval Tassa 393c1e4217 Migrate mjtByte to mjtBool for boolean-valued fields.
PiperOrigin-RevId: 921408093
Change-Id: Icb00457836359779f0f72fc02d6a7c0dc9f6bd23
2026-05-26 05:35:49 -07:00
Yuval Tassa 15d27b363f Compile-time size assertions for MuJoCo basic types
PiperOrigin-RevId: 919107499
Change-Id: I07fcba4f33c77a2a1e68528dba6d399af94d0220
2026-05-21 09:55:04 -07:00
Yuval Tassa 2810edd27a Rename mjtnum.h to mjtype.h, move enum types to mjtype.h
PiperOrigin-RevId: 919020039
Change-Id: I441295c0baa0b7456f78239fbd5478d32ffc07c1
2026-05-21 06:43:29 -07:00
Kyle Bayes 7174d33f08 Introduce mjPreContact, a minimal struct passed into the collision functions.
PiperOrigin-RevId: 918533795
Change-Id: I2b5af05c1479b25d5c2cfdc690321a26fce6ede6
2026-05-20 10:47:46 -07:00
Sam Haves fa8ac7a516 Implement mjz encoder.
PiperOrigin-RevId: 918493808
Change-Id: I150d182ff27801d829537a8001a0b3a04c1a0499
2026-05-20 09:32:51 -07:00
Yuval Tassa bdf00966f9 Add compiler timing diagnostics to mjsCompiler, printed by compile.cc
For example, `compile mujoco_menagerie/robotis_op3/scene.xml` now outputs

```
Compile 1 (cold cache):
  total:      317.2 ms
  assets:     284.8 ms (wall clock)
    load:     616.1 ms
    hull:      26.4 ms
    poly:     137.8 ms
    inert:    177.8 ms
    bvh:      568.2 ms
    octr:       1.6 ms
    tex:       25.3 ms
  other:       32.4 ms

Compile 2 (warm cache):
  total:       79.9 ms
  assets:      54.5 ms (wall clock)
    load:     888.5 ms
    hull:       0.0 ms
    poly:       0.0 ms
    inert:      0.0 ms
    bvh:        0.0 ms
    octr:       0.0 ms
    tex:       21.4 ms
  other:       25.3 ms
```

PiperOrigin-RevId: 917850214
Change-Id: Iaec86230bec0faf2e47820e20cbff61de5b2621e
2026-05-19 08:28:47 -07:00
Yuval Tassa f712eed4ce Allow flex sleeping
PiperOrigin-RevId: 917817500
Change-Id: Ia3bd5e52e7c2eaa3f70c81352d82c130b1d357f6
2026-05-19 07:15:27 -07:00
Copybara-Service a1056676a0 Merge pull request #3276 from dparikh79:fix/3275-boxqp-symmetric-lower-matvec
PiperOrigin-RevId: 917279467
Change-Id: If4117b1e2147679336becb558e0f87621555dfc7
2026-05-18 09:36:01 -07:00
Yuval Tassa 71d1014e70 Add mjENBL_DIAGEXACT for exact constraint diagonal. Fixes #2472
PiperOrigin-RevId: 916932908
Change-Id: Id23ac39b5cd996afc52990719a4e07c0cc7de600
2026-05-17 16:47:54 -07:00
Alessio Quaglino 8a20ce24d3 Refactor shell stiffness computation to use pure membrane modes plus an explicit warp mode.
PiperOrigin-RevId: 916879634
Change-Id: Ib706909521b4f503b13904a34b0e29aefd4fa433
2026-05-17 13:00:08 -07:00
Yuval Tassa a897805683 Improve test comparing forward and inverse dynamics mismatch
PiperOrigin-RevId: 916864072
Change-Id: I9952c7dd1bde2033dfe1380552f2c4b6b7344b26
2026-05-17 12:03:20 -07:00
Dhruvil 71072c025d Honor lower-triangle contract for H in mju_boxQP.
mju_boxQP documents that only the lower triangle of the Hessian H is
read, but the gradient and search-direction updates inside
mju_boxQPoption still called the dense mju_mulMatVec, which reads the
upper triangle as well. This violated the documented contract and
prevented callers from safely leaving the upper triangle uninitialized.

Add a file-local mulMatVecSym helper that computes res = H*vec while
reading only the lower triangle of H (mirroring the convention of the
existing mulVecMatVecSym quadratic-form helper), and use it in place of
mju_mulMatVec in both call sites. Extend the BoxQP test suite with
UpperTrianglePoisoned, which fills the strict upper triangle of H with
NaN and verifies that the solver produces the same result as on the
clean symmetric input.

Reported by @lshdlut.

Fixes #3275
2026-05-17 13:56:53 -04:00
Kyle Bayes a0c4c62654 Update thread_performance_test.cc.
PiperOrigin-RevId: 916025277
Change-Id: Icc000e5f81b79e0239359638d0eabc3e2ecd00e6
2026-05-15 08:47:48 -07:00