openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.86k stars 816 forks source link

Is there and equivalent to "simulate.cpp" in Mujoco-Py? #248

Closed kaelgabriel closed 5 years ago

kaelgabriel commented 6 years ago

Hi there guys!

Is there an equivalent to the code simulate.cpp, generally located in ~/.mujoco/mujocopro151/sample (or the binary on /bin) in mujoco-py?

It would be nice to be able to change features in the simulation while the training model is in the "test phase", something like V-REP.

Thanks for your time.

cyrilzakka commented 5 years ago

If I'm understanding your question correctly you're trying to render an XML file using mujoco-py. Is that correct? In that case please try the following:

import mujoco_py
import os

mj_path, _ = mujoco_py.utils.discover_mujoco()
xml_path = os.path.join(mj_path, 'model', 'FULL_PATH_TO_FOLDER_CONTAINING_XML/pick_and_place.xml')

model = mujoco_py.load_model_from_path(xml_path)
sim = mujoco_py.MjSim(model)

rend = mujoco_py.MjViewer(sim)

for _ in range(10000):
    sim.step()
    rend.render()

Please refer to the following documentation for more information on sampling and such: https://openai.github.io/mujoco-py/build/html/index.html

machinaut commented 5 years ago

@kaelgabriel you can change the simulation while it is running, but there is not a specially-made interactive user program written with mujoco-py that I know of.

You can re-implement simulate.cpp yourself using the mujoco_py.functions object to access internal functions, and manually use ctypes objects (including pointers, etc) where the interfaces require C-type data structures.

I'd be interested in reviewing a pull request for an example of this if one was provided.

Closing for now, as I think the question is answered.

kaelgabriel commented 5 years ago

Thanks for the replies. I will try to replicate using a something like a "wrapper" for the original library.