Skip to content

Commit bb0252f

Browse files
Add show_in_pybullet command
1 parent b7400fb commit bb0252f

File tree

4 files changed

+87
-4
lines changed

4 files changed

+87
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ All notable changes to this project will be documented in this file.
1111
- Description: Robot Soccer Kit
1212
- Description: Robotiq 2F-85 (MJCF V4) (thanks to @peterdavidfagan)
1313
- CLI: Add `show_in_meshcat` command
14+
- CLI: Add `show_in_mujoco` command
15+
- CLI: Add `show_in_pybullet` command
1416

1517
### Changed
1618

1719
- Enable command-line to run from `python -m robot_descriptions`
20+
- CLI: Rename `show` command to `show_in_yourdfpy`
1821

1922
### Fixed
2023

examples/show_in_meshcat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"""
88
Show a robot descriptions, specified from the command line, using MeshCat.
99
10-
This example requires Pinocchio, installed by e.g. `conda install pinocchio`,
11-
and MeshCat, which is installed by `pip install meshcat`.
10+
This example is equivalent to `python -m robot_descriptions show_in_meshcat`.
11+
It requires Pinocchio, installed by e.g. `conda install pinocchio`, and
12+
MeshCat, installed by e.g. `conda install meshcat-python`.
1213
"""
1314

1415
import argparse

examples/show_in_mujoco.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"""
88
Show a robot description, specified from the command line, using MuJoCo.
99
10-
This example requires MuJoCo, which is installed by `pip install mujoco`, and
11-
the MuJoCo viewer installed by `pip install mujoco-python-viewer`.
10+
This example is equivalent to `python -m robot_descriptions show_in_mujoco`. It
11+
requires MuJoCo, which is installed by `pip install mujoco`, and the MuJoCo
12+
viewer installed by `pip install mujoco-python-viewer`.
1213
"""
1314

1415
import argparse

robot_descriptions/__main__.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ def get_argument_parser() -> argparse.ArgumentParser:
5858
help="name of the robot description",
5959
)
6060

61+
# show_in_mujoco --------------------------------------------------------
62+
parser_mujoco = subparsers.add_parser(
63+
"show_in_mujoco",
64+
help="load and display a given robot description in mujoco",
65+
)
66+
parser_mujoco.add_argument(
67+
"name",
68+
help="name of the robot description",
69+
)
70+
71+
# show_in_pybullet --------------------------------------------------------
72+
parser_pybullet = subparsers.add_parser(
73+
"show_in_pybullet",
74+
help="load and display a given robot description in pybullet",
75+
)
76+
parser_pybullet.add_argument(
77+
"name",
78+
help="name of the robot description",
79+
)
80+
6181
# show_in_yourdfpy --------------------------------------------------------
6282
parser_yourdfpy = subparsers.add_parser(
6383
"show_in_yourdfpy",
@@ -134,6 +154,60 @@ def show_in_meshcat(name: str) -> None:
134154
input("Press Enter to close MeshCat and terminate... ")
135155

136156

157+
def show_in_mujoco(name: str) -> None:
158+
"""Show a robot description in MuJoCo.
159+
160+
Args:
161+
name: Name of the robot description.
162+
"""
163+
import mujoco
164+
165+
try:
166+
import mujoco_viewer
167+
except ImportError as e:
168+
raise ImportError(
169+
"MuJoCo viewer not found, "
170+
"try `pip install mujoco-python-viewer`"
171+
) from e
172+
173+
from robot_descriptions.loaders.mujoco import load_robot_description
174+
175+
try:
176+
model = load_robot_description(name)
177+
except ModuleNotFoundError:
178+
model = load_robot_description(f"{name}_mj_description")
179+
180+
data = mujoco.MjData(model)
181+
viewer = mujoco_viewer.MujocoViewer(model, data)
182+
mujoco.mj_step(model, data) # step at least once to load model in viewer
183+
while viewer.is_alive:
184+
viewer.render()
185+
viewer.close()
186+
187+
188+
def show_in_pybullet(name: str) -> None:
189+
"""Show a robot description in PyBullet.
190+
191+
Args:
192+
name: Name of the robot description.
193+
"""
194+
import pybullet
195+
196+
from robot_descriptions.loaders.pybullet import load_robot_description
197+
198+
pybullet.connect(pybullet.GUI)
199+
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_SHADOWS, 0)
200+
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_GUI, 0)
201+
202+
try:
203+
load_robot_description(name)
204+
except ModuleNotFoundError:
205+
load_robot_description(f"{name}_description")
206+
207+
input("Press Enter to close PyBullet and terminate... ")
208+
pybullet.disconnect()
209+
210+
137211
def show_in_yourdfpy(
138212
name: str,
139213
configuration: List[float],
@@ -212,6 +286,10 @@ def main(argv=None):
212286
list_descriptions()
213287
elif args.subcmd == "show_in_meshcat":
214288
show_in_meshcat(args.name)
289+
elif args.subcmd == "show_in_mujoco":
290+
show_in_mujoco(args.name)
291+
elif args.subcmd == "show_in_pybullet":
292+
show_in_pybullet(args.name)
215293
elif args.subcmd == "show_in_yourdfpy":
216294
show_in_yourdfpy(args.name, args.configuration, args.collision)
217295
elif args.subcmd == "animate":

0 commit comments

Comments
 (0)