Commit Graph

82 Commits

Author SHA1 Message Date
Sam Haves 2582a83ac3 Add equalityJointAPI to mjcPhysics.
PiperOrigin-RevId: 860081702
Change-Id: Ifd961dcb2a8e0f5d885e9e9dadc0153b03cb5f4d
2026-01-23 06:28:29 -08:00
Sam Haves c08e1d9e6e Add MjcEqualityAPI as a base class for MuJoCo constraints and MjcEqualityWeldAPI for representing weld constraints.
This change introduces two new USD API schema:
* MjcEqualityAPI - base API for representing MuJoCo equality constraints in USD, this will typically be applied to joints such as UsdPhysicsFixedJoint.
* MjcEqualityWeldAPI - extends MjcEqualityAPI for MuJoCo's weld equality constraints with an attribute for torqueScale.

The usd_decoder is updated to parse UsdPhysicsFixedJoints and convert the new schema attributes into the appropriate mjsEquality data fields.

PiperOrigin-RevId: 856723634
Change-Id: I0982fd3168b643f8e91d87bb5ae5933e526b63a1
2026-01-15 10:44:27 -08:00
Sam Haves d816b38f4c mjcPhysics MjcTendon path now has an indices attribute to allow repeated sites in tendon path.
Since relationships in USD can only contain a single instance of a path, it was previously impossible to have a tendon path that visits the same wrap target more than once. This is a fairly common occurence when dealing with tendons that have pulleys.

With this change, if mjc:path:indices is not defined then the behaviour is as it was and the mjc:path is considered to be ordered. If it is authored then the parser will use the indices into mjc:path as the order. This mirrors other similar concepts in USD such as face vertex indices.

PiperOrigin-RevId: 856339887
Change-Id: I6b9503973de377acdb0689be168c16e4aa19b70b
2026-01-14 13:24:28 -08:00
Sam Haves a5dc57c0c3 Move OpenUSD parsing to usd_decoder
Add usd_decoder to mujoco/plugin.
  - Previously was src/experimental/usd/usd_to_mjspec.cc, now that same spec is returned by the plugin.

PiperOrigin-RevId: 854350962
Change-Id: Ia980190a557c50ce8197980922a2594b613859b4
2026-01-09 14:48:29 -08:00
Alessio Quaglino 51babec9c5 Move tactile sensor to the engine.
PiperOrigin-RevId: 788863133
Change-Id: I3172ebb7641fa8146469da25cba7db794760e7b1
2025-07-30 05:27:44 -07:00
Alessio Quaglino 4bbd0fb9c7 Do not store grid edges in tactile sensor.
This is in preparation for extending support to store the grid as a mesh.

PiperOrigin-RevId: 786281232
Change-Id: Ic718c2d2e1891cf0b66113270fd3c98acc1e74a5
2025-07-23 08:00:51 -07:00
Alessio Quaglino 0eb2f9f118 Use meshid in touch sensor for mesh geoms.
PiperOrigin-RevId: 784575734
Change-Id: Ibca753273c67128c6c1421dad8413814dce31182
2025-07-18 07:23:04 -07:00
Alessio Quaglino e23226509c Tidy up of touch stress plugin.
PiperOrigin-RevId: 784186240
Change-Id: I47298ff2b7676a540781561817670c5f00c1b63a
2025-07-17 08:14:49 -07:00
Alessio Quaglino 5069534a5c Small (~10%) performance improvement in touch sensor by avoiding a transpose.
PiperOrigin-RevId: 783682096
Change-Id: I8311ee8fe9f64996db852969a70398c66fca4e48
2025-07-16 03:05:05 -07:00
Alessio Quaglino 4ea778f2d3 Add octree support to MJX API.
Also, enable the touch sensor to use the octree SDF.

