forked from google-deepmind/mujoco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmujocoTest.py
More file actions
80 lines (58 loc) · 1.81 KB
/
mujocoTest.py
File metadata and controls
80 lines (58 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import mujoco
import numpy as np
np.set_printoptions(precision=3, suppress=True, linewidth=100)
import mediapy as media
from matplotlib import pyplot as plt
# Testing Mujoco Library
# https://colab.research.google.com/github/deepmind/mujoco/blob/main/python/tutorial.ipynb#scrollTo=eU7uWNsTwmcZ
xml = """
<mujoco>
<worldbody>
<geom name="red_box" type="box" size=".2 .2 .2" rgba="1 0 0 1"/>
<geom name="green_sphere" pos=".2 .2 .2" size=".1" rgba="0 1 0 1"/>
</worldbody>
</mujoco>
"""
model = mujoco.MjModel.from_xml_string(xml)
model.ngeom
print(model.ngeom)
model.geom_rgba
print(model.geom_rgba)
try:
model.geom()
except KeyError as e:
print(e)
model.geom('green_sphere')
print(model.geom('green_sphere'))
model.geom('green_sphere').rgba
print(model.geom('green_sphere').rgba)
id = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_GEOM, 'green_sphere')
model.geom_rgba[id, :]
print(model.geom_rgba[id, :])
print('id of "green_sphere": ', model.geom('green_sphere').id)
print('name of geom 1: ', model.geom(1).name)
print('name of body 0: ', model.body(0).name)
[model.geom(i).name for i in range(model.ngeom)]
print([model.geom(i).name for i in range(model.ngeom)])
data = mujoco.MjData(model)
print(data)
print(data.geom_xpos)
mujoco.mj_kinematics(model, data)
print('raw access:\n', data.geom_xpos)
# MjData also supports named access:
print('\nnamed access:\n', data.geom('green_sphere').xpos)
# Basic rendering, simulation, and animation
# Make model and data
model = mujoco.MjModel.from_xml_string(xml)
data = mujoco.MjData(model)
# Make renderer, render and show the pixels
mujoco.mj_forward(model, data)
renderer = mujoco.Renderer(model)
print(renderer)
print('rendered object:', renderer.__dir__())
print(type(renderer))
'''
while True:
media.show_image(renderer.render())
'''