Commit Graph

160 Commits

Author SHA1 Message Date
Yuval Tassa 63fd23a934 Remove mjTIMER_ACCELERATION, add mjTIMER_ADVANCE.
- mjTIMER_ACCELERATION is not very useful, it's usually very tiny (0.5% for humanoid, 1% for 22humanoids). It basically times a single call to `mj_solveM`.

- Added `mjTIMER_ADVANCE` to time `mj_Euler` and `mj_implicit` (which can be significant).

- Moved `mj_transmission` to `mjTIMER_KINEMATICS` where it belongs (and used to be).

PiperOrigin-RevId: 565936880
Change-Id: I26b8a067133594e5500ca1c809beb3518b4a8d9c
2023-09-16 08:03:45 -07:00
Yuval Tassa 86d8b912f4 Rejigged solver statistics in preparation for islanding.
- See public description below.
- Stopped incrementing the iteration count in saveStats().
- `sizeof(mjSolverStat) == 40`, so this ends up costing 160KB, up from 40KB.

BEGIN_PUBLIC

Changed the size of `mjData.solver`, the structure used to collect solver diagnostic information. The array is now of length `mjNISLAND * mjNSOLVER`, where each row of length `mjNSOLVER` contains separate solver statistics for each constraint island. Until solver islanding is implemented, only row 0 is used.

- The new constant `mjNISLAND` is set to 20.
- `mjNSOLVER` is reduced from 1000 to 200.
- Added `mjData.solver_nisland`, the number of islands for which the solver ran.
- `mjData.solver_niter` (renamed from mjData.solver_iter) and `mjData.solver_nnz` are now integer vectors of length `mjNISLAND`.

END_PUBLIC

PiperOrigin-RevId: 565030093
Change-Id: I773e918805c6ced79f0dab5f19ea23956760c8c5
2023-09-13 06:18:37 -07:00
Alessio Quaglino 8064ad59c8 Add camera projection sensor.
BEGIN_PUBLIC
Add camera projection sensor.
END_PUBLIC

PiperOrigin-RevId: 564726114
Change-Id: I33b8e5562eff29c21538bf8f38ce3116c7dfc5a9
2023-09-12 08:16:20 -07:00
Saran Tunyasuvunakool 78183e60e1 Refactor thread pool implementation.
- Make mjTask non-opaque and remove C++ Task class.
- Make C++ thread pool a subclass of a skeletal mjThreadPool C struct.
- Make the mjTask status enum more consistent with the rest of MuJoCo.
- Change mju_threadPoolEnqueue to take just the mjTask. Users must now prepare the mjTask by assigning the function pointer and argument into the struct.
- Rename files in thread/ to be more consistent with the rest of MuJoCo.
- Run threading tests in CMake.
- Allow use of C++20 designated initializers.

Otherwise the functionality remains identical.

PiperOrigin-RevId: 564374675
Change-Id: I37c9894566bc39faf217e5aa97a4e2713a70e467
2023-09-11 07:20:34 -07:00
Matthew Bennice 0ba10cc4f0 Save normalising transform applied to mesh assets in mjModel.mesh_{pos,quat}
Fixes #409

PiperOrigin-RevId: 564217402
Change-Id: I53ddeef4e343905021cd7852d548f6769c876474
2023-09-10 15:25:59 -07:00
Google DeepMind 040d3efce2 Add options for controlling early termination criteria of CG/Newton linesearch.
Useful for performance tuning models.

PiperOrigin-RevId: 563175078
Change-Id: Id64a510d6080038ea8d5876dabbf0b2b311435bb
2023-09-06 12:02:58 -07:00
Saran Tunyasuvunakool 4929077211 Remove mjMARKSTACK and mjFREESTACK macros.
PiperOrigin-RevId: 562844184
Change-Id: Id2f57f5d132c47094dad75c6dab7297d7aa73458
2023-09-05 11:41:43 -07:00
Saran Tunyasuvunakool 329ed193ac Disallow variable-length arrays and turn on -Wpedantic in Clang and GCC.
PiperOrigin-RevId: 562832747
Change-Id: I0532624cee31e089a47426305d885687eb0fc5c5
2023-09-05 11:05:04 -07:00
Nimrod Gileadi f976d6d228 Use a raw function pointer instead of std::function objects in thread pool.
std::function can have an allocation cost when it's created, and also adds overhead to function calls. Since this API must be used from C, using a raw function pointer is good enough.
PiperOrigin-RevId: 562760324
Change-Id: I2b714a13e07a2b71566d013f21f76c506e817a52
2023-09-05 06:31:05 -07:00
Matthew Bennice 6225186964 Add threading primitives.
PiperOrigin-RevId: 562649644
Change-Id: I9c35b270e4b3b50cc7eb5a152f24d71def8e2fcd
2023-09-04 20:09:19 -07:00
Saran Tunyasuvunakool 94a8705ad0 Add mj_markStack and mj_freeStack as public API functions.
Also add asan instrumentation to detect stack frame leakages (i.e. `mj_markStack` without a corresponding `mj_freeStack` in the same caller function).

