本文整理汇总了Python中mujoco_py.load_model_from_xml函数的典型用法代码示例。如果您正苦于以下问题:Python load_model_from_xml函数的具体用法?Python load_model_from_xml怎么用?Python load_model_from_xml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_model_from_xml函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_userdata
def test_userdata(self):
xml = '''
<mujoco>
<size nuserdata="{}"/>
<worldbody>
<body pos="0 0 0">
<joint type="free"/>
<geom type="sphere" size=".1"/>
</body>
</worldbody>
</mujoco>
'''
model = load_model_from_xml(xml.format(1))
assert model.nuserdata == 1, 'bad nuserdata {}'.format(model.nuserdata)
model = load_model_from_xml(xml.format(10))
assert model.nuserdata == 10, 'bad nuserdata {}'.format(model.nuserdata)
sim = MjSim(model)
data = sim.data
assert data.userdata[0] == 0, 'bad userdata {}'.format(data.userdata)
data.userdata[0] = 1
assert data.userdata[0] == 1, 'bad userdata {}'.format(data.userdata)
# Check that we throw an assert if there's not enough userdata
model = load_model_from_xml(xml.format(0))
with self.assertRaises(AssertionError):
model.set_userdata_names(['foo'])
# Doesn't throw assert
model = load_model_from_xml(xml.format(1))
model.set_userdata_names(['foo'])
with self.assertRaises(AssertionError):
model.set_userdata_names(['foo', 'bar'])
开发者ID:openai,项目名称:mujoco-py,代码行数:30,代码来源:test_cymj.py
示例2: test_model_save_load
def test_model_save_load():
model = load_model_from_xml(BASIC_MODEL_XML)
xml_from_model = model.get_xml()
model_from_xml = load_model_from_xml(xml_from_model)
assert(xml_from_model == model_from_xml.get_xml())
mjb_from_model = model.get_mjb()
model_from_mjb = load_model_from_mjb(mjb_from_model)
assert(mjb_from_model == model_from_mjb.get_mjb())
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:8,代码来源:test_cymj.py
示例3: test_rendering
def test_rendering():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
img, depth = sim.render(200, 200, depth=True)
assert img.shape == (200, 200, 3)
compare_imgs(img, 'test_rendering.freecam.png')
depth = (depth - np.min(depth)) / (np.max(depth) - np.min(depth))
depth = np.asarray(depth * 255, dtype=np.uint8)
assert depth.shape == (200, 200)
compare_imgs(depth, 'test_rendering.freecam.depth.png')
img = sim.render(100, 100, camera_name="camera1")
assert img.shape == (100, 100, 3)
compare_imgs(img, 'test_rendering.camera1.png')
img = sim.render(200, 100, camera_name="camera1")
assert img.shape == (100, 200, 3)
compare_imgs(img, 'test_rendering.camera1.narrow.png')
render_context = sim.render_contexts[0]
render_context.add_marker(size=np.array([.4, .5, .6]),
pos=np.array([.4, .5, .6]),
rgba=np.array([.7, .8, .9, 1.0]),
label="mark")
img = sim.render(200, 200, camera_name="camera1")
assert img.shape == (200, 200, 3)
compare_imgs(img, 'test_rendering_markers.camera1.png')
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:30,代码来源:test_cymj.py
示例4: test_data_attribute_getters
def test_data_attribute_getters():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
assert_array_equal(sim.data.get_body_xpos("body1"), [0, 0, 1])
with pytest.raises(ValueError):
sim.data.get_body_xpos("body_foo")
with pytest.raises(RuntimeError):
sim.data.get_xpos("body1")
assert len(sim.data.get_body_xquat("body1")) == 4
assert_array_equal(sim.data.get_body_xmat("body1").shape, (3, 3))
# At (0, 1, 1) since the geom is displaced in the body
assert_array_equal(sim.data.get_body_xipos("body1"), [0, 1, 1])
assert_array_equal(sim.data.get_site_xpos("site1"), [1, 0, 1])
assert_array_equal(sim.data.get_site_xmat("site1").shape, (3, 3))
assert_array_equal(sim.data.get_geom_xpos("geom1"), [0.5, 0.4, 0.3])
assert_array_equal(sim.data.get_geom_xpos("geom2"), [0, 1, 1])
assert_array_equal(sim.data.get_geom_xmat("geom2").shape, (3, 3))
assert_array_equal(sim.data.get_light_xpos("light1"), [0, 0, 3])
assert_array_equal(sim.data.get_light_xdir("light1"), [0, 0, -1])
assert_array_equal(sim.data.get_camera_xpos("camera1"), [3, 0, 0])
assert_array_equal(sim.data.get_camera_xmat("camera1").shape, (3, 3))
assert_array_equal(sim.data.get_joint_xaxis("joint1"), [0, 0, 1])
assert_array_equal(sim.data.get_joint_xanchor("joint1"), [0, 0, 1])
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:27,代码来源:test_cymj.py
示例5: test_concurrent_rendering
def test_concurrent_rendering():
'''Best-effort testing that concurrent multi-threaded rendering works.
The test has no guarantees around being deterministic, but if it fails
you know something is wrong with concurrent rendering. If it passes,
things are probably working.'''
err = None
def func(sim, event):
event.wait()
sim.data.qpos[:] = 0.0
sim.forward()
img1 = sim.render(width=40, height=40, camera_name="camera1")
img2 = sim.render(width=40, height=40, camera_name="camera2")
try:
assert np.sum(img1[:]) == 23255
assert np.sum(img2[:]) == 12007
except Exception as e:
nonlocal err
err = e
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.render(100, 100)
event = Event()
threads = []
for _ in range(100):
thread = Thread(target=func, args=(sim, event))
threads.append(thread)
thread.start()
event.set()
for thread in threads:
thread.join()
assert err is None, "Exception: %s" % (str(err))
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:32,代码来源:test_cymj.py
示例6: test_multiple_sims
def test_multiple_sims():
# Ensure that creating new simulators still produces good renderings.
xml = """
<mujoco>
<asset>
<texture name="t1" width="32" height="32" type="2d" builtin="flat" />
<material name="m1" texture="t1" />
</asset>
<worldbody>
<light diffuse=".5 .5 .5" pos="0 0 5" dir="0 0 -1" />
<camera name="topcam" pos="0 0 2.5" zaxis="0 0 1" />
<geom name="g1" pos="0 0 0" type="box" size="1 1 0.1" rgba="1 1 1 1" material="m1" />
</worldbody>
</mujoco>
"""
model = load_model_from_xml(xml)
random_state = np.random.RandomState(0)
for i in range(3):
sim = MjSim(model)
sim.forward()
modder = TextureModder(sim, random_state=random_state)
for j in range(2):
modder.rand_checker('g1')
compare_imgs(
sim.render(201, 205, camera_name="topcam"),
'test_multiple_sims.loop%d_%d.png' % (i, j))
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:28,代码来源:test_modder.py
示例7: test_rendering
def test_rendering():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
img, depth = sim.render(200, 200, depth=True)
assert img.shape == (200, 200, 3)
compare_imgs(img, 'test_rendering.freecam.png')
depth = (depth - np.min(depth)) / (np.max(depth) - np.min(depth))
depth = np.asarray(depth * 255, dtype=np.uint8)
assert depth.shape == (200, 200)
# Unfortunately mujoco 2.0 renders slightly different depth image on mac and on linux here
if "darwin" in sys.platform.lower():
compare_imgs(depth, 'test_rendering.freecam.depth-darwin.png')
else:
compare_imgs(depth, 'test_rendering.freecam.depth.png')
img = sim.render(100, 100, camera_name="camera1")
assert img.shape == (100, 100, 3)
compare_imgs(img, 'test_rendering.camera1.png')
img = sim.render(200, 100, camera_name="camera1")
assert img.shape == (100, 200, 3)
compare_imgs(img, 'test_rendering.camera1.narrow.png')
render_context = sim.render_contexts[0]
render_context.add_marker(size=np.array([.4, .5, .6]),
pos=np.array([.4, .5, .6]),
rgba=np.array([.7, .8, .9, 1.0]),
label="mark")
img = sim.render(200, 200, camera_name="camera1")
assert img.shape == (200, 200, 3)
compare_imgs(img, 'test_rendering_markers.camera1.png')
开发者ID:openai,项目名称:mujoco-py,代码行数:35,代码来源:test_cymj.py
示例8: test_ignore_mujoco_warnings
def test_ignore_mujoco_warnings():
# Two boxes on a plane need more than 1 contact (nconmax)
xml = '''
<mujoco>
<size nconmax="1"/>
<worldbody>
<geom type="plane" size="1 1 0.1"/>
<body pos="1 0 1"> <joint type="free"/> <geom size="1"/> </body>
<body pos="0 1 1"> <joint type="free"/> <geom size="1"/> </body>
</worldbody>
</mujoco>
'''
model = load_model_from_xml(xml)
sim = MjSim(model)
sim.reset()
with ignore_mujoco_warnings():
# This should raise an exception due to the mujoco warning callback,
# but it's suppressed by the context manager.
sim.step()
sim.reset()
with pytest.raises(Exception):
# test to make sure previous warning callback restored.
sim.step()
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:25,代码来源:test_cymj.py
示例9: test_high_res
def test_high_res():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
img = sim.render(1000, 1000)
img = np.array(Image.fromarray(img).resize(size=(200, 200)))
assert img.shape == (200, 200, 3)
compare_imgs(img, 'test_rendering.freecam.png')
开发者ID:openai,项目名称:mujoco-py,代码行数:8,代码来源:test_cymj.py
示例10: test_mj_sim_pool_basics
def test_mj_sim_pool_basics():
model = load_model_from_xml(BASIC_MODEL_XML)
sims = [MjSim(model) for _ in range(2)]
sim_pool = MjSimPool(sims, nsubsteps=2)
sim_pool.reset()
sim_pool.step()
sim_pool.forward()
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:8,代码来源:test_cymj.py
示例11: test_high_res
def test_high_res():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
img = sim.render(1000, 1000)
img = scipy.misc.imresize(img, (200, 200, 3))
assert img.shape == (200, 200, 3)
compare_imgs(img, 'test_rendering.freecam.png')
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:8,代码来源:test_cymj.py
示例12: test_mj_sim_basics
def test_mj_sim_basics():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model, nsubsteps=2)
sim.reset()
sim.step()
sim.reset()
sim.forward()
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:8,代码来源:test_cymj.py
示例13: test_many_sims_rendering
def test_many_sims_rendering():
model = load_model_from_xml(BASIC_MODEL_XML)
sims = [MjSim(model) for _ in range(5)]
pool = MjSimPool(sims)
pool.forward()
for sim in sims:
img, depth = sim.render(200, 200, depth=True)
assert img.shape == (200, 200, 3)
compare_imgs(img, 'test_rendering.freecam.png')
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:9,代码来源:test_cymj.py
示例14: test_sim_save
def test_sim_save():
model = load_model_from_xml(BASIC_MODEL_XML)
assert model.nkey == 0
sim = MjSim(model)
with StringIO() as f:
sim.save(f)
f.seek(0)
loaded_model = load_model_from_xml(f.read())
assert loaded_model.nkey == 1
with BytesIO() as f:
sim.save(f, format='mjb')
f.seek(0)
loaded_model = load_model_from_mjb(f.read())
assert loaded_model.nkey == 1
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:19,代码来源:test_cymj.py
示例15: test_viewercontext
def test_viewercontext():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
renderer = cymj.MjRenderContext(sim, offscreen=True)
renderer.add_marker(type=const.GEOM_SPHERE,
size=np.ones(3) * 0.1,
pos=np.zeros(3),
mat=np.eye(3).flatten(),
rgba=np.ones(4),
label="mark")
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:11,代码来源:test_cymj.py
示例16: test_read_depth_buffer
def test_read_depth_buffer():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
ctx = MjRenderContext(sim, offscreen=True, opengl_backend='glfw')
buf = np.zeros((11, 100), dtype=np.float32)
assert buf.sum() == 0, f'{buf.sum()}'
ctx.render(buf.shape[1], buf.shape[0], 0)
ctx.read_pixels_depth(buf)
assert buf.sum() != 0, f'{buf.sum()} {buf.max()}'
开发者ID:openai,项目名称:mujoco-py,代码行数:12,代码来源:test_opengl_context.py
示例17: test_mj_sim_buffers
def test_mj_sim_buffers():
model = load_model_from_xml(BASIC_MODEL_XML)
# test no callback
sim = MjSim(model, nsubsteps=2)
assert(sim.udd_state == {})
sim.step()
assert(sim.udd_state == {})
# test with callback
foo = 10
d = {"foo": foo,
"foo_2": np.array([foo, foo])}
def udd_callback(sim):
return d
sim = MjSim(model, nsubsteps=2, udd_callback=udd_callback)
assert(sim.udd_state is not None)
assert(sim.udd_state["foo"] == foo)
assert(sim.udd_state["foo_2"].shape[0] == 2)
assert(sim.udd_state["foo_2"][0] == foo)
foo = 11
d = {"foo": foo,
"foo_2": np.array([foo, foo])}
sim.step()
assert(sim.udd_state is not None)
assert(sim.udd_state["foo"] == foo)
assert(sim.udd_state["foo_2"][0] == foo)
d = {}
with pytest.raises(AssertionError):
sim.step()
d = {"foo": foo,
"foo_2": np.array([foo, foo]),
"foo_3": foo}
with pytest.raises(AssertionError):
sim.step()
d = {"foo": foo,
"foo_2": np.array([foo, foo, foo])}
with pytest.raises(AssertionError):
sim.step()
d = {"foo": "haha",
"foo_2": np.array([foo, foo, foo])}
with pytest.raises(AssertionError):
sim.step()
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:52,代码来源:test_cymj.py
示例18: test_textures
def test_textures():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_textures.premod.png')
random_state = np.random.RandomState(0)
modder = TextureModder(sim, random_state=random_state)
modder.whiten_materials()
modder.whiten_materials(['g1', 'g2'])
modder.set_rgb('g1', (255, 0, 0))
modder.set_rgb('g2', (0, 255, 0))
modder.set_rgb('g3', (0, 0, 255))
modder.set_rgb('g4', (255, 0, 255))
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_textures.rgb.png')
modder.set_checker('g1', (255, 0, 0), (0, 255, 0))
modder.set_gradient('g2', (0, 255, 0), (0, 0, 255), vertical=True)
modder.set_gradient('g3', (255, 255, 0), (0, 0, 255), vertical=False)
modder.set_noise('g4', (0, 0, 255), (255, 0, 0), 0.1)
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_textures.variety.png')
modder.rand_checker('g1')
modder.rand_gradient('g2')
modder.rand_noise('g3')
modder.rand_rgb('g4')
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_textures.rand_specific.png')
modder.rand_all('g1')
modder.rand_all('g2')
modder.rand_all('g3')
modder.rand_all('g4')
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_textures.rand_all.png')
modder.rand_checker('g1')
modder.rand_checker('g2')
modder.rand_checker('g3')
modder.rand_checker('g4')
mat_modder = MaterialModder(sim, random_state=random_state)
mat_modder.rand_texrepeat('g1')
mat_modder.rand_texrepeat('g2')
mat_modder.rand_texrepeat('g3')
mat_modder.rand_texrepeat('g4')
compare_imgs(sim.render(201, 205, camera_name="topcam"),
'test_textures.rand_texrepeat.png')
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:52,代码来源:test_modder.py
示例19: test_glfw_context
def test_glfw_context():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
render_context = MjRenderContext(sim, offscreen=True, opengl_backend='glfw')
assert len(sim.render_contexts) == 1
assert sim.render_contexts[0] is render_context
assert isinstance(render_context.opengl_context, GlfwContext)
compare_imgs(sim.render(201, 205, camera_name="topcam"), 'test_glfw_context.png')
assert len(sim.render_contexts) == 1
assert sim.render_contexts[0] is render_context
开发者ID:openai,项目名称:mujoco-py,代码行数:13,代码来源:test_opengl_context.py
示例20: test_joint_qpos_qvel_ops
def test_joint_qpos_qvel_ops():
model = load_model_from_xml(BASIC_MODEL_XML)
sim = MjSim(model)
sim.forward()
# Test setting one with a list
sim.data.set_joint_qpos("joint1", [1, 2, 3, 1, 0, 0, 0])
# And the other with an np.ndarray
sim.data.set_joint_qvel("joint1", np.array([1, 2, 3, 0.1, 0.1, 0.1]))
sim.forward()
assert_array_equal(sim.data.get_joint_qpos(
"joint1"), [1, 2, 3, 1, 0, 0, 0])
assert_array_equal(sim.data.get_joint_qvel(
"joint1"), [1, 2, 3, 0.1, 0.1, 0.1])
开发者ID:m-j-mcdonald,项目名称:mujoco-py,代码行数:14,代码来源:test_cymj.py
注:本文中的mujoco_py.load_model_from_xml函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论