PiperOrigin-RevId: 783313462
Change-Id: I0032c2a7164f4770aa10a3612db3fd70bea954db
2025-07-15 06:44:43 -07:00
Alessio Quaglino bbb265da4a Do not draw touch sensor grid if contact point vis flag is disabled.
PiperOrigin-RevId: 781908115
Change-Id: Id42206b1d8b6766352071e20150e2a4047895bf7
2025-07-11 03:11:26 -07:00
Alessio Quaglino cef02fabea Remove sdflib plugin and move interpolation to engine_collision_sdf.
Before:
```
 Simulation time      : 1.71 s
 Steps per second     : 5854
 Realtime factor      : 11.71 x
 Time per step        : 170.8 µs

 Newton iters / step  : 2.19
 Contacts / step      : 3.45
 Constraints / step   : 13.79
 Degrees of freedom   : 12
 Dynamic memory usage : 0.2% of 14M
```

After:
```
 Simulation time      : 1.41 s
 Steps per second     : 7093
 Realtime factor      : 14.19 x
 Time per step        : 141.0 µs

 Newton iters / step  : 2.19
 Contacts / step      : 3.45
 Constraints / step   : 13.79
 Degrees of freedom   : 12
 Dynamic memory usage : 0.2% of 14M
```

PiperOrigin-RevId: 781087896
Change-Id: Iaf69dccc5e95af5bac862344683c74f962162186
2025-07-09 09:29:47 -07:00
Alessio Quaglino 96118da08b Move SDF precomputation to the mujoco compiler.
Before:
```
 Simulation time      : 2.24 s
 Steps per second     : 4472
 Realtime factor      : 8.94 x
 Time per step        : 223.6 µs

 Newton iters / step  : 2.47
 Contacts / step      : 3.37
 Constraints / step   : 13.49
 Degrees of freedom   : 12
 Dynamic memory usage : 0.2% of 14M
```

After:
```
 Simulation time      : 1.71 s
 Steps per second     : 5854
 Realtime factor      : 11.71 x
 Time per step        : 170.8 µs

 Newton iters / step  : 2.19
 Contacts / step      : 3.45
 Constraints / step   : 13.79
 Degrees of freedom   : 12
 Dynamic memory usage : 0.2% of 14M
```

PiperOrigin-RevId: 781075182
Change-Id: Ie509047ff581ab0df4b10bbd394c27d350ab5a13
2025-07-09 08:57:09 -07:00
Alessio Quaglino b81f1db8af Replace SdfLib with linear octree interpolation of TriangleMeshDistance.
Temporary changes to the octree:
- Changed frame from mesh to geom

Before change (tolerance 1e-3):
```
 Simulation time      : 2.34 s
 Steps per second     : 4275
 Realtime factor      : 8.55 x
 Time per step        : 233.9 µs

 Newton iters / step  : 2.26
 Contacts / step      : 3.69
 Constraints / step   : 14.76
 Degrees of freedom   : 12
 Dynamic memory usage : 0.7% of 14M
```

After change (6 octree levels):
```
 Simulation time      : 2.24 s
 Steps per second     : 4472
 Realtime factor      : 8.94 x
 Time per step        : 223.6 µs

 Newton iters / step  : 2.47
 Contacts / step      : 3.37
 Constraints / step   : 13.49
 Degrees of freedom   : 12
 Dynamic memory usage : 0.2% of 14M
```

PiperOrigin-RevId: 781019754
Change-Id: Ib15581244dfe9e571e1c6c2cac4a101cf3d8ba3d
2025-07-09 06:21:41 -07:00
Alessio Quaglino 35665c5cb3 Skip mesh geoms in touch sensor.
Also, use geom_rbound for the sensor size and check that there is at least one collision geom.

