Commit Graph

49 Commits

Author SHA1 Message Date
Omar Rayyan 040872fd65 Copybara import of the project:
--
a5221e754c88580d103bfc7bfaf1ed32927ca499 by omar rayyan <olr7742@nyu.edu>:

Fix .mjz loading in simulate

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/3384 from omarrayyann:fix-mjz-simulate a5221e754c88580d103bfc7bfaf1ed32927ca499
PiperOrigin-RevId: 944573851
Change-Id: Ifba77ee9f9b97a7d8c0b0a47ac82d390a273672b
2026-07-08 10:30:54 -07:00
Yuval Tassa 916695e794 Fix step timing diagnostics and make compiler errors transient in simulate.
PiperOrigin-RevId: 935675994
Change-Id: I7bc26291fb061e712187e0a6205723fda65b5f46
2026-06-21 11:08:01 -07: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
Taylor Howell 401bf431b8 Modify Simulate::InjectNoise to set target of exponential decay to value from key_ctrl if a valid key is provided as input.
PiperOrigin-RevId: 813819040
Change-Id: I79508039b17fb3484b71ae0d19614c32adacfa10
2025-10-01 10:46:29 -07:00
Matija Kecman afbefc38a6 Ensure noise is injected when the simulation is paused and a single step is manually requested
PiperOrigin-RevId: 807688008
Change-Id: I8de9706c633565d6d6944b58d34de9da1037a837
2025-09-16 07:35:42 -07:00
Yuval Tassa c7a82c32dc Do not update qacc_warmstart at the end of the solver call; instead, update it at the same time as all other state variables. This change makes mj_forward idempotent.
See changelog herein for motivation and discussion.

PiperOrigin-RevId: 797392841
Change-Id: If50e9f09e1d07e8363169d3589c32097aeca2432
2025-08-20 11:30:13 -07:00
Sam Haves 14972d2490 Add mj_loadUSD function. Change simulate to use that instead of manual spec compilation.
PiperOrigin-RevId: 780608874
Change-Id: I333238c756fe76b371518a7cdf9452b93da3540a
2025-07-08 10:04:08 -07:00
Sam Haves e80a62c6d5 Allow loading USD files into simulate.
PiperOrigin-RevId: 776584803
Change-Id: I66a5277b3752d69ba5d44ed419204951edb18d41
2025-06-27 07:59:21 -07:00
Yuval Tassa 14dc7c2a60 Add "cameraid" attribute to visual/global specifying the default camera to use at model load.
PiperOrigin-RevId: 773783069
Change-Id: I2fff2abdceedc982d89cee8d14b95abceea1c113
2025-06-20 11:41:27 -07:00
Hannes Braun af0cb2d365 Use errno.h instead of sys/errno.h 2025-05-15 16:15:51 +02:00
Alessio Quaglino c5a677a9de Fix load error message. Fixes #2135
PiperOrigin-RevId: 685668168
Change-Id: Ieac7ccca5bee695cf55fc74bd33fadf77a025cb9
2024-10-14 05:10:58 -07:00
Yuval Tassa cf3e60f9a4 Fix load time reporting in simulate.
Before this change, a model which took more than 1/4 seconds to load caused the simulation to pause, which is a behavior that is only supposed to occur for models that loaded with a warning.

PiperOrigin-RevId: 665786861
Change-Id: Ie3a6c8d18a6abbb425a0bbcc5a8e55d5fd7a0c72
2024-08-21 02:54:10 -07:00
Yuval Tassa 24a555062d Rename mjDSBL_AUTORESETNAN to mjDSBL_AUTORESET.
- Expose in MJCF.
- Add documentation.
- Improve handling in simulate.

