-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
data.body("...").xpos
does not match data.qpos
#889
Comments
data.body("...") does not match
data.qpos`data.body("...")
does not match data.qpos
Hi! Some clarifications are in order.
Explanation: The purpose of
Does this make sense? |
def test_ant_com():
env = gym.make('Ant-v5', frame_skip=5) # `env` contains `data : MjData` and `model : MjModel`
env.reset() # randomly initlizies the `data.qpos` and `data.qvel`, calls mujoco.mj_forward(env.model, env.data)
x_position_before = env.unwrapped.data.qpos[0]
x_position_before_com = env.unwrapped.data.body("torso").xpos[0]
assert(x_position_before == x_position_before_com), "before failed" # This succeeds
random_control = env.action_space.sample()
_, _, _, _, info = env.step(random_control) # This calls mujoco.mj_step(env.model, env.data, nstep=env.frame_skip)
mujoco.mj_forward(env.unwrapped.model, env.unwrapped.data) # <-- This is new
x_position_after = env.unwrapped.data.qpos[0]
x_position_after_com = env.unwrapped.data.body("torso").xpos[0]
assert(x_position_after == x_position_after_com), "after failed" # This succeeds now
Thanks! |
data.body("...")
does not match data.qpos
data.body("...").xpos
does not match data.qpos
|
One last thing (and the reason I created the unit test, in the first place) Option A: # note `env` holds `data` and `model`
x_position_before = env.data.body("torso").xpos[0]
mujoco.mj_step(env.model, env.data, nstep=env.frame_skip)
# Note: we do not call `mj_kinematics`
x_position_after = env.data.body("torso").xpos[0]
dx = x_position_after - x_position_before # displacement Option B: # note `env` holds `data` and `model`
x_position_before = env.data.qpos[0]
mujoco.mj_step(env.model, env.data, nstep=env.frame_skip)
x_position_after = env.data.qpos[0]
dx = x_position_after - x_position_before # displacement We currently use option A for Thanks! |
Both options are equally accurate, but the second one is more up to date (by 1 timestep). You might legitimately now ask "why would I want a delayed measurement if I can get one that is more up to date?" There are sometimes good reasons for this. For example imagine that you want to compute some value that is a function of your dx and some contact force. Forces are only determined during the step and could not be computed now since they depend on the controls. I.e. contact forces are inherently linked not to a state but a state transition. So while it possible to get some values (i.e. functions only of position and velocity) w.r.t to the current timestep, if you want all your measurements (including force/acc related quantities) to be correctly "synced", you have to pay the price of a delay of 1 timestep. In your case you may not care, but in general this can be important. Hope this makes sense. |
Hi,
I'm a maintainer of
Gymnasium-Robotics
and I'm trying to use MuJoCo to develop thev5
revision of theGymansium/mujoco
RL environments Farama-Foundation/Gymnasium-Robotics#104.I'm looking for some help with understanding why the following unit test fails.
data.qpos[0] == data.body("torso").xpos[0]
is truebut after steeping the
MuJoCo
modeldata.qpos[0] == data.body("torso").xpos[0]
is FalseHere is a model which explains my question:
The
Ant.xml
inGymnasium/MuJoCo/Ant
environmenthttps://github.com/Farama-Foundation/Gymnasium/blob/main/gymnasium/envs/mujoco/assets/ant.xml
Here is a unit test illustrating my question:
Note: this is the case for other
body.xpos
&body.xquat
Is this normal/expected?
The text was updated successfully, but these errors were encountered: