Closed lucattyy closed 3 weeks ago
You’re trying to mutate a frozen field. You need to use the .at(idx).set(val) semantics.
That's exactly what I did. The .at(idx).set(val) semantics can be used to modify value of MjData.ctrl, but still cannot solve the problem. state.pipeline_state.xfrc_applied = state.pipeline_state.xfrc_applied.at[1, 2].set(75) dataclasses.FrozenInstanceError: cannot assign to field 'xfrc_applied'
Do you mean that MJX do not support external force applied through xfrc_applied currently?
Oh forgot to add that you also need to use the replace
method of the dataclass:
pipeline_state = pipeline_state.replace(xfrc_applied=xfrc_applied.at[1, 2].set(75))
Thx! It really help a lot!
Intro
Hi!
I am a student and I am using MJX for my research on Robotics.
My setup
I am using mujoco-mjx version is 3.1.3 on Ubuntu22.04
What's happening? What did you expect?
I need to apply external force to robot and I discover that parametre 'xfrc_applied' can be checked in mjx, but something wrong happened when I try to modify them.
Traceback (most recent call last): File "/home/pyproject/mjx/scripts/env.py", line 66, in
state = jit_step(state, ctrl)
File "/home/pyproject/mjx/scripts/../env/env.py", line 255, in step
state.pipeline_state.xfrc_applied = state.pipeline_state.xfrc_applied.at[1, 2].set(75)
File "", line 4, in setattr
dataclasses.FrozenInstanceError: cannot assign to field 'xfrc_applied'
It seems that 'xfrc_applied ' has been frozen. Is there any method can help apply external force to robot in MJX?
Confirmations