mujoco-python-viewer icon indicating copy to clipboard operation
mujoco-python-viewer copied to clipboard

Full Reload of Sim without closing window?

Open rohit-kumar-j opened this issue 2 years ago • 2 comments

This might be a breaking change:

# pass in the xml path to the viewer directly and upon KEY_BACKSPACE, reload the sim
viewer = viewer.MujocoViewer(xml_path="Projects/rjax_python/robots/humanoid/scene.xml")
while True:
        mujoco.mj_step(viewer.model, viewer.data)
        viewer.render()

Each time the model and data have to be accessed, they have to be done via viewer.model and viewer.data. The examples, etc need to change. Would this PR be okay? (Of course, the changes will be reflected in the README and examples)

Need for this/Use case:

No relaunching of the python script for .xml tweaking, no need to use simulate.cc for the same

Implementation Example:

https://user-images.githubusercontent.com/37873142/192229058-3711d7ab-b69c-46c0-b6b3-998364ce704f.mp4

(If the video stops in the middle, kindly scrub manually to the end. The video may be corrupted)

rohit-kumar-j avatar Sep 26 '22 08:09 rohit-kumar-j

Thanks for the nice demo @rohit-kumar-j ! Yes, it's quite a big change (and I'm still looking at your other PR, sorry for the delay).

Don't you think it's better to let simulate.cc handle features like this? As far as I know, there are soon going to be python bindings for simulate.cc, which would make this a redundant feature. What do you think?

rohanpsingh avatar Sep 26 '22 08:09 rohanpsingh

Yes, simualte.cc's python counterpart might most likely be able better to handle features like reloading simulation. Perhaps this would be only temporary.

I guess I haven't explained my reasoning for #23, especially in the context of the new simulate.cc viewer's implementation in python. I hope I can faithfully do so here:

I don't see this repo a replica of simulate.cc's. I see this as a more easy-to-use and functional viewer as opposed to feature loaded (like simulate). There are a few things that I have noticed when developing/preparing xml files (I guess this is more of a workflow thing than a number of features in thing, Hence all the PRs 😅)

  • simulate.cc has too many options which clutter the window(of course we can close this with Tab and turn features on or off by clicking on them), Not sure how this will be handled within the new simulate(.py?/.so?) .
  • When implementing/testing a Stable-PD strategy, It was necessary to use the force visualization and the graphing utilities to be able to see what happens especially at boundary conditions(eg: contact with the floor, force is applied but the end effector does not move).
  • It was also necesssary to graph multiple things including internally and exteranlly generated signals(like sinewaves), preferablly with a time-axis.
  • While editing the XML file, It was tedious to restart the script each time instead of just reloading the model and data. This was especially useful while attending to minor modifications required the robot file.(For example modifying the location of sites or joint limits and viewing while script executes) (This issue)
  • For launching multiple scripts, it made sense to pre-position the windows in a fixed location instead of manually repositioning them.(Will soon add a demo below)

PS: I have not seen the src code/used the python version of the simulate.cc. (perhaps it is this.)

rohit-kumar-j avatar Sep 29 '22 12:09 rohit-kumar-j