How to properly update the default classes with new MjSpec workflow #2197
-
IntroHi! I am a grad student at FSU working on different robot designs and using MuJoCo to help with feasibility analysis and motor selection. My setupI am using the python api for mujoco and I am using the basic "viewer" method as shown in the Python examples My questionI am trying to adjust the default classes in my robot's XML file using the MjSpec workflow, but nothing is updating. I can find the default class I need, but whenever I rewrite the value and recompile, nothing about the model changes. I am starting with simple changes to my geometry masses, but would eventually like to be able to update joint armatures as different motor models are plugged in. Another, side issue I am having, is that I am loading in my entire "scene" xml file into MjSpec and then recompiling. I can separate this into two MjModels, but I haven't found much documentation for how to load both into the simulation at the same time. The viewer takes a single model and data object so I'm not sure how to add more. Right now I only care about adding in a ground plane and a few obstacles in the scene. The robot is described in a separate XML. I can find all of the parameters I want to change, but they are not changing when I recompile. Minimal model and/or code that explain my questionHere are some of the default classes in my xml that I want to adjust in code:
In my python file I have tried the following:
and
After running Confirmations
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I too have a similar issue when I use mjSpec to edit the model. One thing I noticed is that the model in simulation does not seem to change until a new instance of viewer is created. Here is what I did to change the color of simple model. I loaded and compiled the model using mjSpec, simulated it for 300 simulation seconds and closed the simulation, changed the model parameters using spec and then opened a new simulation instance to simulate with the new changes compiled. Only this way I am able see the changes of the model in simulation. However, I feel like this is not the best way to do it but I see that the simulation instance is not able see the changes in the model as the instance is instantiated with the original model. spec = mujoco.MjSpec().from_file("test.xml")
model = spec.compile()
data = mujoco.MjData(model)
with mujoco.viewer.launch_passive(model, data) as viewer:
# Reset the simulation.
mujoco.mj_resetData(model, data)
while data.time < 300:
mujoco.mj_step(model, data)
viewer.sync()
spec.geoms[0].rgba = np.array([1.,1.,0,1.])
model, data = spec.recompile(model, data)
with mujoco.viewer.launch_passive(model, data) as viewer:
# Reset the simulation.
mujoco.mj_resetData(model, data)
while viewer.is_running():
mujoco.mj_step(model, data)
viewer.sync() Here is the <mujoco>
<worldbody>
<light name="top" pos="0 0 1"/>
<body name="box_and_sphere" euler="0 0 -30">
<joint name="swing" type="hinge" axis="1 -1 0" pos="-.2 -.2 -.2"/>
<geom name="red_box" type="box" size=".2 .2 .2" rgba="1 0 0 1"/>
<geom name="green_sphere" pos=".2 .2 .2" size=".1" rgba="0 1 0 1"/>
</body>
</worldbody>
</mujoco> I guess there is a better way to do it. I am not sure if it is limited by the simulator. I could not find any documention explaining the changing of model on the fly, rather found documentation about loading a model, changing it and then compiling it. |
Beta Was this translation helpful? Give feedback.
-
Hi, defaults should be considered an "initializer", not something that can updated once they are used for creating an object. Maybe we will add the functionality in the future, but for now you should consider them as a const object. |
Beta Was this translation helpful? Give feedback.
-
Detailed answer now live in the docs: https://mujoco.readthedocs.io/en/latest/programming/modeledit.html#default-classes |
Beta Was this translation helpful? Give feedback.
Detailed answer now live in the docs:
https://mujoco.readthedocs.io/en/latest/programming/modeledit.html#default-classes