How to use mujoco-py to run various .xml files of the model #2437
Replies: 6 comments
-
Hi, I am a MuJoCo user, You should use the official Python bindings instead of mujoco-py You may download the introductory tutorial and run it offline (after some editing)/write your own Python file with its help: |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply! import time m = mujoco.MjModel.from_xml_path('/home/zl/Mujoco/mujoco327/mujoco327/model/flex/floppy.xml') with mujoco.viewer.launch_passive(m, d) as viewer: Close the viewer automatically after 30 wall-seconds.start = time.time()
|
Beta Was this translation helpful? Give feedback.
-
~/.mujoco/mujoco_327/bin$ ./simulate /home/zl/Mujoco/mujoco327/mujoco327/model/flex/floppy.xml Very good ! |
Beta Was this translation helpful? Give feedback.
-
<!-- Copyright 2021 DeepMind Technologies Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<mujoco model="Floppy">
<include file="scene.xml"/>
<compiler autolimits="true"/>
<option solver="CG" tolerance="1e-6" timestep=".001"/>
<size memory="100M"/>
<visual>
<map stiffness="100"/>
</visual>
<worldbody>
<flexcomp type="grid" count="24 4 4" spacing=".1 .1 .1" pos=".1 0 1.5"
radius=".0" rgba="0 .7 .7 1" name="softbody" dim="3" mass="25">
<contact condim="3" solref="0.01 1" solimp=".95 .99 .0001" selfcollide="none"/>
<elasticity young="5e4" damping="0.002" poisson="0.2"/>
</flexcomp>
<body>
<joint name="hinge" pos="0 0 .5" axis="0 1 0" damping="50"/>
<geom type="cylinder" size=".4" fromto="0 -.5 .5 0 .5 .5" density="300"/>
</body>
</worldbody>
<actuator>
<motor name="cylinder" joint="hinge" gear="1 0 0 0 0 0" ctrlrange="-100 100"/>
</actuator>
</mujoco>
Code: import time
import mujoco
import mujoco.viewer
m = mujoco.MjModel.from_xml_path('/home/zl/Mujoco/mujoco327/mujoco327/model/flex/floppy.xml')
d = mujoco.MjData(m)
with mujoco.viewer.launch_passive(m, d) as viewer:
start = time.time()
while viewer.is_running() and time.time() - start < 30:
step_start = time.time()
# mj_step can be replaced with code that also evaluates
# a policy and applies a control signal before stepping the physics.
mujoco.mj_step(m, d)
# Example modification of a viewer option: toggle contact points every two seconds.
with viewer.lock():
viewer.opt.flags[mujoco.mjtVisFlag.mjVIS_CONTACTPOINT] = int(d.time % 2)
# Pick up changes to the physics state, apply perturbations, update options from GUI.
viewer.sync()
# Rudimentary time keeping, will drift relative to wall clock.
time_until_next_step = m.opt.timestep - (time.time() - step_start)
if time_until_next_step > 0:
time.sleep(time_until_next_step) |
Beta Was this translation helpful? Give feedback.
-
The above is the code I use, looking forward to anyone's reply, thank you! |
Beta Was this translation helpful? Give feedback.
-
Your code seems to have some problems with it. Regardless, you can open an issue because the simulation is breaking for me (for flexible models) as well when I use the Python viewer Please |
Beta Was this translation helpful? Give feedback.
-
Intro
Hi!
I am a graduate student at HIT, I use MuJoCo for my research on robot control.
My setup
mujoco 3.2.7 python ubuntu22.04
My question
I downloaded the latest version of mujoco3.2.7. I can use /bin/simulate to run various .xml files of the model, but I want to run these programs using python programs, but an error will be reported.
Minimal model and/or code that explain my question
import mujoco_py
from mujoco_py import load_model_from_path, MjSim
model = load_model_from_path("~/.mujoco/mujoco327/model/humanoid.xml")
sim = MjSim(model)
print("MuJoCo version:", sim.model.opt.timestep)
error:
You appear to be missing MuJoCo. We expected to find the file here: /home/zl/.mujoco/mujoco210
This package only provides python bindings, the library must be installed separately.
Please follow the instructions on the README to install MuJoCo
Confirmations
Beta Was this translation helpful? Give feedback.
All reactions