PiperOrigin-RevId: 562625645
Change-Id: I4e3ff66ca0b9d08ed0a95cef45393db8e3053e22
2023-09-04 17:04:11 -07:00
Saran Tunyasuvunakool 33f51856c1 Check that alignment is power of 2 in mj_stackAlloc.
PiperOrigin-RevId: 562024496
Change-Id: I9230c6dc05ebb78e935f9b2f606aa77c921d67e5
2023-09-01 12:45:35 -07:00
Yuval Tassa 02e819e76a Tighten const qualifiers of mjData in Jacobian multiplication functions.
PiperOrigin-RevId: 561711229
Change-Id: I66dc1d2fbcfbf8e935b244fe496ada314d53b135
2023-08-31 11:27:15 -07:00
Kyle Bayes 16ee0dfde5 Add modified callback to resource providers (for caching purposes).
PiperOrigin-RevId: 561327623
Change-Id: Id6683f6d6d32ee91019aba46599c28cbffe29df6
2023-08-30 06:53:20 -07:00
Kyle Bayes f86e8b449f Refactor VFS logic out of ResourceProvider plugin code.
PiperOrigin-RevId: 561302536
Change-Id: I952f9e76e85a7e3a111e0338f307378a6ff58197
2023-08-30 04:47:24 -07:00
Saran Tunyasuvunakool 215433f5f7 Implement mj_stackAlloc and mj_arenaAlloc alignment using bitwise-and.
This implementation explicitly avoids calling division instructions (which are generally expensive) even when link-time optimization is not active or if the alloc functions aren't inlined for some reason.

Also make mj_stackAlloc cheaper for external callers who may be linking against MuJoCo dynamically (and therefore cannot benefit from inlining).

PiperOrigin-RevId: 561299565
Change-Id: Iea4be5bf6d351ddf0c9d1fd8bd89a0c207b39309
2023-08-30 04:29:18 -07:00
Saran Tunyasuvunakool 4c899b92cc Rename mj_stackAllocByte to mj_stackAlloc and make it public.
PiperOrigin-RevId: 561133040
Change-Id: I4f5ffe51c1287aa0c82af68bfe17ed6dd2ad09da
2023-08-29 14:07:54 -07:00
Saran Tunyasuvunakool a48e0aa355 Use size_t for the mjMARKSTACK temporary variable.
This is necessary since daa2ac7f8b changed the type of mjData pstack from int to size_t.

PiperOrigin-RevId: 561092753
Change-Id: I298507c2c0656c797637b35ee684b73eefaae8f5
2023-08-29 11:39:01 -07:00
Yuval Tassa d3ed16e78f Add mjData.dof_islandind, indexing from dofs into islands.
Also fix bug in allocation for constraint islands, added allocation for limit constraints.

PiperOrigin-RevId: 561083128
Change-Id: I9e01d5a5b7454ec3cf60bccadaa0f96f2c0d87d1
2023-08-29 11:06:17 -07:00
Saran Tunyasuvunakool daa2ac7f8b Rename nstack to narena, change it and pstack to count bytes.
PiperOrigin-RevId: 561066311
Change-Id: I4d0e645e6c254dd906bfc42159e0e99149a7c6c8
2023-08-29 10:13:33 -07:00
Saran Tunyasuvunakool b979a26b10 Rename mj_stackAlloc to mj_stackAllocNum.
PiperOrigin-RevId: 561040193
Change-Id: I49ea21ffb5b596471d2aacefb1961c11c5c905d0
2023-08-29 08:43:03 -07:00
Yuval Tassa df1b3515c7 Add mjData.nl: number of active limit constraints.
PiperOrigin-RevId: 561012367
Change-Id: I9a01fec55502f8a90d7435972e477455ae29df15
2023-08-29 06:32:18 -07:00
Tom Erez 819b5cb982 Add invdiscrete flag to enable discrete-time inverse dynamics with mj_inverse.
PiperOrigin-RevId: 560161140
Change-Id: If3e30be5e9af4982571dd310172f2fc0d8d1c551
2023-08-25 12:08:37 -07:00
Yuval Tassa 1dad5993f0 Refactor constraint island representation.
Required for constraint solver islanding.