PiperOrigin-RevId: 772928954
Change-Id: I56f1577df66213a70fb1dc12488fbcd2f8a4b8b4
2025-06-18 08:24:37 -07:00
Alessio Quaglino 7edbdd0ad6 Remove the Shell plugin and integrate it into the engine.
PiperOrigin-RevId: 760688502
Change-Id: Ia70988d42b7edf571d7cb4a4f48f8fc50b51667d
2025-05-19 10:51:25 -07:00
Alessio Quaglino 71bdd915f7 Move bending stiffness from plugin to the compiler.
PiperOrigin-RevId: 758677644
Change-Id: I7d5c5140ba6948002bfa4ae9d6b4bf0f6de0e39b
2025-05-14 07:39:24 -07:00
Alessio Quaglino 34e8ff1aad Add flex edge flap connectivity to mjModel.
PiperOrigin-RevId: 758593152
Change-Id: I79836df961972c9eae8037e5fcbfc3d0122645de
2025-05-14 02:50:37 -07:00
Alessio Quaglino 2386dfd7da Add touch sensor for estimating the surface contact stresses from the SDF.
PiperOrigin-RevId: 758556339
Change-Id: Ib56d76fab084b530fd68d61a29294cb6f1d05f3f
2025-05-14 00:45:58 -07:00
Sam Haves ab63a7e824 Add CMakeLists for usdMjcf file format plugin.
This adds an option MUJOCO_BUILD_USD_PLUGINS to the top level CMakeLists which allows us to build the usdMjcf file format plugin with the rest of mujoco.

In this first version, we allow building against either standalone USD or against Houdini (DCC) since it has it's own fork of USD. When building against standalone USD we also build the file format tests.

PiperOrigin-RevId: 753969974
Change-Id: If691eecbddf45d18b7c4ff76f7650999d42e99c5
2025-05-02 05:48:33 -07:00
Alessio Quaglino 0995af83f9 Add documentation for SdfLib plugin.
Fixes #2182.

PiperOrigin-RevId: 690980373
Change-Id: Ifc94f928e9cfbdbef3cb6f11ad4bffed542bf49a
2024-10-29 05:32:13 -07:00
Alessio Quaglino 4998e7b392 Move flex damping to the engine and remove membrane and solid plugins.
PiperOrigin-RevId: 676434954
Change-Id: I24e8dbaa90afcffd613a9cf106ef8b7262195328
2024-09-19 09:01:30 -07:00
Alessio Quaglino 66a9cacc90 Move elasticity force computation to the engine.
PiperOrigin-RevId: 676028775
Change-Id: I994e3dda8d6470815763c04df0c276e265aa1f54
2024-09-18 09:55:00 -07:00
Alessio Quaglino ddbc083810 Move elasticity computation to mjCFlex.
PiperOrigin-RevId: 675949380
Change-Id: Ia48f4fd6ae1ede206ccacd1205914e7e4b3c7aec
2024-09-18 05:23:10 -07:00
Alessio Quaglino 31abd7900a Add edge ids to flex elements in mjModel.
PiperOrigin-RevId: 675130981
Change-Id: If2ccfb268142d235273b7a50e15740f6399903b2
2024-09-16 06:58:10 -07:00
Alessio Quaglino b15de2c951 Add elasticity parameters to the schema.
PiperOrigin-RevId: 675115200
Change-Id: Ic6608ce61cbb857dca71b3d9cbdac057e8f1ac7a
2024-09-16 05:56:36 -07:00
Alessio Quaglino 2da15cf137 Add flex elasticity stiffness matrix to mjModel.
PiperOrigin-RevId: 675101645
Change-Id: Ic169c108b9eece3657ea4ec211df357abe615b7e
2024-09-16 05:00:54 -07:00
Alessio Quaglino 33e56ccb88 Remove edge length computations from elasticity plugins.
Read the lengths from mjModel and mjData flex arrays.

PiperOrigin-RevId: 673116608
Change-Id: Iffa209abb7443707effaffb5bda99345399fac1c
2024-09-10 14:54:53 -07:00
Alessio Quaglino 4862b9e765 Remove plugin support from Composite particles.
This functionality is replaced by FlexComp.

