Skip to content

Commit e11db27

Browse files
authored
add example of using scene_synthesizer to procedurally generate kitchens w/ RB-Y1 (#440)
1 parent 6b46d13 commit e11db27

14 files changed

+1621
-474
lines changed

book/htmlbook

book/mobile/BUILD.bazel

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright 2020-2024 Massachusetts Institute of Technology.
55
# Licensed under the BSD 3-Clause License. See LICENSE.TXT for details.
66

7+
load("@pip_deps//:requirements.bzl", "requirement")
78
load("//book/htmlbook/tools/jupyter:defs.bzl", "rt_ipynb_test")
89

910
rt_ipynb_test(
@@ -16,7 +17,6 @@ rt_ipynb_test(
1617
],
1718
)
1819

19-
2020
rt_ipynb_test(
2121
name = "mobile_iiwa",
2222
srcs = ["mobile_iiwa.ipynb"],
@@ -26,6 +26,27 @@ rt_ipynb_test(
2626
],
2727
)
2828

29+
rt_ipynb_test(
30+
name = "rainbow",
31+
srcs = ["rainbow.ipynb"],
32+
tags = ["requires-network", "no-sandbox"],
33+
deps = [
34+
"//manipulation",
35+
"//manipulation:remotes",
36+
],
37+
)
38+
39+
rt_ipynb_test(
40+
name = "scene_synthesizer",
41+
srcs = ["scene_synthesizer.ipynb"],
42+
tags = ["requires-network", "no-sandbox"], # for rainbow
43+
deps = [
44+
"//manipulation",
45+
"//manipulation:remotes",
46+
requirement("scene_synthesizer"),
47+
],
48+
)
49+
2950
rt_ipynb_test(
3051
name = "spot",
3152
srcs = ["spot.ipynb"],

book/mobile/rainbow.ipynb

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "05124c35",
6+
"metadata": {
7+
"colab_type": "text",
8+
"id": "EgiF12Hf1Dhs"
9+
},
10+
"source": [
11+
"This notebook provides examples to go along with the [textbook](http://manipulation.csail.mit.edu/robot.html). I recommend having both windows open, side-by-side!"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 1,
17+
"id": "99268d0c",
18+
"metadata": {
19+
"colab": {},
20+
"colab_type": "code",
21+
"id": "eeMrMI0-1Dhu",
22+
"lines_to_end_of_cell_marker": 2
23+
},
24+
"outputs": [],
25+
"source": [
26+
"from pydrake.all import ModelVisualizer, StartMeshcat\n",
27+
"\n",
28+
"from manipulation import running_as_notebook\n",
29+
"from manipulation.make_drake_compatible_model import MakeDrakeCompatibleModel\n",
30+
"from manipulation.remotes import AddRby1Remote"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "7dec0a5e",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"# Start the visualizer.\n",
41+
"meshcat = StartMeshcat()"
42+
]
43+
},
44+
{
45+
"cell_type": "markdown",
46+
"id": "7112a8be",
47+
"metadata": {},
48+
"source": [
49+
"# Rainbow's RB-Y1 mobile manipulator\n",
50+
"\n",
51+
"First we'll use the ModelVisualizer to inspect the model."
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": null,
57+
"id": "ec925772",
58+
"metadata": {
59+
"colab": {},
60+
"colab_type": "code",
61+
"id": "5SjOClhTltPk"
62+
},
63+
"outputs": [],
64+
"source": [
65+
"visualizer = ModelVisualizer(meshcat=meshcat)\n",
66+
"parser = visualizer.parser()\n",
67+
"AddRby1Remote(parser.package_map())\n",
68+
"model_path = parser.package_map().ResolveUrl(\"package://rby1/urdf/model.urdf\")\n",
69+
"drake_model_path = model_path.replace(\".urdf\", \".drake.urdf\")\n",
70+
"MakeDrakeCompatibleModel(model_path, drake_model_path)\n",
71+
"visualizer.AddModels(drake_model_path)\n",
72+
"visualizer.Run(loop_once=not running_as_notebook)\n",
73+
"meshcat.DeleteAddedControls()"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": null,
79+
"metadata": {},
80+
"outputs": [],
81+
"source": []
82+
}
83+
],
84+
"metadata": {
85+
"kernelspec": {
86+
"display_name": "venv",
87+
"language": "python",
88+
"name": "python3"
89+
},
90+
"language_info": {
91+
"codemirror_mode": {
92+
"name": "ipython",
93+
"version": 3
94+
},
95+
"file_extension": ".py",
96+
"mimetype": "text/x-python",
97+
"name": "python",
98+
"nbconvert_exporter": "python",
99+
"pygments_lexer": "ipython3",
100+
"version": "3.10.12"
101+
}
102+
},
103+
"nbformat": 4,
104+
"nbformat_minor": 5
105+
}

book/mobile/robocasa.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
"MakeDrakeCompatibleModel(\n",
163163
" original_model_path,\n",
164164
" drake_model_path,\n",
165-
" overwrite=True,\n",
166165
" remap_mujoco_geometry_groups={0: 3},\n",
167166
")\n",
168167
"visualizer.AddModels(drake_model_path)\n",
@@ -180,7 +179,7 @@
180179
],
181180
"metadata": {
182181
"kernelspec": {
183-
"display_name": "Python 3.10.8 64-bit",
182+
"display_name": "venv",
184183
"language": "python",
185184
"name": "python3"
186185
},

book/mobile/scene_synthesizer.ipynb

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "05124c35",
6+
"metadata": {
7+
"colab_type": "text",
8+
"id": "EgiF12Hf1Dhs"
9+
},
10+
"source": [
11+
"This notebook provides examples to go along with the [textbook](http://manipulation.csail.mit.edu/robot.html). I recommend having both windows open, side-by-side!\n"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 1,
17+
"id": "99268d0c",
18+
"metadata": {
19+
"colab": {},
20+
"colab_type": "code",
21+
"id": "eeMrMI0-1Dhu",
22+
"lines_to_end_of_cell_marker": 2
23+
},
24+
"outputs": [],
25+
"source": [
26+
"import os\n",
27+
"import tempfile\n",
28+
"\n",
29+
"from pydrake.all import ModelVisualizer, RigidTransform, StartMeshcat\n",
30+
"from scene_synthesizer import BoxAsset\n",
31+
"from scene_synthesizer.procedural_scenes import kitchen\n",
32+
"\n",
33+
"from manipulation.remotes import AddRby1Remote"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": null,
39+
"id": "7dec0a5e",
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"# Start the visualizer.\n",
44+
"meshcat = StartMeshcat()\n",
45+
"tmpdir = tempfile.TemporaryDirectory()"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"id": "780027d3",
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"def VisualizeKitchen(meshcat):\n",
56+
" visualizer = ModelVisualizer(meshcat=meshcat)\n",
57+
"\n",
58+
" # Generate a random kitchen.\n",
59+
" scene = kitchen(seed=None)\n",
60+
"\n",
61+
" # Use scene_synthesizer to figure out where to place the robot in the scene.\n",
62+
" rby1_bbox = BoxAsset(extents=[0.662, 0.58, 1.47])\n",
63+
" scene.add_object(\n",
64+
" rby1_bbox,\n",
65+
" \"rby1_bbox\",\n",
66+
" connect_parent_id=\"refrigerator\",\n",
67+
" connect_parent_anchor=(\"center\", \"front\", \"bottom\"),\n",
68+
" connect_obj_anchor=(\"center\", \"back\", \"bottom\"),\n",
69+
" translation=[0, -0.02, 0],\n",
70+
" )\n",
71+
" X_WRby1 = RigidTransform(scene.get_transform(\"rby1_bbox\")) @ RigidTransform(\n",
72+
" [0, 0, -1.47 / 2]\n",
73+
" )\n",
74+
" scene.remove_object(\"rby1_bbox\")\n",
75+
"\n",
76+
" # Export the kitchen to a urdf and add it to the visualizer.\n",
77+
" kitchen_urdf_path = os.path.join(tmpdir.name, \"kitchen.urdf\")\n",
78+
" scene.export(kitchen_urdf_path)\n",
79+
" visualizer.AddModels(kitchen_urdf_path)\n",
80+
"\n",
81+
" # Add the robot.\n",
82+
" AddRby1Remote(visualizer.parser().package_map())\n",
83+
" rby1_id = visualizer.parser().AddModels(url=\"package://rby1/urdf/model.drake.urdf\")[\n",
84+
" 0\n",
85+
" ]\n",
86+
" plant = visualizer.parser().plant()\n",
87+
" plant.SetDefaultFreeBodyPose(plant.GetBodyByName(\"base\", rby1_id), X_WRby1)\n",
88+
" visualizer.Run(loop_once=True)\n",
89+
"\n",
90+
"\n",
91+
"VisualizeKitchen(meshcat)"
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": null,
97+
"id": "fb792263",
98+
"metadata": {},
99+
"outputs": [],
100+
"source": []
101+
}
102+
],
103+
"metadata": {
104+
"kernelspec": {
105+
"display_name": "venv",
106+
"language": "python",
107+
"name": "python3"
108+
},
109+
"language_info": {
110+
"codemirror_mode": {
111+
"name": "ipython",
112+
"version": 3
113+
},
114+
"file_extension": ".py",
115+
"mimetype": "text/x-python",
116+
"name": "python",
117+
"nbconvert_exporter": "python",
118+
"pygments_lexer": "ipython3",
119+
"version": "3.10.12"
120+
}
121+
},
122+
"nbformat": 4,
123+
"nbformat_minor": 5
124+
}

book/robot/menagerie.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
" model_path = package_map.ResolveUrl(model_url)\n",
8585
" image_path = package_map.ResolveUrl(image_url)\n",
8686
" drake_model_path = model_path.replace(\".xml\", \".drake.xml\")\n",
87-
" MakeDrakeCompatibleModel(model_path, drake_model_path, overwrite=True)\n",
87+
" MakeDrakeCompatibleModel(model_path, drake_model_path)\n",
8888
" model_instances = parser.AddModels(drake_model_path)\n",
8989
" plant.Finalize()\n",
9090
" ApplyDefaultVisualization(builder.builder(), meshcat=meshcat)\n",
@@ -221,7 +221,7 @@
221221
" \"package://mujoco_menagerie/agility_cassie/scene.xml\"\n",
222222
")\n",
223223
"drake_model_path = model_path.replace(\".xml\", \".drake.xml\")\n",
224-
"MakeDrakeCompatibleModel(model_path, drake_model_path, overwrite=True)\n",
224+
"MakeDrakeCompatibleModel(model_path, drake_model_path)\n",
225225
"vis.AddModels(drake_model_path)\n",
226226
"vis.Run(loop_once=not running_as_notebook)"
227227
]