Replace linked lists with `island_{dof,efc}_{num,adr,ind}`, corresponding to the standard `{rownnz,rowadr,colind}` sparse matrix representation. By effectively defining two sparse matrix structures of dimensions `nisland x nv` and `nisland x nefc`, respectively, this representation is more conducive to reuse of existing sparse matrix utility functions, while being cache-friendlier by making sequential indices adjacent in memory.

PiperOrigin-RevId: 559704957
Change-Id: I919362cbef0d5fe5acc4aa2bb4ffb17eee8223a2
2023-08-24 03:48:57 -07:00
Yuval Tassa b7cf479abe Add flag for disabling implicit integration of joint damping in the Euler integrator.
PiperOrigin-RevId: 559398414
Change-Id: I43b23c5e75a2830a64b1898daeaa16f19e011718
2023-08-23 05:51:37 -07:00
Alessio Quaglino b5f9628dd7 Reduce mjMAXCONPAIR to 50.
Use only the first `mjMAXCONPAIR` contacts in SDF-mesh collisions after sorting them using the penetration depth.

PiperOrigin-RevId: 558176217
Change-Id: Ia1ee12bd5ceb81e4c52f143831ad00426e8cf174
2023-08-18 10:02:44 -07:00
Yuval Tassa b1ecc943bb Fix multiple bugs related to mjvSceneState.
PiperOrigin-RevId: 557864131
Change-Id: I47d9692930c54b1304a5cc161f99bbd81d992a7c
2023-08-17 10:25:39 -07:00
Alessio Quaglino fdb041580c Add Signed Distance Field to collision geometries.
PiperOrigin-RevId: 557507088
Change-Id: I358a642407aee1ba8dfc9d405eb9a4f609435fe9
2023-08-16 09:15:23 -07:00
Yuval Tassa 3e034e38b2 Add constraint island discovery
PiperOrigin-RevId: 557067599
Change-Id: Ic41e1d0efef02b7a79142518afe49cf9d4e74725
2023-08-15 02:30:05 -07:00
Nimrod Gileadi 2c3297b3e7 Add filterexact and actearly options to MuJoCo.
When filterexact is a new dyntype which is just like the existing `filter`, but the activation state is integrated with exact integration, instead of simple Euler integration.

When actearly is specified on a general actuator, `qfrc_actuator` is computed using the next timestep's `act` value, instead of the current value.

