Skip to content

Commit b7400fb

Browse files
Add show_in_meshcat command
1 parent 6f2cd1e commit b7400fb

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ All notable changes to this project will be documented in this file.
1010
- Description: AgileX PiPER (URDF)
1111
- Description: Robot Soccer Kit
1212
- Description: Robotiq 2F-85 (MJCF V4) (thanks to @peterdavidfagan)
13+
- CLI: Add `show_in_meshcat` command
14+
15+
### Changed
16+
17+
- Enable command-line to run from `python -m robot_descriptions`
1318

1419
### Fixed
1520

robot_descriptions/__main__.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,33 @@ def get_argument_parser() -> argparse.ArgumentParser:
4848
help="list all available robot descriptions",
4949
)
5050

51+
# show_in_meshcat --------------------------------------------------------
52+
parser_meshcat = subparsers.add_parser(
53+
"show_in_meshcat",
54+
help="load and display a given robot description in Meshcat",
55+
)
56+
parser_meshcat.add_argument(
57+
"name",
58+
help="name of the robot description",
59+
)
60+
5161
# show_in_yourdfpy --------------------------------------------------------
52-
parser_show = subparsers.add_parser(
62+
parser_yourdfpy = subparsers.add_parser(
5363
"show_in_yourdfpy",
54-
help="load and display a given robot description",
64+
help="load and display a given robot description with yourdfpy",
5565
)
56-
parser_show.add_argument(
66+
parser_yourdfpy.add_argument(
5767
"name",
5868
help="name of the robot description",
5969
)
60-
parser_show.add_argument(
70+
parser_yourdfpy.add_argument(
6171
"-c",
6272
"--configuration",
6373
nargs="+",
6474
type=float,
6575
help="configuration of the visualized robot description",
6676
)
67-
parser_show.add_argument(
77+
parser_yourdfpy.add_argument(
6878
"--collision",
6979
action="store_true",
7080
help="use collision geometry for the visualized robot description",
@@ -96,6 +106,34 @@ def list_descriptions():
96106
print(f"- {name} [{formats}]")
97107

98108

109+
def show_in_meshcat(name: str) -> None:
110+
"""Show a robot description in MeshCat.
111+
112+
Args:
113+
name: Name of the robot description.
114+
"""
115+
try:
116+
from pinocchio.visualize import MeshcatVisualizer
117+
except ImportError as e:
118+
raise ImportError(
119+
"Pinocchio not found, try for instance `conda install pinocchio`"
120+
) from e
121+
122+
from robot_descriptions.loaders.pinocchio import load_robot_description
123+
124+
try:
125+
robot = load_robot_description(name)
126+
except ModuleNotFoundError:
127+
robot = load_robot_description(f"{name}_description")
128+
129+
robot.setVisualizer(MeshcatVisualizer())
130+
robot.initViewer(open=True)
131+
robot.loadViewerModel()
132+
robot.display(robot.q0)
133+
134+
input("Press Enter to close MeshCat and terminate... ")
135+
136+
99137
def show_in_yourdfpy(
100138
name: str,
101139
configuration: List[float],
@@ -172,6 +210,8 @@ def main(argv=None):
172210
args = parser.parse_args(argv)
173211
if args.subcmd == "list":
174212
list_descriptions()
213+
elif args.subcmd == "show_in_meshcat":
214+
show_in_meshcat(args.name)
175215
elif args.subcmd == "show_in_yourdfpy":
176216
show_in_yourdfpy(args.name, args.configuration, args.collision)
177217
elif args.subcmd == "animate":

0 commit comments

Comments
 (0)