Commit Graph

26 Commits

Author SHA1 Message Date
Copybara-Service f0ad80f268 Merge pull request #1534 from aftersomemath:simulate-clear-load-error
PiperOrigin-RevId: 618005670
Change-Id: Id2d33463e01dfb4193c1b22155d42c792d5d4f7d
2024-03-21 17:06:47 -07:00
Levi Burner 848e014020 Copybara import of the project:
--
40996ab1a05f328c2b5d1b940abb189d43f646de by Levi Burner <leviburner@gmail.com>:

[Python Viewer] load mjb files, fixes #1421

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/1535 from aftersomemath:simulate-load-mjb 40996ab1a05f328c2b5d1b940abb189d43f646de
PiperOrigin-RevId: 617913250
Change-Id: I09e858495784122c29e0a3895ce43b95010003bc
2024-03-21 11:40:40 -07:00
Levi Burner af38845280 [Python Viewer] clear load error on successful reload, fixes #1116 2024-03-21 12:52:23 -04:00
Saran Tunyasuvunakool a84499e904 Fix non-graceful exiting behaviour in launch_passive.
The viewer currently hard crashes when the user script loops on the passive viewer handle without paying attention to `is_running`. This is considered user error, however this change makes the user script hang on the loop rather than hard crashing.

Startblock:
   diffbase is submitted
PiperOrigin-RevId: 572336261
Change-Id: Id53126a158242b947584da1f946304ae8e792d4a
2023-10-10 12:39:37 -07:00
Saran Tunyasuvunakool a1d0cbd654 Add show_{left,right}_ui kwarg to viewer.launch(_passive).
Fixes #857

PiperOrigin-RevId: 572333909
Change-Id: I12247fe856afddf808eb8f386a594acac47c34b5
2023-10-10 12:31:11 -07: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 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
Saran Tunyasuvunakool 48d0bfde44 Replace glfw.get_time with time.time in the Python viewer timing logic.
PiperOrigin-RevId: 563134207
Change-Id: Ic548701fc78336d8d87e94ea48833f94ee6395b8
2023-09-06 09:52:12 -07:00
Saran Tunyasuvunakool 06b70832ce Add keyboard event callback for Python passive viewer.
Fixes #766
Fixes #846

PiperOrigin-RevId: 549449372
Change-Id: I37d17f1162c66d0e8482d402aae22d9a16b59deb
2023-07-19 15:54:44 -07:00
Saran Tunyasuvunakool f7847ba73e Fix GLFW crash when Python exits while the passive viewer is running.
Fixes #790

PiperOrigin-RevId: 549440435
Change-Id: I808f6aaab6662225e5fe1131e0da72eca6011ba9
2023-07-19 15:20:46 -07:00
Saran Tunyasuvunakool 0ccfef7314 Add update_{hfield,mesh,texture} methods to the passive viewer.
Fixes #812.
Fixes #958.
Fixes #965.

PiperOrigin-RevId: 548181282
Change-Id: I6eb0cd2ce52c66083e83dd08d69e0cfb4178dbba
2023-07-14 11:43:36 -07:00
Nimrod Gileadi 707fcdb44f Correct return type on viewer.launch_passive.
PiperOrigin-RevId: 525753923
Change-Id: Idfff26e89deaeb37dd8b179106640f05c0deabb2
2023-04-20 08:30:42 -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 cefc290eac Reorder arguments of Simulate::Load in Python to match C++.
PiperOrigin-RevId: 523973129
Change-Id: I58760e3e392a208dd8257c340da146aa8f745fb7
2023-04-13 05:22:13 -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 34226bf52d Fix a race condition in launch_passive and launch_repl.
Before this change, these functions can return before an internal call to `mj_forward`, which results in a race condition if the user script then tries to modify the physics state.

Fixes #783
Fixes #790

PiperOrigin-RevId: 523214378
Change-Id: I8a4c6cef0f5d3ec781fd2c5cae3c20dd4b8be67f
2023-04-10 14:35:53 -07:00
Saran Tunyasuvunakool 230e2780de Add viewer.launch_passive and a mjpython launcher for macOS.
The `launch_passive` function launches the GUI viewer in a non-blocking manner, allowing the Python script or REPL to continue execution. The viewer is automatically kept up to date with any subsequent modifications to mjModel and mjData.

Note that when run inside a REPL (including IPython), `launch_passive` is functionally identical to `launch_repl`.

On Linux and Windows, this is achieved by spawning a new thread and launching the GUI there.

On macOS, this is not possible as all Cocoa API calls must be made on the "macOS main thread", which is always the first thread launched in a process and carries the `com.apple.main-thread` dispatch queue. We also cannot simply trampoline from a Python script on the main thread into the user's script on a side thread because CPython's signal handler can only be installed on the "Python main thread". Putting the user's script in a side thread means that it cannot e.g. gracefully handle SIGINT by catching a KeyboardInterrupt exception. To work around this, we ship a custom Python launcher on macOS called `mjpython`. This launcher is a native binary that spawns a pthread and initialize the Python interpreter on that thread, thus allowing "Python main thread" and "macOS main thread" to represent two distinct threads. From Python's point of view, the "macOS main thread" is a secondary thread that runs a loop that continuously empties a Queue of (mjModel, mjData) and launches a viewer.

PiperOrigin-RevId: 517167868
Change-Id: Icac9d2126bbb4760d47e0b9300e0a979cffa4338
2023-03-16 10:53:11 -07:00
Saran Tunyasuvunakool 7d8e810ab1 Fix IPython history corruption when using launch_repl.
PiperOrigin-RevId: 508064761
Change-Id: I58fa2e4f35b57a1ab68c3172ba5c0d4495e40ced
2023-02-08 06:37:42 -08:00
Saran Tunyasuvunakool d022cd1a31 Fix broken launch_repl in the Python viewer.
The REPL functionality was broken in 9fcf3b0c2e.

PiperOrigin-RevId: 501818153
Change-Id: I3fe2f14d78839e63deb43c1017527e7a1cf79e3c
2023-01-13 04:59:22 -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 0d608282dd Fix viewer.py for Python 3.7 and 3.8.
PiperOrigin-RevId: 493301329
Change-Id: I44ffe5b33595d2dec7cd1aefbdd77d535901d894
2022-12-06 07:36:25 -08:00
Saran Tunyasuvunakool 0846f38c82 Rename Python mujoco.simulate to mujoco.viewer.
PiperOrigin-RevId: 492701386
Change-Id: I059c572e2a63bd5529e863a9404720973df8ea46
2022-12-03 10:09:42 -08:00