PiperOrigin-RevId: 554438423
Change-Id: If901e4988fa6b518d6f3097f149770665a189a4b
2023-08-07 04:50:33 -07:00
Yuval Tassa f0f535ed04 Improve order and clarify declarations of arena variables in mjdata.h
PiperOrigin-RevId: 554419319
Change-Id: I83b83c56be4b74060f4a108c35ce481b8f354c5e
2023-08-07 03:07:11 -07:00
Saran Tunyasuvunakool eaf78b798b Bump dev version number to 2.3.8.
PiperOrigin-RevId: 549580971
Change-Id: If8be1910f0196754ce8abb8d91fe604e789ecec8
2023-07-20 03:27:50 -07:00
Saran Tunyasuvunakool c9246e1f50 Release version 2.3.7.
PiperOrigin-RevId: 549565890
Change-Id: I56db138998e43637bdde86de6490a567f0f255ec
2023-07-20 02:13:55 -07:00
Yuval Tassa 51aa375af0 Improvements related to models where joint-actuator relationship is not one-to-one:
- Add `joint-actuatorforcerange` for clamping total actuator force at joints. Add `sensor-jointactuatorfrc` for sensing total actuator forces on a single joint.
See [documentation](https://mujoco.readthedocs.io/en/latest//modeling.html#actuator-force-clamping) for justification and use cases.
- Add simple car model to `model/`.
- Move actuation-related test models into `engine/testdata/actuation/`.

PiperOrigin-RevId: 549355941
Change-Id: I27f6c1f80426d73a2811ef5ae74684a228b2fbd1
2023-07-19 10:29:32 -07:00
Yuval Tassa 5cfbb6ac8b Add mjd_quatIntegrate, expose mjd_subQuat.
PiperOrigin-RevId: 546252926
Change-Id: I7d6b2bd6536e7e8afc368f3c46037c20f6a1cb5e
2023-07-07 05:33:24 -07:00
Yuval Tassa c50c92ccc8 Add mjv_connector, identical to mjv_makeConnector but with a more convenient "from-to" parameterization.
PiperOrigin-RevId: 542343761
Change-Id: I75f5ff3c404a2a9f65dfed706e590efd7b951f6e
2023-06-21 13:19:36 -07:00
Yuval Tassa f67e359532 Add mjtState enum and related mj_stateSize, mj_getState and mj_setState functions.
PiperOrigin-RevId: 539667943
Change-Id: I14c34be8ce4c287e529380257b5c5bffc3ab45ce
2023-06-12 08:56:48 -07:00
Yuval Tassa 466c9aca82 Remove mj_activate and mj_deactivate.
PiperOrigin-RevId: 538799120
Change-Id: I4d6729131e20ab9ae15c94c221ba83ae5732e942
2023-06-08 08:55:39 -07:00
Yuval Tassa d82f5ce5a4 Add mjContact.solreffriction, mjModel.pair_solreffriction and related implementation, allowing contact reference acceleration to be different for normal and frictional contact directions. This is required for e.g. elastic frictional collisions.
PiperOrigin-RevId: 538513357
Change-Id: Id9eb910fe791cf898c712030cb2c0fc481389c91
2023-06-07 09:40:20 -07:00
Yuval Tassa d40c395917 Add Visualization tab to simulate.
Also:
- Increased label width in mjUI tight theme spacing.
- Added `mjITEM_EDITFLOAT` for editing float values.
- Move mjUI numpad key codes to header file.
PiperOrigin-RevId: 535839953
Change-Id: Ibdc0a9a20be514caa5b487211212ed6f5b8a6ba9
2023-05-27 05:08:15 -07:00
Saran Tunyasuvunakool f887c1e928 Add ASAN and MSAN instrumentation for arena and mjData stack.
PiperOrigin-RevId: 535635490
Change-Id: Ia1e58771bae25bf72c861f57452fb8faa2b918fb
2023-05-26 09:17:26 -07:00
Alessio Quaglino 03d6d27f64 Use mesh BVH for speeding up ray mesh intersection.
PiperOrigin-RevId: 534141245
Change-Id: I9f5a71ea059a1a232fd2910d1efc0506ab6dbef3
2023-05-22 12:05:20 -07:00
Alessio Quaglino dab49d487c Use mesh BVH for speeding up ray mesh intersection.
PiperOrigin-RevId: 532516008
Change-Id: Ia9cac060279d030221c1a6b4fad457a857701370
2023-05-16 11:10:38 -07:00
Alessio Quaglino 9d1a21f99d Use mesh BVH for speeding up ray mesh intersection.
PiperOrigin-RevId: 532464595
Change-Id: If159c89b93c24e6a7be6310911364cfad7baae81
2023-05-16 08:17:50 -07:00
Alessio Quaglino fcc825c5e6 Add cutoff argument to mj_multiRay.
PiperOrigin-RevId: 532158635
Change-Id: I70f98be9f781c8281e21aa5c17bd85f3654e9383
2023-05-15 10:44:37 -07:00
Yuval Tassa 770b4b363a Added optional smoothing to muscle dynamics:
- `muscle` actuators take a new `tausmooth` attribute (defaults to 0) which when positive, smooths the transition between activation and deactivation timescales.
- `mju_muscleDynamics` takes 3 parameters, adding width of smoothing sigmoid.

PiperOrigin-RevId: 531473354
Change-Id: I8ab6c0289ff04437e798c3ca6edda132a30fcc31
2023-05-12 04:58:53 -07:00
Alessio Quaglino 4c487e07ed Add mesh BVH.
PiperOrigin-RevId: 530559807
Change-Id: Ibdafae22c7c74d15d707f205be73e4a571a6ae10
2023-05-09 03:31:06 -07:00
Yuval Tassa 49efa9cc15 Change finite-support mju_sigmoid from a two-quadratic construction to a single quintic with zero 1st and 2nd derivatives at 0 and 1, the boundary of the smooth-support segment.
Note: this function is currently unused in the MuJoCo codebase.
PiperOrigin-RevId: 529969804
Change-Id: I2bddc72916eff67625b806510935bc7f3ce5c770
2023-05-06 09:22:37 -07:00
Kyle Bayes 67f0f5154f Add various improvements for resource providers.
PiperOrigin-RevId: 529706437
Change-Id: I20385e031446674584349c301982dbe13b812477
2023-05-05 07:03:49 -07:00
Nimrod Gileadi 3d82d2a40f Increase maximum number of UI elements per section in Simulate.
PiperOrigin-RevId: 529079121
Change-Id: Ia81418e45c855649e1d9654bbc522f7dffd7dfdc
2023-05-03 07:06:06 -07:00