Mujoco KDL Wrapper  0.2.2
MuJoCo + KDL bridge for robot kinematics and dynamics
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
4The cabinet is a mesh SceneObject (no robot). Headless prints each drawer's
5grasp-site pose; --gui opens it in the wrapper's simulate UI. The drawers are
6passive slide joints -- drag one open in the viewer and it stays put.
7"""
8
9from __future__ import annotations
10
11import argparse
12
13import mj_kdl_wrapper as mjk
14
15GRASPS = ["cabinet_grasp1", "cabinet_grasp2", "cabinet_grasp3"]
16
17
18def cabinet_path() -> str:
19 return mjk.menagerie.asset_path("cabinet/cabinet.xml", env_var="MJ_KDL_CABINET")
20
21
22def 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
36def 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
43def 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
53def 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
69if __name__ == "__main__":
70 raise SystemExit(main())
None run_gui(mjk.Scene scene)
Definition ex_cabinet.py:43
mjk.Scene build_scene()
Definition ex_cabinet.py:22
int main()
Definition ex_cabinet.py:53
None run_headless(mjk.Scene scene)
Definition ex_cabinet.py:36
str cabinet_path()
Definition ex_cabinet.py:18