PiperOrigin-RevId: 657606140
Change-Id: I6a27c2f4842d7d4ae32642f2a6255e5f8f1f605a
2024-07-30 08:41:59 -07:00
Yuval Tassa 3d1d1d0718 Multithreaded mesh compilation.
PiperOrigin-RevId: 651358120
Change-Id: Id6272aac84ec6ac1b709d2f4a44b7593307bd158
2024-07-11 04:21:49 -07:00
Yuval Tassa 17f6b12930 Report model load time in simulate if it takes more than 0.5 seconds.
PiperOrigin-RevId: 650933302
Change-Id: Id33aa9935a6b4f493dfa9a913f8a424b3f387fa1
2024-07-10 02:56:47 -07:00
Yuval Tassa 3f3b39bbb1 Fix type-related issues in dependent code. Remove hardcoded mjUSEDOUBLE. Add mjUSESINGLE compiler flag.
This CL does not change the default build behavior of MuJoCo. To use single-precision floating-point, build MuJoCo with `-DmjUSESINGLE`.

PiperOrigin-RevId: 644782648
Change-Id: Ie815df9916798ca8054306437b39a33f84ce9e08
2024-06-19 10:52:18 -07:00
Yuval Tassa 6a532fc53e Fix bug in simulate noise injection logic.
Noise injection was occurring at every iteration of the physics thread, rather than before every call to `mj_step`, leading to time-step-dependent noise rate.

- Moved the logic from main.cc to a `Simulate::` method, called before `mj_step`.
- Reduced the maximum time-scale slider value back to 4 seconds (recent increase was due to this bug).

PiperOrigin-RevId: 643350296
Change-Id: I96832905e6614f92ac725298b16fcabe64ea1df1
2024-06-14 08:13:24 -07:00
Yuval Tassa f37f840880 Improvements to control noise in simulate:
- Use `ctrl` as filter state rather than external preallocated buffer.
- Scale and clip to control ranges.
- Exponential decay to the middle of the range.
- Scale is now [0 1] (scaled to range).
- Rate is now [0 20].

PiperOrigin-RevId: 642586333
Change-Id: Id45a0420736a6edcf09be1db53d9320e7df2c668
2024-06-12 05:35:41 -07:00
Silvio Traversaro d90d57609e Copybara import of the project:
--
4883e8aacd531d8dbc3551ba7cb4e3b4694dda1e by Silvio Traversaro <silvio@traversaro.it>:

Fix plugin related comment in simulate

The comment was outdated after https://github.com/google-deepmind/mujoco/commit/2ebc5f097b1a5fbbe276250ad1d13966510d1291 .

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/1499 from traversaro:patch-37 4883e8aacd531d8dbc3551ba7cb4e3b4694dda1e
PiperOrigin-RevId: 615005350
Change-Id: I93d746f996de25b871cc1bc5651308d44382feef
2024-03-12 05:33:33 -07:00
Alessio Quaglino 8c7c39a211 Lock the sim mutex in PhysicsLoop and PhysicsThread.
This prevents an invalid memory access when the stack is used in engine_vis.

Fixes #1219.

PiperOrigin-RevId: 588017796
Change-Id: I1ee18c5aa5e96ccaeebb0a467cd384355882b80b
2023-12-05 03:56:52 -08:00
Saran Tunyasuvunakool 2e15574b58 Allow user-defined visualization geoms to be added to the passive viewer.
Fixes #1023, #1082