PiperOrigin-RevId: 672503965
Change-Id: I58953267de285f82e416f9f60576a336b7d0da4c
2024-09-09 04:58:26 -07:00
Google DeepMind 70d70bc3b7 Fix typos in MuJoCo documentation.
PiperOrigin-RevId: 656068822
Change-Id: I5ebbb3701148ea4d978a6a1ad3f762ffcc7e57cb
2024-07-25 13:31:13 -07:00
Nimrod Gileadi 393895bb29 Explicitly specify actdim on PID plugin actuators, to allow them to be used with keyframes.
Support actdim attribute on plugin actuators.

Remove the actuator_actdim callback. This callback leads to crashes when loading keyframes for models that have a stateful plugin.

PiperOrigin-RevId: 650649505
Change-Id: I40d1994d02ae4e20ce631b2702a984766cf2628e
2024-07-09 09:08:48 -07:00
Nimrod Gileadi c5f958bdff When reporting compilation errors, include warning strings.
This allows plugins to call mju_warning, and have the string propagate to users.

PiperOrigin-RevId: 650621601
Change-Id: I608e7a3a1ad126ab8da2ff0634fa708458fb9ccc
2024-07-09 07:33:11 -07:00
Yuval Tassa 8e2f830fd2 Fix type errors in compiler and tests.
In preparation for a float32 build of MuJoCo.

PiperOrigin-RevId: 644407674
Change-Id: I60069f0f865ef89fbf613f5a2ca0c336cc63461e
2024-06-18 09:12:44 -07:00
Yuval Tassa 19388eee0c Fix type errors in engine and plugins.
- Preparation for a float32 build of MuJoCo.
- Fix use of `float`-typed `fabs` in `mju_eig3`.

PiperOrigin-RevId: 643804942
Change-Id: I89f64e8fd39f4e70e78d7607816283e217912383
2024-06-16 12:35:05 -07:00
Yuval Tassa 6067048537 Deprecate mju_rotVecMat and mju_rotVecMatT in favor of mju_mulMatVec3 and mju_mulMatTVec3.
These functions names and argument ordering are more consistent with the rest of the API.

PiperOrigin-RevId: 643788290
Change-Id: I783eda8021b80b82098e23ed95669b102bb82508
2024-06-16 10:02:36 -07:00
Alessio Quaglino 195bd32aa6 Add a check for mesh dimension in the elasticity.solid plugin. Fixes #1647.
PiperOrigin-RevId: 637905358
Change-Id: I1432a8fe054752bc962174548da3c1f81deb6555
2024-05-28 08:18:12 -07:00
Alessio Quaglino 1d181786a2 Prevent visualization of SDF iterations from writing outside the maximum allocated vector. Fixes #1539.
PiperOrigin-RevId: 632071103
Change-Id: Idf91ede1661e717ad338f601a5482ab171d7f625
2024-05-09 01:42:35 -07:00
Alessio Quaglino 80674149ce Allow pinning flexes to non-simple bodies. Fixes #1270.
PiperOrigin-RevId: 598865882
Change-Id: I105ff1910a7d67f5b7bcb46bcef0e5e388ec08ea
2024-01-16 09:32:26 -08:00
Alessio Quaglino 5d46c39529 Increased SdfLib bounding box by 10% to prevent querying outside it during collision detection.
In case a query outside is performed, add SDF gradient computation using finite differences.

For SDFs generated from meshes, when the query point lies outside of the bounding box, the gradient provided by SdfLib ignores the SDF and is equivalent to the gradient of the distance from the bounding box, causing local minima in the contact point optimization. This CL increased the size of the bounding boxes and replaces the SdfLib gradient with a finite difference approximation of the gradient if a point lies outside it.

PiperOrigin-RevId: 597839637
Change-Id: I79dfddbe25288eca7eb235db51781fc2bb2c3c5f
2024-01-12 07:54:10 -08:00
Alessio Quaglino baaaa10612 Fix typo in plugin docs.
PiperOrigin-RevId: 596884568
Change-Id: Ic0ba59fc73fbfd95361655e7761e49b2cb4985b0
2024-01-09 04:00:29 -08:00
Alessio Quaglino 63ec34f9f8 Add plugins to flex parent body if there are pinned vertices.
Fixes #1270.

