-
Notifications
You must be signed in to change notification settings - Fork 26
/
test_sims.py
82 lines (61 loc) · 2.18 KB
/
test_sims.py
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
81
import unittest
import os
import mujoco
model_paths = [
# Basic models
"basic/myomuscle.xml",
# finger models
"finger/finger_v0.xml",
"finger/myofinger_v0.xml",
"finger/motorfinger_v0.xml",
# elbow models
"elbow/myoelbow_1dof6muscles_1dofexo.xml",
"elbow/myoelbow_1dof6muscles.xml",
"elbow/myoelbow_2dof6muscles.xml",
"elbow/myoelbow_1dof6muscles_1dofSoftexo_Ideal.xml",
"elbow/myoelbow_1dof6muscles_1dofSoftexo_sim2.xml",
# arms
"arm/myoarm.xml",
# hand models
"hand/myohand.xml",
# leg models
"leg/myolegs.xml",
# torso
"torso/myotorsorigid.xml",
# scene
"scene/myosuite_scene_noPedestal.xml",
"scene/myosuite_scene.xml",
"scene/myosuite_quad.xml",
"scene/myosuite_logo.xml",
]
class TestSims(unittest.TestCase):
def get_sim(self, model_path:str=None, model_xmlstr=None):
"""
Get sim using model_path or model_xmlstr.
"""
# load from path
if model_path:
# resolve full path
if model_path.startswith("/"):
fullpath = model_path
else:
fullpath = os.path.join(os.path.dirname(__file__), model_path)
if not os.path.exists(fullpath):
raise IOError("File %s does not exist" % fullpath)
# load model
if model_path.endswith(".mjb"):
model = mujoco.MjModel.from_binary_path(fullpath)
elif model_path.endswith(".xml"):
model = mujoco.MjModel.from_xml_path(fullpath)
# load from xml string
elif model_xmlstr:
model = mujoco.MjModel.from_xml_path(model_xmlstr)
else:
raise TypeError("Both model_path and model_xmlstr can't be None")
return model
def test_sims(self):
for model_path in model_paths:
print("Testing: {}".format(model_path))
self.get_sim(model_path)
if __name__ == '__main__':
unittest.main()