How to rewrite the reset function in python? when you press the "reset" button in the mujoco viewer window. #3263
Replies: 2 comments
-
|
Yeah, looks like the Reset button just calls import mujoco
mujoco.mj_resetData(model, data) # qpos back to qpos0, and qvel/ctrl/act/mocap/applied-forces zeroed, time back to 0
mujoco.mj_forward(model, data) # recompute everything so the next render looks rightI looked at if (pending_.reset) { // simulate.cc:1950
mj_resetData(m_, d_);
mj_forward(m_, d_);
}Backspace is wired to the exact same thing (the Reset doesn't seem to take you to a keyframe, it always drops you back to the model's default state. If what you're really key_id = 0 # or mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_KEY, "my_keyframe")
mujoco.mj_resetDataKeyframe(model, data, key_id)
mujoco.mj_forward(model, data)I ran both on 3.2.3 (your version) and on 3.4.0 just to be sure, and they behave the same. As far as I know none of these have changed across 3.x Links if you want them: |
Beta Was this translation helpful? Give feedback.
-
|
thanks.
From: nas ***@***.***>
Date: 2026-06-02 10:51:28
To: google-deepmind/mujoco ***@***.***>
Cc: liujianyong001 ***@***.***>,Author ***@***.***>
Subject: Re: [google-deepmind/mujoco] How to rewrite the reset function in python? when you press the "reset" button in the mujoco viewer window. (Discussion #3263)
Yeah, looks like the Reset button just calls mj_resetData and then mj_forward, that's the whole thing. So you can do the same from Python:
import mujoco
mujoco.mj_resetData(model, data) # qpos back to qpos0, and qvel/ctrl/act/mocap/applied-forces zeroed, time back to 0
mujoco.mj_forward(model, data) # recompute everything so the next render looks right
I looked at simulate/simulate.cc. Pressing Reset flips a pending_.reset flag, and then on the physics thread it
runs:
if (pending_.reset) { // simulate.cc:1950
mj_resetData(m_, d_);
mj_forward(m_, d_);
}
Backspace is wired to the exact same thing (the #259 on the button is just the GLFW keycode for Backspace).
Reset doesn't seem to take you to a keyframe, it always drops you back to the model's default state. If what you're really
after is "send me back to keyframe N", that's the Key slider plus Load key button in the viewer, and it's a separate function:
key_id = 0 # or mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_KEY, "my_keyframe")
mujoco.mj_resetDataKeyframe(model, data, key_id)
mujoco.mj_forward(model, data)
I ran both on 3.2.3 (your version) and on 3.4.0 just to be sure, and they behave the same. As far as I know none of these have changed across 3.x
Links if you want them: mj_resetData,
mj_resetDataKeyframe,
mj_forward, and the reset handler in the
source if you want to see it.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Intro
Hi!
I am a ([graduate / undergrad] student / professor / researcher) at XYZ, I use MuJoCo for my research on ABC.
My setup
Ubuntu 22.04.5 LTS;
MuJoCo : 3.2.3
api : python
My question
How to rewrite the reset function in python? when you press the "reset" button in the mujoco viewer window.
Minimal model and/or code that explain my question
If you encountered the issue in a complex model, please simplify it as much as possible (while still reproducing the issue).
Model:
minimal XML
Code:
Confirmations
Beta Was this translation helpful? Give feedback.
All reactions