manipulation/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ rt_py_library(
7373
srcs = ["remotes.py"],
7474
imports = [".."],
7575
deps = [
76+
"make_drake_compatible_model",
7677
requirement("drake"),
7778
],
7879
visibility = ["//visibility:public"],

manipulation/remotes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pydrake.multibody.parsing import PackageMap
22

3+
from manipulation.make_drake_compatible_model import MakeDrakeCompatibleModel
4+
35

46
def AddMujocoMenagerie(package_map: PackageMap) -> str:
57
"""Add the remote `mujoco_menagerie` package to the given PackageMap.
@@ -55,6 +57,24 @@ def AddGymnasiumRobotics(package_map: PackageMap) -> str:
5557
return package_name
5658

5759

60+
def AddRby1Remote(package_map: PackageMap):
61+
package_name = "rby1"
62+
package_map.AddRemote(
63+
package_name=package_name,
64+
params=PackageMap.RemoteParams(
65+
urls=[
66+
f"https://github.com/RainbowRobotics/rby1-sdk/archive/refs/tags/v0.3.0.tar.gz"
67+
],
68+
sha256=("f1cbebccc24ad2cb3d966a4816adc8394572949e2b41809b9dc1c6756e501f48"),
69+
strip_prefix="rby1-sdk-0.3.0/models/rby1a/",
70+
),
71+
)
72+
model_path = package_map.ResolveUrl("package://rby1/urdf/model.urdf")
73+
drake_model_path = model_path.replace(".urdf", ".drake.urdf")
74+
MakeDrakeCompatibleModel(model_path, drake_model_path)
75+
return package_name
76+
77+
5878
def PrefetchAllRemotePackages():
5979
"""Prefetch all remote packages in the given PackageMap.
6080
This is useful for CI, where the remote packages are downloaded as part of
@@ -70,3 +90,4 @@ def fetch(package_name):
7090
fetch(AddMujocoMenagerie(package_map))
7191
fetch(AddSpotRemote(package_map))
7292
fetch(AddGymnasiumRobotics(package_map))
93+
fetch(AddRby1Remote(package_map))

0 commit comments

Comments
 (0)