PiperOrigin-RevId: 595429578
Change-Id: Ifc61d4bde4dd3c6b4d4a09106152de1d24e71ef0
2024-01-03 09:53:22 -08:00
Kevin Zakka 2940b934fe Fix typo in sdf plugin readme.
PiperOrigin-RevId: 595404942
Change-Id: I43eb079779538e4ff82d0f549b5a49819ebcd9cb
2024-01-03 08:10:01 -08:00
Nimrod Gileadi aed4254d65 Fix the table formatting in plugin/actuator/README.md.
The line continuation format that was used is not supported on GitHub.

PiperOrigin-RevId: 590141362
Change-Id: I0ab0dabfb8977bdf79682476376dda435787eba0
2023-12-12 03:42:45 -08:00
Nimrod Gileadi c062a8db19 Allow multiple actuators to use the same PID plugin.
Maintain separate state for each actuator in the Plugin object.

PiperOrigin-RevId: 587760569
Change-Id: I633a1b94f0dde9377120145066a26aef6a4033b8
2023-12-04 10:08:07 -08:00
Nimrod Gileadi 236dcb4ffd Fix a bug with PID actuators, when plugin definition order differs from actuator order.
PiperOrigin-RevId: 587729879
Change-Id: If71c7e374f36ef08c5147e7316066d6f5365925f
2023-12-04 08:31:45 -08:00
Alessio Quaglino 4c8ffb44bf Extend SDF outside the bounding box for SdfLib plugin.
SdfLib returns the sum of the distance from a given point to the bounding box and a saved minimum distance from the surface over the whole box boundary. This underestimates the true distance and can cause spurious contacts and jittering. This CL performs a box projection of points outside the bounding box and adds the distance of the original point from the box to the distance of the projected point to the surface. This overestimates the true distance and avoids spurious collisions.

PiperOrigin-RevId: 586701933
Change-Id: I22eecb9757fa22359440156ef6433135648fa3ff
2023-11-30 09:43:06 -08:00
Alessio Quaglino 7d8d4d398e Make elasticity plugins compatible with flex pins. Fixes #1235.
Before change:
poncho       18.20s
poncho_flex  44.60s
floppy       4.70s
floppy_flex  6.43s

After change:
poncho       18.23s
poncho_flex  44.62s
floppy       4.67s
floppy_flex  6.57s

PiperOrigin-RevId: 585952587
Change-Id: I0e7c1513f64c7ab1e6ad71e2168b4467c042b46f
2023-11-28 06:13:43 -08:00
Nimrod Gileadi 6412c95a37 Remove the use of plugin_state from PID plugin.
The plugin was storing a boolean to indicate whether the previous ctrl value was set in `act`. Use d->time == 0 instead.

PiperOrigin-RevId: 585692686
Change-Id: I95335cebdb5716bd6fad81f463a4f248406c80ec
2023-11-27 10:32:07 -08:00
Nimrod Gileadi 002b427a32 PID Controller as an actuator plugin.
Implement a configurable PID controller.

PiperOrigin-RevId: 585282014
Change-Id: I2d884554629101a0a25b5e0979ffb1ff8ed9cab4
2023-11-25 08:41:01 -08:00
Alessio Quaglino 8ca51b5318 Backtracking line search for SDF collisions.
Increased tolerance above zero in nutbolt.xml since now the two parts lock otherwise. Measured speedup of 2x in this example.

This solves the issue of scale-dependent step sizes. Tested on gears with 10cm diameter and 2cm thickness.

PiperOrigin-RevId: 584009449
Change-Id: Ied2f62dbbbc592470b91cf910f3553802a57c752
2023-11-20 06:33:01 -08:00