PiperOrigin-RevId: 572303635
Change-Id: Ia8399f816f311b38a7b137f5bd4f359f77a1da1c
2023-10-10 10:52:21 -07:00
Yuval Tassa e9613f0cc9 Rename simulate.fully_managed_ to simulate.is_passive_ with flipped semantics.
PiperOrigin-RevId: 570815258
Change-Id: Iaffdb0e52bcdb31cff7bd29cb820913e3838f0ee
2023-10-04 14:49:52 -07:00
Yuval Tassa 3e12f0d50c Add history scrubbing mechanism to simulate.
[screen capture](https://www.youtube.com/watch?v=YSvWn_poqWs)

PiperOrigin-RevId: 570676968
Change-Id: Id9a1fccc9418b851e007ddcf3fa89acd4edff3e9
2023-10-04 06:36:34 -07:00
Yuval Tassa 639e77876d Improved unpause behavior in simulate.
PiperOrigin-RevId: 570030315
Change-Id: I5822f8686ba2fd7c5c59a9fa73fc29000a8406ec
2023-10-02 05:00:40 -07:00
Copybara-Service b8a91a00ce Merge pull request #1070 from aftersomemath:simulate-load-message
PiperOrigin-RevId: 568995214
Change-Id: Iac7644c4b35a916aa6a7d1bb158ba15a024b43ac
2023-09-27 16:36:40 -07:00
Yuval Tassa ac74c72657 Fix issue where unpausing the simulation (especially under slowdown) causes a jump in simulation time, in both native simulate and Python viewer.
PiperOrigin-RevId: 568948943
Change-Id: I2f401508555e272f348e97627aeb85cb3e9cf017
2023-09-27 13:46:19 -07:00
Levi Burner e7d1f2f110 simulate: fix display of loading message 2023-09-27 16:04:36 -04:00
Alessio Quaglino 1afd98ec4b Add [SdfLib](https://github.com/UPC-ViRVIG/SdfLib) plugin to first-party SDFs.
The following dependencies are disabled with a cmake patch file.
- Enoki
- OpenMP
- Assimp
- FCPW

PiperOrigin-RevId: 565352386
Change-Id: Icff9de68408e0afa2032bb83b24491fc4e41d181
2023-09-14 06:42:42 -07:00
Nimrod Gileadi 39723891ce Use the correct string length argument to mj_loadXML.
PiperOrigin-RevId: 531941053
Change-Id: Ia85b779b603a673b8e1d6f22d4bc183311204c4b
2023-05-14 14:40:36 -07:00
Saran Tunyasuvunakool b362cb4972 Expose a handle for the Python viewer.
This change also requires user scripts to explicitly synchronize changes to physics state to the viewer. The Simulate class was reconfigured so that certain UI events are handled during this sync operation, outside of the render loop on the main thread. These correspond to operations that require access to the full mjModel/mjData.

To support other, more interactive operations (e.g. camera movements), a new mjvSceneState struct is introduced which captures only the portion of the physics state required for scene re-rendering. The mjvSceneState is updated from mjModel/mjData during the viewer sync operation, and is significantly cheaper than a full mj_copyModel and mj_copyData.

Fixes https://github.com/deepmind/mujoco/issues/796

PiperOrigin-RevId: 525723636
Change-Id: Id08d0210a2c067d5afe85e2bf104f276aeddd75e
2023-04-20 05:59:19 -07:00
Saran Tunyasuvunakool 5646c905cd Rename a few functions and variables to be a bit more Googley.
PiperOrigin-RevId: 523963645
Change-Id: Ife7ed3f44aa83c64dfbdc3ca78ee6de2092b0d63
2023-04-13 04:24:31 -07:00
Saran Tunyasuvunakool 95a07e85cc Fix Windows stack overflow problem in the simulate app.
PiperOrigin-RevId: 507763611
Change-Id: I199910142d9165710c48b41a842ab9aef01ff5c2
2023-02-07 06:34:10 -08:00
Saran Tunyasuvunakool e40775fab3 Abstract out GLFW calls from Simulate.
PiperOrigin-RevId: 500129478
Change-Id: I7ba998e20439575ad9a3fe1a866c3db4c36b9328
2023-01-06 02:45:56 -08:00
Kevin Zakka a173e01f42 Prevent division by zero in Ornstein–Uhlenbeck control noise.
PiperOrigin-RevId: 498753494
Change-Id: Ib43e165a4da524c12fab4ea05848b084b2e7713c
2022-12-31 10:29:03 -08:00
Saran Tunyasuvunakool df25d7d602 Raise an informative error when running on macOS under Rosetta 2.
Current users only get a cryptic "Illegal instruction" crash.

Context: https://github.com/deepmind/mujoco/issues/611
PiperOrigin-RevId: 491705647
Change-Id: I1285897a36e858300ee3d125957e90754be9a7f7
2022-11-29 12:19:06 -08:00
Saran Tunyasuvunakool 9ecade0707 Move plugin loading and scanning logic from Simulate to MuJoCo library.
PiperOrigin-RevId: 489020177
Change-Id: I1c29d931b47d5252e57e1d797cc7c17645859ffc
2022-11-16 13:15:51 -08:00
Saran Tunyasuvunakool 2ebc5f097b Change simulate plugin directory name to mujoco_plugin.
This helps distro packagers avoid having to create a directory with the generic `plugin` name in system locations.

Context: https://github.com/deepmind/mujoco/issues/552
PiperOrigin-RevId: 489011386
Change-Id: Ie9f1748cbb4f2b9dc8c328064caaeb50c88fdec3
2022-11-16 12:40:31 -08:00
Copybara-Service f7b256de91 Merge pull request #419 from aftersomemath:simulate-python
PiperOrigin-RevId: 487496285
Change-Id: I17d15bd2a3886e5ce1631f4eb78afa94830d08cc
2022-11-10 04:12:34 -08:00
Levi Burner 95a4b1c551 simulate python: fix cmake, glfw usage, update Python version of physics loop 2022-10-04 14:37:06 -04:00
Saran Tunyasuvunakool 7072b61cc5 Make Simulate app scan for plugin libraries on launch.
PiperOrigin-RevId: 478502151
Change-Id: I9057e74af4d207cfc551e701134820100bdeee78
2022-10-03 07:47:42 -07:00
Yuval Tassa 834e8dd506 Improvements to time synchronisation in simulate.
- Improved time-sync logic readability in `PhysicsLoop`.
- Fixed unattainable condition for breaking from stepping loop if data was reset.
- Added measurement of actual real-time tracking.
- Moved slowdown overlay to top left.
- Report slowdown as % of real-time, rather than fraction.
- Report actual slowdown if different than requested (very small timestep, PhysicsLoop cannot keep up) by more than 10%.
- Replaced slowdown increments of 2 with decimal-rounded increments of 10^(1/10). This is a finer-grained scale (approximately 3x as fine) and well suited for decimal percentage representation.
- Maximum slowdown increased to 1000.
- Added `Simulate.refreshrate` with a default of 60Hz, in case videomode refreshrate is 0 (can occur e.g. when forwarding over X11).
- Remove realtime reporting from regular info overlay.
- Various cleanups.

PiperOrigin-RevId: 471547481
Change-Id: Idd2514a4defb1dc431617f3a515cc747c4fd8971
2022-09-01 09:09:48 -07:00
Saran Tunyasuvunakool 3240596c3a Call GLFW functions via a dynamic dispatch table.
This allows us to use GLFW without needing to introduce a link-time dependency on the library, which in turn enables us to get GLFW through Python.

PiperOrigin-RevId: 470100999
Change-Id: I27c84ad3310afdbebd582ab0033b6a963ba6307e
2022-08-25 15:41:53 -07:00
Saran Tunyasuvunakool e40b9da181 Merge pull request #201 from aftersomemath:refactor-simulate
PiperOrigin-RevId: 465044152
Change-Id: I54e65a30764a444dbd175260314d685fd7ffa6a1
2022-08-03 15:32:15 +01:00
Levi Burner 70ec29a722 Simulate: fix header includes 2022-07-08 16:04:12 -04:00
Levi Burner a526a6bd78 Simulate: move all glfw calls to main thread to fix MacOS 2022-07-08 16:04:12 -04:00
Levi Burner 1d4461fce6 Simulate: Use new cmake system fix build errors introduced with rebase 2022-07-08 16:04:12 -04:00
Levi Burner 033ca81db6 Simulate: fix reload button causing segfault, make interface changes needed for Python bindings 2022-07-08 16:04:12 -04:00
Levi Burner 447877abef Simulate creates and maintains its own thread 2022-07-08 16:04:12 -04:00
Levi Burner 65d5ade426 Refactor simulate to split UI from application
Fix name of glew library

Move simulate to new directory and refactor to use C++ conventions

Wrap simulate in mujoco namespace

fix namespaces, convert struct to class, use std::lock_guard

use GetMutex to better handle destruction ordering

rename mjSimulate to Simulate

nit: space before public and typo

move startup print

use nullptr instead of NULL

use GetInstance() to get simulate object

convert init to default constructor
2022-07-08 16:04:07 -04:00