Created
February 9, 2018 19:40
-
-
Save machinaut/9bd1473c763554086c176d39062700b0 to your computer and use it in GitHub Desktop.
mujoco-py - Change Model Parameters on the Fly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import numpy as np | |
from mujoco_py import load_model_from_xml, MjSim, MjViewer | |
XML = ''' | |
<mujoco> | |
<worldbody> | |
<geom name='floor' pos='0 0 0' size='5 5 .125' type='plane' condim='3'/> | |
<body name='ball' pos='0 0 1'> | |
<joint type='free'/> | |
<geom name='ball' pos='0 0 0' size='.1' type='sphere' rgba='1 0 0 1'/> | |
</body> | |
</worldbody> | |
</mujoco> | |
''' | |
model = load_model_from_xml(XML) | |
sim = MjSim(model) | |
viewer = MjViewer(sim) | |
while True: | |
sim.model.opt.gravity[0] = np.sin(time.time()) | |
sim.model.opt.gravity[1] = np.cos(time.time()) | |
sim.step() | |
viewer.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment