Mujoco KDL Wrapper
0.2.2
MuJoCo + KDL bridge for robot kinematics and dynamics
Dark
Loading...
Searching...
No Matches
ex_cabinet.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
"""Load the 3-drawer cabinet asset into a robot-less scene.
3
4
The cabinet is a mesh SceneObject (no robot). Headless prints each drawer's
5
grasp-site pose; --gui opens it in the wrapper's simulate UI. The drawers are
6
passive slide joints -- drag one open in the viewer and it stays put.
7
"""
8
9
from
__future__
import
annotations
10
11
import
argparse
12
13
import
mj_kdl_wrapper
as
mjk
14
15
GRASPS = [
"cabinet_grasp1"
,
"cabinet_grasp2"
,
"cabinet_grasp3"
]
16
17
18
def
cabinet_path
() -> str:
19
return
mjk.menagerie.asset_path(
"cabinet/cabinet.xml"
, env_var=
"MJ_KDL_CABINET"
)
20
21
22
def
build_scene
() -> mjk.Scene:
23
cabinet = mjk.SceneObject()
24
cabinet.name =
"cabinet"
25
cabinet.mjcf_path =
cabinet_path
()
26
cabinet.pos = [0.0, 0.0, 0.0]
27
cabinet.fixed =
True
28
spec = mjk.SceneSpec()
29
spec.timestep = 0.002
30
spec.add_floor =
True
31
spec.add_skybox =
True
32
spec.objects = [cabinet]
33
return
mjk.Scene.build(spec)
34
35
36
def
run_headless
(scene: mjk.Scene) ->
None
:
37
scene.step()
38
for
name
in
GRASPS:
39
p = scene.site_frame(name).p
40
print(f
" {name}: world xyz = ({p.x():.3f}, {p.y():.3f}, {p.z():.3f})"
)
41
42
43
def
run_gui
(scene: mjk.Scene) ->
None
:
44
viewer = mjk.SimulateViewer.open(scene,
"ex_cabinet.py"
)
45
try
:
46
while
viewer.is_running():
47
if
not
viewer.step():
48
break
49
finally
:
50
viewer.close()
51
52
53
def
main
() -> int:
54
parser = argparse.ArgumentParser()
55
parser.add_argument(
"--gui"
, action=
"store_true"
, help=
"open the simulate UI"
)
56
args = parser.parse_args()
57
58
scene =
build_scene
()
59
try
:
60
if
args.gui:
61
run_gui
(scene)
62
else
:
63
run_headless
(scene)
64
finally
:
65
scene.close()
66
return
0
67
68
69
if
__name__ ==
"__main__"
:
70
raise
SystemExit(
main
())
ex_cabinet.run_gui
None run_gui(mjk.Scene scene)
Definition
ex_cabinet.py:43
ex_cabinet.build_scene
mjk.Scene build_scene()
Definition
ex_cabinet.py:22
ex_cabinet.main
int main()
Definition
ex_cabinet.py:53
ex_cabinet.run_headless
None run_headless(mjk.Scene scene)
Definition
ex_cabinet.py:36
ex_cabinet.cabinet_path
str cabinet_path()
Definition
ex_cabinet.py:18
python
examples
ex_cabinet.py
Generated by
1.16.1