Spaces:
Sleeping
Sleeping
init commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +7 -0
- .gitignore +164 -0
- LICENSE.md +7 -0
- README.md +69 -12
- README_CaP.md +53 -0
- Real/composer/real_composer_prompt.py +120 -0
- Real/perception/real_parse_query_obj_prompt.py +104 -0
- Real/planner/real_planner_prompt.py +121 -0
- Real/value_maps/real_get_affordance_map_prompt.py +146 -0
- Real/value_maps/real_get_avoidance_map_prompt.py +36 -0
- Real/value_maps/real_get_gripper_map_prompt.py +48 -0
- Real/value_maps/real_get_rotation_map_prompt.py +53 -0
- Real/value_maps/real_get_velocity_map_prompt.py +31 -0
- Sim/composer/sim_composer_prompt.py +91 -0
- Sim/perception/sim_parse_query_obj_prompt.py +71 -0
- Sim/value_maps/sim_get_affordance_map_prompt.py +177 -0
- Sim/value_maps/sim_get_avoidance_map_prompt.py +60 -0
- Sim/value_maps/sim_get_gripper_map_prompt.py +57 -0
- Sim/value_maps/sim_get_rotation_map_prompt.py +25 -0
- Sim/value_maps/sim_get_velocity_map_prompt.py +46 -0
- VoxPoserApiExamples/Real/composer/real_composer_prompt.py +120 -0
- VoxPoserApiExamples/Real/perception/real_parse_query_obj_prompt.py +104 -0
- VoxPoserApiExamples/Real/planner/real_planner_prompt.py +121 -0
- VoxPoserApiExamples/Real/value_maps/real_get_affordance_map_prompt.py +146 -0
- VoxPoserApiExamples/Real/value_maps/real_get_avoidance_map_prompt.py +36 -0
- VoxPoserApiExamples/Real/value_maps/real_get_gripper_map_prompt.py +48 -0
- VoxPoserApiExamples/Real/value_maps/real_get_rotation_map_prompt.py +53 -0
- VoxPoserApiExamples/Real/value_maps/real_get_velocity_map_prompt.py +31 -0
- VoxPoserApiExamples/Sim/composer/sim_composer_prompt.py +91 -0
- VoxPoserApiExamples/Sim/perception/sim_parse_query_obj_prompt.py +71 -0
- VoxPoserApiExamples/Sim/value_maps/sim_get_affordance_map_prompt.py +177 -0
- VoxPoserApiExamples/Sim/value_maps/sim_get_avoidance_map_prompt.py +60 -0
- VoxPoserApiExamples/Sim/value_maps/sim_get_gripper_map_prompt.py +57 -0
- VoxPoserApiExamples/Sim/value_maps/sim_get_rotation_map_prompt.py +25 -0
- VoxPoserApiExamples/Sim/value_maps/sim_get_velocity_map_prompt.py +46 -0
- agibot_prompts/agibot_composer.py +139 -0
- agibot_prompts/agibot_perceptor.py +104 -0
- agibot_prompts/agibot_planner.py +121 -0
- app.py +202 -0
- bowl/bowl.urdf +3 -0
- bowl/cup.obj +3 -0
- bowl/textured-0008192.obj +3 -0
- cfg.yaml +90 -0
- cfg_agibot.yaml +51 -0
- cfg_voxposer.yaml +114 -0
- consts.py +33 -0
- lmp.py +253 -0
- md_logger.py +16 -0
- prompts/fgen.py +49 -0
- prompts/parse_obj_name.py +59 -0
.gitattributes
CHANGED
@@ -33,3 +33,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
robotiq_2f_85/ filter=lfs diff=lfs merge=lfs -text
|
37 |
+
*.stl filter=lfs diff=lfs merge=lfs -text
|
38 |
+
*.urdf filter=lfs diff=lfs merge=lfs -text
|
39 |
+
*.mtl filter=lfs diff=lfs merge=lfs -text
|
40 |
+
*.obj filter=lfs diff=lfs merge=lfs -text
|
41 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
42 |
+
*.dae filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
161 |
+
|
162 |
+
.DS_Store
|
163 |
+
|
164 |
+
.vscode/
|
LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Copyright 2021 Google LLC. SPDX-License-Identifier: Apache-2.0
|
2 |
+
|
3 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
4 |
+
|
5 |
+
https://www.apache.org/licenses/LICENSE-2.0
|
6 |
+
|
7 |
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
README.md
CHANGED
@@ -1,12 +1,69 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# VoxPoser API Examples
|
2 |
+
|
3 |
+
## Usage
|
4 |
+
|
5 |
+
```bash
|
6 |
+
python3 app.py
|
7 |
+
```
|
8 |
+
|
9 |
+
1. 在界面中填写OpenAI API Key,使用的代理地址,选择需要的configuration
|
10 |
+
2. 点击Setup/Reset Simulation
|
11 |
+
3. 填写自定义Instruction
|
12 |
+
4. 点击Run执行(需要等待较长时间)
|
13 |
+
|
14 |
+
## Example
|
15 |
+
|
16 |
+
### VLM & Perception
|
17 |
+
|
18 |
+
1. Open Vocab object detection [owlvit](https://huggingface.co/docs/transformers/model_doc/owlvit)
|
19 |
+
2. [SAM](https://github.com/facebookresearch/segment-anything)
|
20 |
+
3. Object mask tracking [XMem](https://github.com/hkchengrex/XMem)
|
21 |
+
4. 使用realsense获得深度图
|
22 |
+
5. 使用深度图获得法向量(抓取位姿)
|
23 |
+
|
24 |
+
可替代性:
|
25 |
+
- [x] owlvit -> Grounded SAM / YOLO
|
26 |
+
- [x] SAM -> FastSAM / YOLO-seg
|
27 |
+
- [ ] XMem -> DeepSORT(?) ByteTrack(?)
|
28 |
+
|
29 |
+
### LMP语言模型编程
|
30 |
+
|
31 |
+
语言模型编程:使用GPT-4
|
32 |
+
|
33 |
+
VoxPoser需要三大类LMP:
|
34 |
+
1. Planner
|
35 |
+
2. Composer
|
36 |
+
3. Value map generator
|
37 |
+
|
38 |
+
可替代性:
|
39 |
+
- [ ] GPT-4 -> LLaMA2 (?)
|
40 |
+
|
41 |
+
## LMPs
|
42 |
+
|
43 |
+
### Planner
|
44 |
+
|
45 |
+
LMP的输出是一系列的编程模型接口,Planner将这些语言描述转化为一系列高层级的规划,每步规划这些动作将被Composer执行。
|
46 |
+
|
47 |
+
模拟环境中不使用规划器,因为评估的任务由单个操作阶段组成。
|
48 |
+
|
49 |
+
### Composer
|
50 |
+
|
51 |
+
Composer LMP 从依次逐渐调用如下模组:
|
52 |
+
1. 感知模组调用获得感知结果
|
53 |
+
2. [optional] Affordance LMP
|
54 |
+
3. [optional] Avoidance LMP
|
55 |
+
4. [optional] End Effector Velocity LMP
|
56 |
+
5. [optional] End Effector Rotation LMP
|
57 |
+
6. [optional] Gripper Action LMP
|
58 |
+
7. Execute
|
59 |
+
|
60 |
+
### Value Maps
|
61 |
+
|
62 |
+
TODO
|
63 |
+
|
64 |
+
### Execution
|
65 |
+
|
66 |
+
1. Motion Planner: 贪心搜索得到一系列末端位姿,仅适用Affordance Map 和 Avoidance Map
|
67 |
+
2. Cost map: $W = -2 * \text{norm}(\text{Affordance}) - \text{norm}(\text{Avoidance})$
|
68 |
+
3. 根据离开/接近,调用目标法向量的正/负值方向上的Affordance Map
|
69 |
+
4. 根据避障目标的占据栅格occupancy_map,调整Avoidance Map
|
README_CaP.md
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Code As Policies
|
3 |
+
emoji: 📈
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.3.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
---
|
12 |
+
|
13 |
+
# Code as Policies Tabletop Manipulation Interactive Demo
|
14 |
+
|
15 |
+
This demo is from the paper:
|
16 |
+
|
17 |
+
[Code as Policies: Language Model Programs for Embodied Control](https://code-as-policies.github.io/)
|
18 |
+
|
19 |
+
Below is an interactive demo for the simulated tabletop manipulation domain, seen in the paper section IV.D
|
20 |
+
|
21 |
+
## Preparations
|
22 |
+
1. Obtain an [OpenAI API Key](https://openai.com/blog/openai-api/)
|
23 |
+
|
24 |
+
## Usage
|
25 |
+
1. Fill in the API Key and how many blocks and bowls to be spawned in the environment.
|
26 |
+
2. Click Setup/Reset Simulation
|
27 |
+
3. Based on the new randomly sampled object names, input an instruction and click Run Instruction. If successful, this will render a video and update the simulation environment visualization.
|
28 |
+
|
29 |
+
You can run instructions in sequence and refer back to previous instructions (e.g. do the same with other blocks, move the same block to the other bowl, etc). To reset, click Setup/Reset Env, and this will clear the current instruction history.
|
30 |
+
|
31 |
+
## Supported Instructions
|
32 |
+
* Spatial reasoning (e.g. to the left of the red block, the closest corner, the farthest bowl, the second block from the right)
|
33 |
+
* Sequential actions (e.g. put blocks in matching bowls, stack blocks on the bottom right corner)
|
34 |
+
* Contextual instructions (e.g. do the same with the blue block, undo that)
|
35 |
+
* Language-based reasoning (e.g. put the forest-colored block on the ocean-colored bowl).
|
36 |
+
* Simple Q&A (e.g. how many blocks are to the left of the blue bowl?)
|
37 |
+
|
38 |
+
## Example Instructions
|
39 |
+
Note object names may need to be changed depending the sampled object names.
|
40 |
+
* put the sun-colored block on the bowl closest to it
|
41 |
+
* stack the blocks on the bottom most bowl
|
42 |
+
* arrange the blocks as a square in the middle
|
43 |
+
* move the square 5cm to the right
|
44 |
+
* how many blocks are to the right of the orange bowl?
|
45 |
+
* pick up the block closest to the top left corner and place it on the bottom right corner
|
46 |
+
|
47 |
+
## Known Limitations
|
48 |
+
* In simulation we're using ground truth object poses instead of using vision models. This means that instructions the require knowledge of visual apperances (e.g. darkest bowl, largest object, empty bowls) are not supported.
|
49 |
+
* Currently, the low-level pick place primitive does not do collision checking, so if there are many objects on the table, placing actions may incur collisions.
|
50 |
+
* The pick place primitive is also unable to pick up bowls.
|
51 |
+
* Prompt saturation - if too many instructions (10+) are executed in a row, then the LLM may start to ignore examples in the early parts of the prompt.
|
52 |
+
* Ambiguous instructions - if a given instruction doesn't lead to the desired actions, try rephrasing it to remove ambiguities (e.g. place the block on the closest bowl -> place the block on its closest bowl)
|
53 |
+
* Maximum token length - you may hit the maximum token length if running multiple commands in sequence. Please reset the simulation when this happens.
|
Real/composer/real_composer_prompt.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute, reset_to_default_pose
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
from plan_utils import get_affordance_map, get_avoidance_map, get_velocity_map, get_rotation_map, get_gripper_map
|
5 |
+
|
6 |
+
# Query: move ee forward for 10cm.
|
7 |
+
movable = parse_query_obj('gripper')
|
8 |
+
affordance_map = get_affordance_map(f'a point 10cm in front of {movable.position}')
|
9 |
+
execute(movable, affordance_map)
|
10 |
+
|
11 |
+
# Query: go back to default.
|
12 |
+
reset_to_default_pose()
|
13 |
+
|
14 |
+
# Query: move the gripper behind the bowl, and slow down when near the bowl.
|
15 |
+
movable = parse_query_obj('gripper')
|
16 |
+
affordance_map = get_affordance_map('a point 15cm behind the bowl')
|
17 |
+
avoidance_map = get_avoidance_map('10cm near the bowl')
|
18 |
+
velocity_map = get_velocity_map('slow down when near the bowl')
|
19 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
20 |
+
|
21 |
+
# Query: move to the back side of the table while staying at least 5cm from the blue block.
|
22 |
+
movable = parse_query_obj('gripper')
|
23 |
+
affordance_map = get_affordance_map('a point on the back side of the table')
|
24 |
+
avoidance_map = get_avoidance_map('5cm from the blue block')
|
25 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
26 |
+
|
27 |
+
# Query: move to the top of the plate and face the plate.
|
28 |
+
movable = parse_query_obj('gripper')
|
29 |
+
affordance_map = get_affordance_map('a point 10cm above the plate')
|
30 |
+
rotation_map = get_rotation_map('face the plate')
|
31 |
+
execute(movable, affordance_map=affordance_map, rotation_map=rotation_map)
|
32 |
+
|
33 |
+
# Query: drop the toy inside container.
|
34 |
+
movable = parse_query_obj('gripper')
|
35 |
+
affordance_map = get_affordance_map('a point 15cm above the container')
|
36 |
+
gripper_map = get_gripper_map('close everywhere but open when on top of the container')
|
37 |
+
execute(movable, affordance_map=affordance_map, gripper_map=gripper_map)
|
38 |
+
|
39 |
+
# Query: push close the topmost drawer.
|
40 |
+
movable = parse_query_obj('topmost drawer handle')
|
41 |
+
affordance_map = get_affordance_map('a point 30cm into the topmost drawer handle')
|
42 |
+
execute(movable, affordance_map=affordance_map)
|
43 |
+
|
44 |
+
# Query: push the second to the left block along the red line.
|
45 |
+
movable = parse_query_obj('second to the left block')
|
46 |
+
affordance_map = get_affordance_map('the red line')
|
47 |
+
execute(movable, affordance_map=affordance_map)
|
48 |
+
|
49 |
+
# Query: grasp the blue block from the table at a quarter of the speed.
|
50 |
+
movable = parse_query_obj('gripper')
|
51 |
+
affordance_map = get_affordance_map('a point at the center of blue block')
|
52 |
+
velocity_map = get_velocity_map('quarter of the speed')
|
53 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the blue block')
|
54 |
+
execute(movable, affordance_map=affordance_map, velocity_map=velocity_map, gripper_map=gripper_map)
|
55 |
+
|
56 |
+
# Query: move to the left of the brown block.
|
57 |
+
movable = parse_query_obj('gripper')
|
58 |
+
affordance_map = get_affordance_map('a point 10cm to the left of the brown block')
|
59 |
+
execute(movable, affordance_map=affordance_map)
|
60 |
+
|
61 |
+
# Query: move to the top of the tray that contains the lemon.
|
62 |
+
movable = parse_query_obj('gripper')
|
63 |
+
affordance_map = get_affordance_map('a point 10cm above the tray that contains the lemon')
|
64 |
+
execute(movable, affordance_map=affordance_map)
|
65 |
+
|
66 |
+
# Query: close drawer by 5cm.
|
67 |
+
movable = parse_query_obj('drawer handle')
|
68 |
+
affordance_map = get_affordance_map('a point 5cm into the drawer handle')
|
69 |
+
execute(movable, affordance_map=affordance_map)
|
70 |
+
|
71 |
+
# Query: move to 5cm on top of the soda can, at 0.5x speed when within 20cm of the wooden mug, and keep at least 15cm away from the wooden mug.
|
72 |
+
movable = parse_query_obj('gripper')
|
73 |
+
affordance_map = get_affordance_map('a point 5cm above the soda can')
|
74 |
+
avoidance_map = get_avoidance_map('15cm from the wooden mug')
|
75 |
+
velocity_map = get_velocity_map('0.5x speed when within 20cm of the wooden mug')
|
76 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
77 |
+
|
78 |
+
# Query: wipe the red dot but avoid the blue block.
|
79 |
+
movable = parse_query_obj('gripper')
|
80 |
+
affordance_map = get_affordance_map('the red dot')
|
81 |
+
avoidance_map = get_avoidance_map('10cm from the blue block')
|
82 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
83 |
+
|
84 |
+
# Query: grasp the mug from the shelf.
|
85 |
+
movable = parse_query_obj('gripper')
|
86 |
+
affordance_map = get_affordance_map('a point at the center of the mug handle')
|
87 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the mug handle')
|
88 |
+
execute(movable, affordance_map=affordance_map, gripper_map=gripper_map)
|
89 |
+
|
90 |
+
# Query: move to 10cm on top of the soup bowl, and 5cm to the left of the soup bowl, while away from the glass, at 0.75x speed.
|
91 |
+
movable = parse_query_obj('gripper')
|
92 |
+
affordance_map = get_affordance_map('a point 10cm above and 5cm to the left of the soup bowl')
|
93 |
+
avoidance_map = get_avoidance_map('10cm from the glass')
|
94 |
+
velocity_map = get_velocity_map('0.75x speed')
|
95 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
96 |
+
|
97 |
+
# Query: open gripper.
|
98 |
+
movable = parse_query_obj('gripper')
|
99 |
+
gripper_map = get_gripper_map('open everywhere')
|
100 |
+
execute(movable, gripper_map=gripper_map)
|
101 |
+
|
102 |
+
# Query: turn counter-clockwise by 180 degrees.
|
103 |
+
movable = parse_query_obj('gripper')
|
104 |
+
rotation_map = get_rotation_map('turn counter-clockwise by 180 degrees')
|
105 |
+
execute(movable, rotation_map=rotation_map)
|
106 |
+
|
107 |
+
# Query: sweep all particles to the left side of the table.
|
108 |
+
particles = parse_query_obj('particles')
|
109 |
+
for particle in particles:
|
110 |
+
movable = particle
|
111 |
+
affordance_map = get_affordance_map('a point on the left side of the table')
|
112 |
+
execute(particle, affordance_map=affordance_map)
|
113 |
+
|
114 |
+
# Query: grasp the bottom drawer handle while moving at 0.5x speed.
|
115 |
+
movable = parse_query_obj('gripper')
|
116 |
+
affordance_map = get_affordance_map('a point at the center of the bottom drawer handle')
|
117 |
+
velocity_map = get_velocity_map('0.5x speed')
|
118 |
+
rotation_map = get_rotation_map('face the bottom drawer handle')
|
119 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the bottom drawer handle')
|
120 |
+
execute(movable, affordance_map=affordance_map, velocity_map=velocity_map, rotation_map=rotation_map, gripper_map=gripper_map)
|
Real/perception/real_parse_query_obj_prompt.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import detect
|
3 |
+
|
4 |
+
objects = ['table', 'gripper', 'green block', 'cardboard box']
|
5 |
+
# Query: gripper.
|
6 |
+
gripper = detect('gripper')[0]
|
7 |
+
ret_val = gripper
|
8 |
+
|
9 |
+
objects = ['table', 'gripper', 'drawer', 'egg', 'egg', 'plate']
|
10 |
+
# Query: topmost handle.
|
11 |
+
handles = detect('drawer handle')
|
12 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
13 |
+
top_handle = handles[-1]
|
14 |
+
ret_val = top_handle
|
15 |
+
|
16 |
+
objects = ['table', 'gripper', 'yellow block', 'charging cable', 'cyan block', 'magenta block']
|
17 |
+
# Query: second to the left block.
|
18 |
+
blocks = detect('block')
|
19 |
+
blocks = sorted(blocks, key=lambda x: x.position[1])
|
20 |
+
second_left_block = blocks[1]
|
21 |
+
ret_val = second_left_block
|
22 |
+
|
23 |
+
objects = ['table', 'gripper', 'iPhone', 'ruler', 'pink line', 'blue line']
|
24 |
+
# Query: the front most line on the table.
|
25 |
+
lines = detect('line')
|
26 |
+
lines = sorted(lines, key=lambda x: x.position[0])
|
27 |
+
front_most_line = lines[-1]
|
28 |
+
ret_val = front_most_line
|
29 |
+
|
30 |
+
objects = ['table', 'gripper', 'vase', 'napkin box', 'mask']
|
31 |
+
# Query: table.
|
32 |
+
table = detect('table')[0]
|
33 |
+
ret_val = table
|
34 |
+
|
35 |
+
objects = ['table', 'gripper', 'bottle', 'drawer', 'bowl', 'bag']
|
36 |
+
# Query: second to the bottom handle.
|
37 |
+
handles = detect('drawer handle')
|
38 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
39 |
+
second_bottom_handle = handles[1]
|
40 |
+
ret_val = second_bottom_handle
|
41 |
+
|
42 |
+
objects = ['table', 'gripper', 'brown line', 'red block', 'monitor']
|
43 |
+
# Query: brown line.
|
44 |
+
brown_line = detect('brown line')[0]
|
45 |
+
ret_val = brown_line
|
46 |
+
|
47 |
+
objects = ['table', 'gripper', 'green block', 'cup holder', 'black block']
|
48 |
+
# Query: block.
|
49 |
+
block = detect('green block')[0]
|
50 |
+
ret_val = block
|
51 |
+
|
52 |
+
objects = ['table', 'gripper', 'mouse', 'yellow bowl', 'brown bowl', 'sticker']
|
53 |
+
# Query: bowl closest to the sticker.
|
54 |
+
bowls = detect('bowl')
|
55 |
+
sticker = detect('sticker')[0]
|
56 |
+
closest_bowl = min(bowls, key=lambda x: np.linalg.norm(x.position - sticker.position))
|
57 |
+
ret_val = closest_bowl
|
58 |
+
|
59 |
+
objects = ['table', 'gripper', 'keyboard', 'brown bag', 'pink bag', 'red tape', 'bottle']
|
60 |
+
# Query: bag with the red tape on top.
|
61 |
+
bags = detect('bag')
|
62 |
+
red_tape = detect('red tape')[0]
|
63 |
+
bag_with_red_tape = min(bags, key=lambda x: np.linalg.norm(x.position - red_tape.position))
|
64 |
+
ret_val = bag_with_red_tape
|
65 |
+
|
66 |
+
objects = ['table', 'gripper', 'grape', 'wood tray', 'strawberry', 'white tray', 'blue tray', 'bread']
|
67 |
+
# Query: tray that contains the bread.
|
68 |
+
trays = detect('tray')
|
69 |
+
bread = detect('bread')[0]
|
70 |
+
tray_with_bread = min(trays, key=lambda x: np.linalg.norm(x.position - bread.position))
|
71 |
+
ret_val = tray_with_bread
|
72 |
+
|
73 |
+
objects = ['table', 'gripper', 'drawer']
|
74 |
+
# Query: top drawer handle.
|
75 |
+
handles = detect('drawer handle')
|
76 |
+
top_drawer_handle = max(handles, key=lambda x: x.position[2])
|
77 |
+
ret_val = top_drawer_handle
|
78 |
+
|
79 |
+
objects = ['table', 'gripper', 'door']
|
80 |
+
# Query: the thing you can open the door with.
|
81 |
+
door_handle = detect('door handle')[0]
|
82 |
+
ret_val = door_handle
|
83 |
+
|
84 |
+
objects = ['table', 'gripper', 'glass', 'vase', 'plastic bottle', 'block', 'phone case']
|
85 |
+
# Query: anything fragile.
|
86 |
+
fragile_items = []
|
87 |
+
for obj in ['glass', 'vase']:
|
88 |
+
item = detect(obj)[0]
|
89 |
+
fragile_items.append(item)
|
90 |
+
ret_val = fragile_items
|
91 |
+
|
92 |
+
objects = ['table', 'gripper', 'fridge']
|
93 |
+
# Query: fridge handle.
|
94 |
+
fridge_handle = detect('fridge handle')[0]
|
95 |
+
ret_val = fridge_handle
|
96 |
+
|
97 |
+
objects = ['table', 'gripper', 'blue block', 'red block']
|
98 |
+
# Query: green block.
|
99 |
+
ret_val = None
|
100 |
+
|
101 |
+
objects = ['table', 'gripper', 'yellow bowl', 'red spoon']
|
102 |
+
# Query: gripper.
|
103 |
+
gripper = detect('gripper')[0]
|
104 |
+
ret_val = gripper
|
Real/planner/real_planner_prompt.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
import action_utils import composer
|
5 |
+
|
6 |
+
objects = ['blue block', 'yellow block', 'mug']
|
7 |
+
# Query: place the blue block on the yellow block, and avoid the mug at all time.
|
8 |
+
composer("grasp the blue block while keeping at least 15cm away from the mug")
|
9 |
+
composer("back to default pose")
|
10 |
+
composer("move to 5cm on top of the yellow block while keeping at least 15cm away from the mug")
|
11 |
+
composer("open gripper")
|
12 |
+
# done
|
13 |
+
|
14 |
+
objects = ['airpods', 'drawer']
|
15 |
+
# Query: Open the drawer slowly.
|
16 |
+
composer("grasp the drawer handle, at 0.5x speed")
|
17 |
+
composer("move away from the drawer handle by 25cm, at 0.5x speed")
|
18 |
+
composer("open gripper, at 0.5x speed")
|
19 |
+
# done
|
20 |
+
|
21 |
+
objects = ['tissue box', 'tissue', 'bowl']
|
22 |
+
# Query: Can you pass me a tissue and place it next to the bowl?
|
23 |
+
composer("grasp the tissue")
|
24 |
+
composer("back to default pose")
|
25 |
+
composer("move to 10cm to the right of the bowl")
|
26 |
+
composer("open gripper")
|
27 |
+
composer("back to default pose")
|
28 |
+
# done
|
29 |
+
|
30 |
+
objects = ['charger', 'outlet']
|
31 |
+
# Query: unplug the charger from the wall.
|
32 |
+
composer("grasp the charger")
|
33 |
+
composer("back to default pose")
|
34 |
+
# done
|
35 |
+
|
36 |
+
objects = ['grape', 'lemon', 'drill', 'router', 'bread', 'tray']
|
37 |
+
# Query: put the sweeter fruit in the tray that contains the bread.
|
38 |
+
composer("grasp the grape")
|
39 |
+
composer("back to default pose")
|
40 |
+
composer("move to the top of the tray that contains the bread")
|
41 |
+
composer("open gripper")
|
42 |
+
# done
|
43 |
+
|
44 |
+
objects = ['marbles', 'tray', 'broom']
|
45 |
+
# Query: Can you sweep the marbles into the tray?
|
46 |
+
composer("grasp the broom")
|
47 |
+
composer("back to default pose")
|
48 |
+
composer("push the marbles into the tray")
|
49 |
+
# done
|
50 |
+
|
51 |
+
objects = ['orange', 'QR code', 'lemon', 'drawer']
|
52 |
+
# Query: put the sour fruit into the top drawer.
|
53 |
+
composer("grasp the top drawer handle")
|
54 |
+
composer("move away from the top drawer handle by 25cm")
|
55 |
+
composer("open gripper")
|
56 |
+
composer("back to default pose")
|
57 |
+
composer("grasp the lemon")
|
58 |
+
composer("move to 10cm on top of the top drawer")
|
59 |
+
composer("open gripper")
|
60 |
+
# done
|
61 |
+
|
62 |
+
objects = ['fridge', 'hot soup']
|
63 |
+
# Query: Open the fridge door and be careful around the hot soup.
|
64 |
+
composer("grasp the fridge handle and keep at least 15cm away from the hot soup")
|
65 |
+
composer("move away from the fridge handle by 25cm and keep at least 15cm away from the hot soup")
|
66 |
+
composer("open gripper")
|
67 |
+
# done
|
68 |
+
|
69 |
+
objects = ['cyan bowl', 'yellow bowl', 'box', 'ice cream']
|
70 |
+
# Query: move to the top of the cyan bowl.
|
71 |
+
composer("move to the top of the cyan bowl")
|
72 |
+
# done
|
73 |
+
|
74 |
+
objects = ['drawer', 'umbrella']
|
75 |
+
# Query: close the drawer.
|
76 |
+
composer("push close the drawer handle by 25cm")
|
77 |
+
# done
|
78 |
+
|
79 |
+
objects = ['plate', 'steak', 'fork', 'knife', 'spoon']
|
80 |
+
# Query: Could you please set up the fork for the steak for me?
|
81 |
+
composer("grasp the fork")
|
82 |
+
composer("back to default pose")
|
83 |
+
composer("move to 10cm to the right of the plate")
|
84 |
+
composer("open gripper")
|
85 |
+
composer("back to default pose")
|
86 |
+
# done
|
87 |
+
|
88 |
+
objects = ['light switch']
|
89 |
+
# Query: Press down the switch.
|
90 |
+
composer("close the gripper")
|
91 |
+
composer("move to the center of the light switch")
|
92 |
+
composer("back to default pose")
|
93 |
+
# done
|
94 |
+
|
95 |
+
objects = ['beer']
|
96 |
+
# Query: turn close the beer.
|
97 |
+
composer("grasp the beer cap")
|
98 |
+
composer("turn clockwise by 180 degrees")
|
99 |
+
composer("back to default pose")
|
100 |
+
# done
|
101 |
+
|
102 |
+
objects = ['steak', 'grill', 'plate']
|
103 |
+
# Query: Take the steak out of the grill and put it flat on the plate.
|
104 |
+
composer("grasp the steak")
|
105 |
+
composer("back to default pose")
|
106 |
+
composer("rotate the gripper to be 45 degrees slanted relative to the plate")
|
107 |
+
composer("move to 10cm on top of the plate")
|
108 |
+
composer("open gripper")
|
109 |
+
composer("back to default pose")
|
110 |
+
# done
|
111 |
+
|
112 |
+
objects = ['trash can', 'napkin']
|
113 |
+
# Query: sort napkin into trash can.
|
114 |
+
napkin = parse_query_obj("napkin")
|
115 |
+
trash_can = parse_query_obj("trash can")
|
116 |
+
while np.linalg.norm(napkin.position - trash_can.position) > 0.1:
|
117 |
+
composer("grasp the napkin")
|
118 |
+
composer("move to 10cm on top of the trash can")
|
119 |
+
composer("open gripper")
|
120 |
+
composer("back to default pose")
|
121 |
+
# done
|
Real/value_maps/real_get_affordance_map_prompt.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_affordance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: a point 10cm in front of [10, 15, 60].
|
6 |
+
affordance_map = get_empty_affordance_map()
|
7 |
+
# 10cm in front of so we add to x-axis
|
8 |
+
x = 10 + cm2index(10, 'x')
|
9 |
+
y = 15
|
10 |
+
z = 60
|
11 |
+
affordance_map[x, y, z] = 1
|
12 |
+
ret_val = affordance_map
|
13 |
+
|
14 |
+
# Query: a point on the right side of the table.
|
15 |
+
affordance_map = get_empty_affordance_map()
|
16 |
+
table = parse_query_obj('table')
|
17 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
18 |
+
center_x, center_y, center_z = table.position
|
19 |
+
# right side so y = max_y
|
20 |
+
x = center_x
|
21 |
+
y = max_y
|
22 |
+
z = center_z
|
23 |
+
affordance_map[x, y, z] = 1
|
24 |
+
ret_val = affordance_map
|
25 |
+
|
26 |
+
# Query: a point 20cm on top of the container.
|
27 |
+
affordance_map = get_empty_affordance_map()
|
28 |
+
container = parse_query_obj('container')
|
29 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = container.aabb
|
30 |
+
center_x, center_y, center_z = container.position
|
31 |
+
# 20cm on top of so we add to z-axis
|
32 |
+
x = center_x
|
33 |
+
y = center_y
|
34 |
+
z = max_z + cm2index(20, 'z')
|
35 |
+
affordance_map[x, y, z] = 1
|
36 |
+
ret_val = affordance_map
|
37 |
+
|
38 |
+
# Query: a point 1cm to the left of the brown block.
|
39 |
+
affordance_map = get_empty_affordance_map()
|
40 |
+
brown_block = parse_query_obj('brown block')
|
41 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = brown_block.aabb
|
42 |
+
center_x, center_y, center_z = brown_block.position
|
43 |
+
# 1cm to the left of so we subtract from y-axis
|
44 |
+
x = center_x
|
45 |
+
y = min_y - cm2index(1, 'y')
|
46 |
+
z = center_z
|
47 |
+
affordance_map[x, y, z] = 1
|
48 |
+
ret_val = affordance_map
|
49 |
+
|
50 |
+
# Query: anywhere within 20cm of the right most block.
|
51 |
+
affordance_map = get_empty_affordance_map()
|
52 |
+
right_most_block = parse_query_obj('the right most block')
|
53 |
+
set_voxel_by_radius(affordance_map, right_most_block.position, radius_cm=20, value=1)
|
54 |
+
|
55 |
+
# Query: a point on the back side of the table.
|
56 |
+
affordance_map = get_empty_affordance_map()
|
57 |
+
table = parse_query_obj('table')
|
58 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
59 |
+
center_x, center_y, center_z = table.position
|
60 |
+
# back side so x = min_x
|
61 |
+
x = min_x
|
62 |
+
y = center_y
|
63 |
+
z = center_z
|
64 |
+
affordance_map[x, y, z] = 1
|
65 |
+
ret_val = affordance_map
|
66 |
+
|
67 |
+
# Query: a point on the front right corner of the table.
|
68 |
+
affordance_map = get_empty_affordance_map()
|
69 |
+
table = parse_query_obj('table')
|
70 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
71 |
+
center_x, center_y, center_z = table.position
|
72 |
+
# front right corner so x = max_x and y = max_y
|
73 |
+
x = max_x
|
74 |
+
y = max_y
|
75 |
+
z = center_z
|
76 |
+
affordance_map[x, y, z] = 1
|
77 |
+
ret_val = affordance_map
|
78 |
+
|
79 |
+
# Query: a point 30cm into the topmost drawer handle.
|
80 |
+
affordance_map = get_empty_affordance_map()
|
81 |
+
top_handle = parse_query_obj('topmost drawer handle')
|
82 |
+
# negative normal because we are moving into the handle.
|
83 |
+
moving_dir = -top_handle.normal
|
84 |
+
affordance_xyz = top_handle.position + cm2index(30, moving_dir)
|
85 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
86 |
+
ret_val = affordance_map
|
87 |
+
|
88 |
+
# Query: a point 5cm above the blue block.
|
89 |
+
affordance_map = get_empty_affordance_map()
|
90 |
+
blue_block = parse_query_obj('blue block')
|
91 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = blue_block.aabb
|
92 |
+
center_x, center_y, center_z = blue_block.position
|
93 |
+
# 5cm above so we add to z-axis
|
94 |
+
x = center_x
|
95 |
+
y = center_y
|
96 |
+
z = max_z + cm2index(5, 'z')
|
97 |
+
affordance_map[x, y, z] = 1
|
98 |
+
ret_val = affordance_map
|
99 |
+
|
100 |
+
# Query: a point 20cm away from the leftmost block.
|
101 |
+
affordance_map = get_empty_affordance_map()
|
102 |
+
leftmost_block = parse_query_obj('leftmost block')
|
103 |
+
# positive normal because we are moving away from the block.
|
104 |
+
moving_dir = leftmost_block.normal
|
105 |
+
affordance_xyz = leftmost_block.position + cm2index(20, moving_dir)
|
106 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
107 |
+
ret_val = affordance_map
|
108 |
+
|
109 |
+
# Query: a point 4cm to the left of and 10cm on top of the tray that contains the lemon.
|
110 |
+
affordance_map = get_empty_affordance_map()
|
111 |
+
tray_with_lemon = parse_query_obj('tray that contains the lemon')
|
112 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = tray_with_lemon.aabb
|
113 |
+
center_x, center_y, center_z = tray_with_lemon.position
|
114 |
+
# 4cm to the left of so we subtract from y-axis, and 10cm on top of so we add to z-axis
|
115 |
+
x = center_x
|
116 |
+
y = min_y - cm2index(4, 'y')
|
117 |
+
z = max_z + cm2index(10, 'z')
|
118 |
+
affordance_map[x, y, z] = 1
|
119 |
+
ret_val = affordance_map
|
120 |
+
|
121 |
+
# Query: a point 10cm to the right of [45 49 66], and 5cm above it.
|
122 |
+
affordance_map = get_empty_affordance_map()
|
123 |
+
# 10cm to the right of so we add to y-axis, and 5cm above it so we add to z-axis
|
124 |
+
x = 45
|
125 |
+
y = 49 + cm2index(10, 'y')
|
126 |
+
z = 66 + cm2index(5, 'z')
|
127 |
+
affordance_map[x, y, z] = 1
|
128 |
+
ret_val = affordance_map
|
129 |
+
|
130 |
+
# Query: the blue circle.
|
131 |
+
affordance_map = get_empty_affordance_map()
|
132 |
+
blue_circle = parse_query_obj('blue circle')
|
133 |
+
affordance_map = blue_circle.occupancy_map
|
134 |
+
ret_val = affordance_map
|
135 |
+
|
136 |
+
# Query: a point 10cm above and 5cm to the left of the yellow bowl.
|
137 |
+
affordance_map = get_empty_affordance_map()
|
138 |
+
yellow_bowl = parse_query_obj('yellow bowl')
|
139 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = yellow_bowl.aabb
|
140 |
+
center_x, center_y, center_z = yellow_bowl.position
|
141 |
+
# 10cm above so we add to z-axis, and 5cm to the left of so we subtract from y-axis
|
142 |
+
x = center_x
|
143 |
+
y = min_y - cm2index(5, 'y')
|
144 |
+
z = max_z + cm2index(10, 'z')
|
145 |
+
affordance_map[x, y, z] = 1
|
146 |
+
ret_val = affordance_map
|
Real/value_maps/real_get_avoidance_map_prompt.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_avoidance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: 10cm from the bowl.
|
6 |
+
avoidance_map = get_empty_avoidance_map()
|
7 |
+
bowl = parse_query_obj('bowl')
|
8 |
+
set_voxel_by_radius(avoidance_map, bowl.position, radius_cm=10, value=1)
|
9 |
+
ret_val = avoidance_map
|
10 |
+
|
11 |
+
# Query: 20cm near the mug.
|
12 |
+
avoidance_map = get_empty_avoidance_map()
|
13 |
+
mug = parse_query_obj('mug')
|
14 |
+
set_voxel_by_radius(avoidance_map, mug.position, radius_cm=20, value=1)
|
15 |
+
ret_val = avoidance_map
|
16 |
+
|
17 |
+
# Query: 20cm around the mug and 10cm around the bowl.
|
18 |
+
avoidance_map = get_empty_avoidance_map()
|
19 |
+
mug = parse_query_obj('mug')
|
20 |
+
set_voxel_by_radius(avoidance_map, mug.position, radius_cm=20, value=1)
|
21 |
+
bowl = parse_query_obj('bowl')
|
22 |
+
set_voxel_by_radius(avoidance_map, bowl.position, radius_cm=10, value=1)
|
23 |
+
ret_val = avoidance_map
|
24 |
+
|
25 |
+
# Query: 10cm from anything fragile.
|
26 |
+
avoidance_map = get_empty_avoidance_map()
|
27 |
+
fragile_objects = parse_query_obj('anything fragile')
|
28 |
+
for obj in fragile_objects:
|
29 |
+
set_voxel_by_radius(avoidance_map, obj.position, radius_cm=10, value=1)
|
30 |
+
ret_val = avoidance_map
|
31 |
+
|
32 |
+
# Query: 10cm from the blue circle.
|
33 |
+
avoidance_map = get_empty_avoidance_map()
|
34 |
+
blue_circle = parse_query_obj('blue circle')
|
35 |
+
set_voxel_by_radius(avoidance_map, blue_circle.position, radius_cm=10, value=1)
|
36 |
+
ret_val = avoidance_map
|
Real/value_maps/real_get_gripper_map_prompt.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_gripper_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: open everywhere except 1cm around the green block.
|
6 |
+
gripper_map = get_empty_gripper_map()
|
7 |
+
# open everywhere
|
8 |
+
gripper_map[:, :, :] = 0
|
9 |
+
# close when 1cm around the green block
|
10 |
+
green_block = parse_query_obj('green block')
|
11 |
+
set_voxel_by_radius(gripper_map, green_block.position, radius_cm=1, value=1)
|
12 |
+
ret_val = gripper_map
|
13 |
+
|
14 |
+
# Query: close everywhere but open when on top of the back left corner of the table.
|
15 |
+
gripper_map = get_empty_gripper_map()
|
16 |
+
# close everywhere
|
17 |
+
gripper_map[:, :, :] = 1
|
18 |
+
# open when on top of the back left corner of the table
|
19 |
+
table = parse_query_obj('table')
|
20 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
21 |
+
center_x, center_y, center_z = table.position
|
22 |
+
# back so x = min_x, left so y = min_y, top so we add to z
|
23 |
+
x = min_x
|
24 |
+
y = min_y
|
25 |
+
z = max_z + cm2index(15, 'z')
|
26 |
+
set_voxel_by_radius(gripper_map, (x, y, z), radius_cm=10, value=0)
|
27 |
+
ret_val = gripper_map
|
28 |
+
|
29 |
+
# Query: always open except when you are on the right side of the table.
|
30 |
+
gripper_map = get_empty_gripper_map()
|
31 |
+
# always open
|
32 |
+
gripper_map[:, :, :] = 0
|
33 |
+
# close when you are on the right side of the table
|
34 |
+
table = parse_query_obj('table')
|
35 |
+
center_x, center_y, center_z = table.position
|
36 |
+
# right side so y is greater than center_y
|
37 |
+
gripper_map[:, center_y:, :] = 1
|
38 |
+
|
39 |
+
# Query: always close except when you are on the back side of the table.
|
40 |
+
gripper_map = get_empty_gripper_map()
|
41 |
+
# always close
|
42 |
+
gripper_map[:, :, :] = 1
|
43 |
+
# open when you are on the back side of the table
|
44 |
+
table = parse_query_obj('table')
|
45 |
+
center_x, center_y, center_z = table.position
|
46 |
+
# back side so x is less than center_x
|
47 |
+
gripper_map[:center_x, :, :] = 0
|
48 |
+
ret_val = gripper_map
|
Real/value_maps/real_get_rotation_map_prompt.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_rotation_map, set_voxel_by_radius, cm2index, vec2quat
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
from transforms3d.euler import euler2quat, quat2euler
|
5 |
+
from transforms3d.quaternions import qmult, qinverse
|
6 |
+
|
7 |
+
# Query: face the support surface of the bowl.
|
8 |
+
rotation_map = get_empty_rotation_map()
|
9 |
+
bowl = parse_query_obj('bowl')
|
10 |
+
target_rotation = vec2quat(-bowl.normal)
|
11 |
+
rotation_map[:, :, :] = target_rotation
|
12 |
+
ret_val = rotation_map
|
13 |
+
|
14 |
+
# Query: face the table when within 30cm from table center.
|
15 |
+
rotation_map = get_empty_rotation_map()
|
16 |
+
table = parse_query_obj('table')
|
17 |
+
table_center = table.position
|
18 |
+
target_rotation = vec2quat(-table.normal)
|
19 |
+
set_voxel_by_radius(rotation_map, table_center, radius_cm=30, value=target_rotation)
|
20 |
+
ret_val = rotation_map
|
21 |
+
|
22 |
+
# Query: face the blue bowl.
|
23 |
+
rotation_map = get_empty_rotation_map()
|
24 |
+
blue_bowl = parse_query_obj('brown block')
|
25 |
+
target_rotation = vec2quat(-blue_bowl.normal)
|
26 |
+
rotation_map[:, :, :] = target_rotation
|
27 |
+
ret_val = rotation_map
|
28 |
+
|
29 |
+
# Query: turn clockwise by 45 degrees when at the center of the beer cap.
|
30 |
+
rotation_map = get_empty_rotation_map()
|
31 |
+
beer_cap = parse_query_obj('beer cap')
|
32 |
+
(x, y, z) = beer_cap.position
|
33 |
+
curr_rotation = rotation_map[x, y, z]
|
34 |
+
rotation_delta = euler2quat(0, 0, np.pi / 4)
|
35 |
+
rotation_map[x, y, z] = qmult(curr_rotation, rotation_delta)
|
36 |
+
ret_val = rotation_map
|
37 |
+
|
38 |
+
# Query: turn counter-clockwise by 30 degrees.
|
39 |
+
rotation_map = get_empty_rotation_map()
|
40 |
+
curr_rotation = rotation_map[0, 0, 0]
|
41 |
+
rotation_delta = euler2quat(0, 0, -np.pi / 6)
|
42 |
+
rotation_map[:, :, :] = qmult(curr_rotation, rotation_delta)
|
43 |
+
ret_val = rotation_map
|
44 |
+
|
45 |
+
# Query: rotate the gripper to be 45 degrees slanted relative to the plate.
|
46 |
+
rotation_map = get_empty_rotation_map()
|
47 |
+
plate = parse_query_obj('plate')
|
48 |
+
face_plate_quat = vec2quat(-plate.normal)
|
49 |
+
# rotate 45 degrees around the x-axis
|
50 |
+
rotation_delta = euler2quat(-np.pi / 4, 0, 0)
|
51 |
+
target_rotation = qmult(face_plate_quat, rotation_delta)
|
52 |
+
rotation_map[:, :, :] = target_rotation
|
53 |
+
ret_val = rotation_map
|
Real/value_maps/real_get_velocity_map_prompt.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_velocity_map, set_voxel_by_radius, cm2index
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
|
5 |
+
# Query: faster when on the right side of the table and slower when on the left side of the table.
|
6 |
+
velocity_map = get_empty_velocity_map()
|
7 |
+
table = parse_query_obj('table')
|
8 |
+
center_x, center_y, center_z = table.position
|
9 |
+
# faster on right side so 1.5 when y > center_y, slower on left side so 0.5 when y < center_y
|
10 |
+
velocity_map[:, center_y:, :] = 1.5
|
11 |
+
velocity_map[:, :center_y, :] = 0.5
|
12 |
+
ret_val = velocity_map
|
13 |
+
|
14 |
+
# Query: slow down by a quarter.
|
15 |
+
velocity_map = get_empty_velocity_map()
|
16 |
+
velocity_map[:] = 0.75
|
17 |
+
ret_val = velocity_map
|
18 |
+
|
19 |
+
# Query: slow down by a half when you're near anything fragile (objects: ['block', 'fork', 'mug', 'bowl', 'chips']).
|
20 |
+
velocity_map = get_empty_velocity_map()
|
21 |
+
mug = parse_query_obj('mug')
|
22 |
+
set_voxel_by_radius(velocity_map, mug.position, radius_cm=10, value=0.5)
|
23 |
+
bowl = parse_query_obj('bowl')
|
24 |
+
set_voxel_by_radius(velocity_map, bowl.position, radius_cm=10, value=0.5)
|
25 |
+
ret_val = velocity_map
|
26 |
+
|
27 |
+
# Query: quarter of the speed when within 9cm from the yellow line.
|
28 |
+
velocity_map = get_empty_velocity_map()
|
29 |
+
yellow_line = parse_query_obj('yellow_line')
|
30 |
+
set_voxel_by_radius(velocity_map, yellow_line.position, radius_cm=9, value=0.25)
|
31 |
+
ret_val = velocity_map
|
Sim/composer/sim_composer_prompt.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute, reset_to_default_pose
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
from plan_utils import get_affordance_map, get_avoidance_map, get_velocity_map, get_rotation_map, get_gripper_map
|
5 |
+
|
6 |
+
# Query: move ee forward for 7cm.
|
7 |
+
movable = parse_query_obj('ee')
|
8 |
+
affordance_map = get_affordance_map(f'a point 7cm in front of {movable.position}')
|
9 |
+
execute(movable, affordance_map)
|
10 |
+
|
11 |
+
# Query: move to the left of the green block.
|
12 |
+
movable = parse_query_obj('ee')
|
13 |
+
affordance_map = get_affordance_map('a point 11cm to the left of the green block')
|
14 |
+
execute(movable, affordance_map=affordance_map)
|
15 |
+
|
16 |
+
# Query: move to the yellow block while staying on the front side the pink block.
|
17 |
+
movable = parse_query_obj('ee')
|
18 |
+
affordance_map = get_affordance_map('a point 11cm on top of the yellow block')
|
19 |
+
avoidance_map = get_avoidance_map('anywhere behind the pink block')
|
20 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
21 |
+
|
22 |
+
# Query: move to the back side of the table.
|
23 |
+
movable = parse_query_obj('ee')
|
24 |
+
affordance_map = get_affordance_map('a point on the back side of the table')
|
25 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
26 |
+
|
27 |
+
# Query: move to the front right corner of the table while moving at faster speed when within 7cm from the yellow block.
|
28 |
+
movable = parse_query_obj('ee')
|
29 |
+
affordance_map = get_affordance_map('a point on the front right corner of the table')
|
30 |
+
velocity_map = get_velocity_map('faster speed when within 7cm from the yellow block')
|
31 |
+
execute(movable, affordance_map=affordance_map, velocity_map=velocity_map)
|
32 |
+
|
33 |
+
# Query: move to 15cm on top of the rightmost block while avoiding the blue line and moving at a quarter of the speed on the right side of the table.
|
34 |
+
movable = parse_query_obj('ee')
|
35 |
+
affordance_map = get_affordance_map('a point 15cm on top of the rightmost block')
|
36 |
+
avoidance_map = get_avoidance_map('the blue line')
|
37 |
+
velocity_map = get_velocity_map('a quarter of the speed on the right side of the table')
|
38 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
39 |
+
|
40 |
+
# Query: close the topmost drawer by pushing.
|
41 |
+
movable = parse_query_obj('topmost drawer handle')
|
42 |
+
affordance_map = get_affordance_map('a point 21cm into the topmost drawer handle')
|
43 |
+
execute(movable, affordance_map=affordance_map)
|
44 |
+
|
45 |
+
# Query: push the second to the left block along the brown line.
|
46 |
+
movable = parse_query_obj('second to the left block')
|
47 |
+
affordance_map = get_affordance_map('the brown line')
|
48 |
+
execute(movable, affordance_map=affordance_map)
|
49 |
+
|
50 |
+
# Query: grasp the blue block from the table at a quarter of the speed.
|
51 |
+
movable = parse_query_obj('ee')
|
52 |
+
affordance_map = get_affordance_map('a point at the center of blue block')
|
53 |
+
rotation_map = get_rotation_map('face the blue block')
|
54 |
+
velocity_map = get_velocity_map('quarter of the speed')
|
55 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the blue block')
|
56 |
+
execute(movable, affordance_map=affordance_map, rotation_map=rotation_map, velocity_map=velocity_map, gripper_map=gripper_map)
|
57 |
+
|
58 |
+
# Query: move to the left of the brown block.
|
59 |
+
movable = parse_query_obj('ee')
|
60 |
+
affordance_map = get_affordance_map('a point 11cm to the left of the brown block')
|
61 |
+
execute(movable, affordance_map=affordance_map)
|
62 |
+
|
63 |
+
# Query: back to default pose.
|
64 |
+
reset_to_default_pose()
|
65 |
+
|
66 |
+
# Query: open gripper.
|
67 |
+
movable = parse_query_obj('gripper')
|
68 |
+
gripper_map = get_gripper_map('open everywhere')
|
69 |
+
execute(movable, gripper_map=gripper_map)
|
70 |
+
|
71 |
+
# Query: drop the blue block to the right side of the table while staying at least 7cm away from the brown block.
|
72 |
+
movable = parse_query_obj('ee')
|
73 |
+
affordance_map = get_affordance_map('a point on the right side of the table')
|
74 |
+
avoidance_map = get_avoidance_map('7cm away from the brown block')
|
75 |
+
gripper_map = get_gripper_map('close everywhere except 1cm around the right side of the table')
|
76 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, gripper_map=gripper_map)
|
77 |
+
|
78 |
+
# Query: move to the front side of the yellow block.
|
79 |
+
movable = parse_query_obj('ee')
|
80 |
+
affordance_map = get_affordance_map('a point 11cm in front of the yellow block')
|
81 |
+
execute(movable, affordance_map=affordance_map)
|
82 |
+
|
83 |
+
# Query: move to the back side of the table.
|
84 |
+
movable = parse_query_obj('ee')
|
85 |
+
affordance_map = get_affordance_map('a point on the back side of the table')
|
86 |
+
execute(movable, affordance_map=affordance_map)
|
87 |
+
|
88 |
+
# Query: stay away from the brown block.
|
89 |
+
movable = parse_query_obj('ee')
|
90 |
+
avoidance_map = get_avoidance_map('3cm away from the brown block')
|
91 |
+
execute(movable, avoidance_map=avoidance_map)
|
Sim/perception/sim_parse_query_obj_prompt.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import detect
|
3 |
+
|
4 |
+
objects = ['green block', 'yellow line']
|
5 |
+
# Query: ee.
|
6 |
+
ee = detect('ee')[0]
|
7 |
+
ret_val = ee
|
8 |
+
|
9 |
+
objects = ['drawer', 'blue block', 'yellow block']
|
10 |
+
# Query: topmost handle.
|
11 |
+
handles = detect('drawer handle')
|
12 |
+
# topmost so sort by z, take the last one
|
13 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
14 |
+
top_handle = handles[-1]
|
15 |
+
ret_val = top_handle
|
16 |
+
|
17 |
+
objects = ['yellow block', 'pink block', 'brown line', 'pink block']
|
18 |
+
# Query: second to the left block.
|
19 |
+
blocks = detect('block')
|
20 |
+
# second to the left so sort by y, take the second one
|
21 |
+
blocks = sorted(blocks, key=lambda x: x.position[1])
|
22 |
+
second_left_block = blocks[1]
|
23 |
+
ret_val = second_left_block
|
24 |
+
|
25 |
+
objects = ['blue line', 'pink line', 'green block']
|
26 |
+
# Query: table.
|
27 |
+
table = detect('table')[0]
|
28 |
+
ret_val = table
|
29 |
+
|
30 |
+
objects = ['green line', 'drawer', 'yellow block']
|
31 |
+
# Query: second to the bottom handle.
|
32 |
+
handles = detect('drawer handle')
|
33 |
+
# second to the bottom so sort by z, take the second one
|
34 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
35 |
+
second_bottom_handle = handles[1]
|
36 |
+
ret_val = second_bottom_handle
|
37 |
+
|
38 |
+
objects = ['brown line', 'brown block']
|
39 |
+
# Query: brown line.
|
40 |
+
brown_line = detect('brown line')[0]
|
41 |
+
ret_val = brown_line
|
42 |
+
|
43 |
+
objects = ['green block', 'brown block', 'yellow line']
|
44 |
+
# Query: block.
|
45 |
+
block = detect('green block')[0]
|
46 |
+
ret_val = block
|
47 |
+
|
48 |
+
objects = ['pink block', 'pink line', 'blue block']
|
49 |
+
# Query: block closest to the pink line.
|
50 |
+
blocks = detect('block')
|
51 |
+
pink_line = detect('pink line')[0]
|
52 |
+
closest_block = min(blocks, key=lambda x: np.linalg.norm(x.position - pink_line.position))
|
53 |
+
ret_val = closest_block
|
54 |
+
|
55 |
+
objects = ['blue block', 'blue line', 'green block', 'pink block', 'brown block']
|
56 |
+
# Query: the block that is on top of the blue block.
|
57 |
+
blocks = detect('block')
|
58 |
+
blue_block = detect('blue block')[0]
|
59 |
+
# find the block that is on top of the blue block
|
60 |
+
for block in blocks:
|
61 |
+
if block.position[2] > blue_block.position[2]:
|
62 |
+
ret_val = block
|
63 |
+
break
|
64 |
+
|
65 |
+
objects = ['drawer']
|
66 |
+
# Query: top drawer handle.
|
67 |
+
handles = detect('drawer handle')
|
68 |
+
# top drawer handle so sort by z, take the last one
|
69 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
70 |
+
top_handle = handles[-1]
|
71 |
+
ret_val = top_handle
|
Sim/value_maps/sim_get_affordance_map_prompt.py
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_affordance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: a point 10cm in front of [10, 15, 60].
|
6 |
+
affordance_map = get_empty_affordance_map()
|
7 |
+
# in front so we add to x
|
8 |
+
x = 10 + cm2index(10, 'x')
|
9 |
+
y = 15
|
10 |
+
z = 60
|
11 |
+
affordance_map[x, y, z] = 1
|
12 |
+
ret_val = affordance_map
|
13 |
+
|
14 |
+
# Query: a point on the back side of the table.
|
15 |
+
affordance_map = get_empty_affordance_map()
|
16 |
+
table = parse_query_obj('table')
|
17 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
18 |
+
center_x, center_y, center_z = table.position
|
19 |
+
# back side so x = min_x
|
20 |
+
x = min_x
|
21 |
+
y = center_y
|
22 |
+
z = center_z
|
23 |
+
affordance_map[x, y, z] = 1
|
24 |
+
ret_val = affordance_map
|
25 |
+
|
26 |
+
# Query: a point 21cm on top of the green block.
|
27 |
+
affordance_map = get_empty_affordance_map()
|
28 |
+
green_block = parse_query_obj('green block')
|
29 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = green_block.aabb
|
30 |
+
center_x, center_y, center_z = green_block.position
|
31 |
+
# 21cm on top so z = max_z + 21cm
|
32 |
+
x = center_x
|
33 |
+
y = center_y
|
34 |
+
z = max_z + cm2index(21, 'z')
|
35 |
+
affordance_map[x, y, z] = 1
|
36 |
+
ret_val = affordance_map
|
37 |
+
|
38 |
+
# Query: a point 1cm to the left of the brown block.
|
39 |
+
affordance_map = get_empty_affordance_map()
|
40 |
+
brown_block = parse_query_obj('brown block')
|
41 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = brown_block.aabb
|
42 |
+
center_x, center_y, center_z = brown_block.position
|
43 |
+
# 1cm to the left so y = min_y - 1cm
|
44 |
+
x = center_x
|
45 |
+
y = min_y - cm2index(1, 'y')
|
46 |
+
z = center_z
|
47 |
+
affordance_map[x, y, z] = 1
|
48 |
+
ret_val = affordance_map
|
49 |
+
|
50 |
+
# Query: anywhere within 15cm of the right most block.
|
51 |
+
affordance_map = get_empty_affordance_map()
|
52 |
+
right_most_block = parse_query_obj('the right most block')
|
53 |
+
set_voxel_by_radius(affordance_map, right_most_block.position, radius_cm=15, value=1)
|
54 |
+
ret_val = affordance_map
|
55 |
+
|
56 |
+
# Query: a point on the back side of the table.
|
57 |
+
affordance_map = get_empty_affordance_map()
|
58 |
+
table = parse_query_obj('table')
|
59 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
60 |
+
center_x, center_y, center_z = table.position
|
61 |
+
# back side so x = min_x
|
62 |
+
x = min_x
|
63 |
+
y = center_y
|
64 |
+
z = center_z
|
65 |
+
affordance_map[x, y, z] = 1
|
66 |
+
ret_val = affordance_map
|
67 |
+
|
68 |
+
# Query: a point on the front right corner of the table.
|
69 |
+
affordance_map = get_empty_affordance_map()
|
70 |
+
table = parse_query_obj('table')
|
71 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
72 |
+
center_x, center_y, center_z = table.position
|
73 |
+
# front right corner -> front so x = max_x, right so y = max_y
|
74 |
+
x = max_x
|
75 |
+
y = max_y
|
76 |
+
z = center_z
|
77 |
+
affordance_map[x, y, z] = 1
|
78 |
+
ret_val = affordance_map
|
79 |
+
|
80 |
+
# Query: a point 30cm into the topmost drawer handle.
|
81 |
+
affordance_map = get_empty_affordance_map()
|
82 |
+
top_handle = parse_query_obj('topmost drawer handle')
|
83 |
+
# negative normal because we are moving into the handle.
|
84 |
+
moving_dir = -top_handle.normal
|
85 |
+
affordance_xyz = top_handle.position + cm2index(30, moving_dir)
|
86 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
87 |
+
ret_val = affordance_map
|
88 |
+
|
89 |
+
# Query: a point 9cm to the left of the blue block.
|
90 |
+
affordance_map = get_empty_affordance_map()
|
91 |
+
blue_block = parse_query_obj('blue block')
|
92 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = blue_block.aabb
|
93 |
+
center_x, center_y, center_z = blue_block.position
|
94 |
+
# 9cm to the left so y = min_y - 9cm
|
95 |
+
x = center_x
|
96 |
+
y = min_y - cm2index(9, 'y')
|
97 |
+
z = center_z
|
98 |
+
affordance_map[x, y, z] = 1
|
99 |
+
ret_val = affordance_map
|
100 |
+
|
101 |
+
# Query: a point 21cm away from the leftmost block.
|
102 |
+
affordance_map = get_empty_affordance_map()
|
103 |
+
leftmost_block = parse_query_obj('leftmost block')
|
104 |
+
# positive normal because we are moving away from the block.
|
105 |
+
moving_dir = leftmost_block.normal
|
106 |
+
affordance_xyz = leftmost_block.position + cm2index(21, moving_dir)
|
107 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
108 |
+
ret_val = affordance_map
|
109 |
+
|
110 |
+
# Query: a point 7cm above the tray that contains the lemon.
|
111 |
+
affordance_map = get_empty_affordance_map()
|
112 |
+
tray_with_lemon = parse_query_obj('tray that contains the lemon')
|
113 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = tray_with_lemon.aabb
|
114 |
+
center_x, center_y, center_z = tray_with_lemon.position
|
115 |
+
# 7cm above so z = max_z + 7cm
|
116 |
+
x = center_x
|
117 |
+
y = center_y
|
118 |
+
z = max_z + cm2index(7, 'z')
|
119 |
+
affordance_map[x, y, z] = 1
|
120 |
+
ret_val = affordance_map
|
121 |
+
|
122 |
+
# Query: a point 3cm to the left of [45, 49, 99].
|
123 |
+
affordance_map = get_empty_affordance_map()
|
124 |
+
# left so y = 49 - 3cm
|
125 |
+
x = 45
|
126 |
+
y = 49 - cm2index(3, 'y')
|
127 |
+
z = 99
|
128 |
+
affordance_map[x, y, z] = 1
|
129 |
+
ret_val = affordance_map
|
130 |
+
|
131 |
+
# Query: the brown line.
|
132 |
+
brown_line = parse_query_obj('brown line')
|
133 |
+
affordance_map = brown_line.occupancy_map
|
134 |
+
ret_val = affordance_map
|
135 |
+
|
136 |
+
# Query: a point 13cm to the left of the gripper.
|
137 |
+
affordance_map = get_empty_affordance_map()
|
138 |
+
gripper = parse_query_obj('gripper')
|
139 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = gripper.aabb
|
140 |
+
center_x, center_y, center_z = gripper.position
|
141 |
+
# 13cm to the left so y = min_y - 13cm
|
142 |
+
x = center_x
|
143 |
+
y = min_y - cm2index(13, 'y')
|
144 |
+
z = center_z
|
145 |
+
affordance_map[x, y, z] = 1
|
146 |
+
ret_val = affordance_map
|
147 |
+
|
148 |
+
# Query: a point 17cm above the back left corner of the table.
|
149 |
+
affordance_map = get_empty_affordance_map()
|
150 |
+
table = parse_query_obj('table')
|
151 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
152 |
+
center_x, center_y, center_z = table.position
|
153 |
+
# 17cm on top of back left corner so x = min_x, y = min_y, z = max_z + 17cm
|
154 |
+
x = min_x
|
155 |
+
y = min_y
|
156 |
+
z = max_z + cm2index(17, 'z')
|
157 |
+
affordance_map[x, y, z] = 1
|
158 |
+
ret_val = affordance_map
|
159 |
+
|
160 |
+
# Query: a point at the center of the green block.
|
161 |
+
affordance_map = get_empty_affordance_map()
|
162 |
+
green_block = parse_query_obj('green block')
|
163 |
+
center_x, center_y, center_z = green_block.position
|
164 |
+
affordance_map[center_x, center_y, center_z] = 1
|
165 |
+
ret_val = affordance_map
|
166 |
+
|
167 |
+
# Query: the right side of the table.
|
168 |
+
affordance_map = get_empty_affordance_map()
|
169 |
+
table = parse_query_obj('table')
|
170 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
171 |
+
center_x, center_y, center_z = table.position
|
172 |
+
# right side so y = max_y
|
173 |
+
x = center_x
|
174 |
+
y = max_y
|
175 |
+
z = center_z
|
176 |
+
affordance_map[x, y, z] = 1
|
177 |
+
ret_val = affordance_map
|
Sim/value_maps/sim_get_avoidance_map_prompt.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_avoidance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: 11cm from the blue block.
|
6 |
+
avoidance_map = get_empty_avoidance_map()
|
7 |
+
blue_block = parse_query_obj('blue block')
|
8 |
+
set_voxel_by_radius(avoidance_map, blue_block.position, radius_cm=11, value=1)
|
9 |
+
ret_val = avoidance_map
|
10 |
+
|
11 |
+
# Query: 7cm near the pink block.
|
12 |
+
avoidance_map = get_empty_avoidance_map()
|
13 |
+
pink_block = parse_query_obj('pink block')
|
14 |
+
set_voxel_by_radius(avoidance_map, pink_block.position, radius_cm=7, value=1)
|
15 |
+
ret_val = avoidance_map
|
16 |
+
|
17 |
+
# Query: 13cm around the brown block and 5cm around the green block.
|
18 |
+
avoidance_map = get_empty_avoidance_map()
|
19 |
+
brown_block = parse_query_obj('brown block')
|
20 |
+
set_voxel_by_radius(avoidance_map, brown_block.position, radius_cm=13, value=1)
|
21 |
+
green_block = parse_query_obj('green block')
|
22 |
+
set_voxel_by_radius(avoidance_map, green_block.position, radius_cm=5, value=1)
|
23 |
+
ret_val = avoidance_map
|
24 |
+
|
25 |
+
# Query: the blue line.
|
26 |
+
blue_line = parse_query_obj('blue_line')
|
27 |
+
avoidance_map = blue_line.occupancy_map
|
28 |
+
ret_val = avoidance_map
|
29 |
+
|
30 |
+
# Query: anywhere on the front side of the blue block.
|
31 |
+
avoidance_map = get_empty_avoidance_map()
|
32 |
+
blue_block = parse_query_obj('blue block')
|
33 |
+
center_x, center_y, center_z = blue_block.position
|
34 |
+
# front side so x > center_x
|
35 |
+
avoidance_map[center_x:, :, :] = 1
|
36 |
+
ret_val = avoidance_map
|
37 |
+
|
38 |
+
# Query: anywhere on the left of the green block.
|
39 |
+
avoidance_map = get_empty_avoidance_map()
|
40 |
+
green_block = parse_query_obj('green block')
|
41 |
+
center_x, center_y, center_z = green_block.position
|
42 |
+
# left side so y < center_y
|
43 |
+
avoidance_map[:, :center_y, :] = 1
|
44 |
+
ret_val = avoidance_map
|
45 |
+
|
46 |
+
# Query: anywhere behind the pink block.
|
47 |
+
avoidance_map = get_empty_avoidance_map()
|
48 |
+
pink_block = parse_query_obj('pink block')
|
49 |
+
center_x, center_y, center_z = pink_block.position
|
50 |
+
# behind so x < center_x
|
51 |
+
avoidance_map[:center_x, :, :] = 1
|
52 |
+
ret_val = avoidance_map
|
53 |
+
|
54 |
+
# Query: anywhere above the brown block.
|
55 |
+
avoidance_map = get_empty_avoidance_map()
|
56 |
+
brown_block = parse_query_obj('brown block')
|
57 |
+
center_x, center_y, center_z = brown_block.position
|
58 |
+
# above so z > center_z
|
59 |
+
avoidance_map[:, :, center_z:] = 1
|
60 |
+
ret_val = avoidance_map
|
Sim/value_maps/sim_get_gripper_map_prompt.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_gripper_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: open everywhere except 1cm around the green block.
|
6 |
+
gripper_map = get_empty_gripper_map()
|
7 |
+
# open everywhere
|
8 |
+
gripper_map[:, :, :] = 0
|
9 |
+
# close when 1cm around the green block
|
10 |
+
green_block = parse_query_obj('green block')
|
11 |
+
set_voxel_by_radius(gripper_map, green_block.position, radius_cm=1, value=1)
|
12 |
+
ret_val = gripper_map
|
13 |
+
|
14 |
+
# Query: close everywhere but open when on top of the back left corner of the table.
|
15 |
+
gripper_map = get_empty_gripper_map()
|
16 |
+
# close everywhere
|
17 |
+
gripper_map[:, :, :] = 1
|
18 |
+
# open when on top of the back left corner of the table
|
19 |
+
table = parse_query_obj('table')
|
20 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
21 |
+
center_x, center_y, center_z = table.position
|
22 |
+
# back so x = min_x, left so y = min_y, top so we add to z
|
23 |
+
x = min_x
|
24 |
+
y = min_y
|
25 |
+
z = max_z + cm2index(10, 'z')
|
26 |
+
set_voxel_by_radius(gripper_map, (x, y, z), radius_cm=10, value=0)
|
27 |
+
ret_val = gripper_map
|
28 |
+
|
29 |
+
# Query: always open except when you are on the right side of the table.
|
30 |
+
gripper_map = get_empty_gripper_map()
|
31 |
+
# always open
|
32 |
+
gripper_map[:, :, :] = 0
|
33 |
+
# close when you are on the right side of the table
|
34 |
+
table = parse_query_obj('table')
|
35 |
+
center_x, center_y, center_z = table.position
|
36 |
+
# right side so y is greater than center_y
|
37 |
+
gripper_map[:, center_y:, :] = 1
|
38 |
+
|
39 |
+
# Query: always close except when you are on the back side of the table.
|
40 |
+
gripper_map = get_empty_gripper_map()
|
41 |
+
# always close
|
42 |
+
gripper_map[:, :, :] = 1
|
43 |
+
# open when you are on the back side of the table
|
44 |
+
table = parse_query_obj('table')
|
45 |
+
center_x, center_y, center_z = table.position
|
46 |
+
# back side so x is less than center_x
|
47 |
+
gripper_map[:center_x, :, :] = 0
|
48 |
+
ret_val = gripper_map
|
49 |
+
|
50 |
+
# Query: open everywhere except 1cm around the topmost drawer handle.
|
51 |
+
gripper_map = get_empty_gripper_map()
|
52 |
+
# open everywhere
|
53 |
+
gripper_map[:, :, :] = 0
|
54 |
+
# close when 1cm around the topmost drawer handle
|
55 |
+
topmost_drawer_handle = parse_query_obj('topmost drawer handle')
|
56 |
+
set_voxel_by_radius(gripper_map, topmost_drawer_handle.position, radius_cm=1, value=1)
|
57 |
+
ret_val = gripper_map
|
Sim/value_maps/sim_get_rotation_map_prompt.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_rotation_map, set_voxel_by_radius, cm2index, vec2quat
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
|
5 |
+
# Query: face the green block.
|
6 |
+
rotation_map = get_empty_rotation_map()
|
7 |
+
green_block = parse_query_obj('green block')
|
8 |
+
target_rotation = vec2quat(-green_block.normal)
|
9 |
+
rotation_map[:, :, :] = target_rotation
|
10 |
+
ret_val = rotation_map
|
11 |
+
|
12 |
+
# Query: face the table when within 30cm from table center.
|
13 |
+
rotation_map = get_empty_rotation_map()
|
14 |
+
table = parse_query_obj('table')
|
15 |
+
table_center = table.position
|
16 |
+
target_rotation = vec2quat(-table.normal)
|
17 |
+
set_voxel_by_radius(rotation_map, table_center, radius_cm=30, value=target_rotation)
|
18 |
+
ret_val = rotation_map
|
19 |
+
|
20 |
+
# Query: face the topmost drawer handle.
|
21 |
+
rotation_map = get_empty_rotation_map()
|
22 |
+
topmost_drawer_handle = parse_query_obj('topmost drawer handle')
|
23 |
+
target_rotation = vec2quat(-topmost_drawer_handle.normal)
|
24 |
+
rotation_map[:, :, :] = target_rotation
|
25 |
+
ret_val = rotation_map
|
Sim/value_maps/sim_get_velocity_map_prompt.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_velocity_map, set_voxel_by_radius, cm2index
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
|
5 |
+
# Query: faster when on the left side of the table and a quarter of the speed when on the other side of the table.
|
6 |
+
velocity_map = get_empty_velocity_map()
|
7 |
+
table = parse_query_obj('table')
|
8 |
+
center_x, center_y, center_z = table.position
|
9 |
+
# faster on left side so y < center_y
|
10 |
+
velocity_map[:, :center_y, :] = 1.5
|
11 |
+
# a quarter of the speed on the other side so y > center_y
|
12 |
+
velocity_map[:, center_y:, :] = 0.25
|
13 |
+
ret_val = velocity_map
|
14 |
+
|
15 |
+
# Query: slow down by a quarter.
|
16 |
+
velocity_map = get_empty_velocity_map()
|
17 |
+
velocity_map[:] = 0.75
|
18 |
+
ret_val = velocity_map
|
19 |
+
|
20 |
+
# Query: quarter of the speed when within 9cm from the yellow block.
|
21 |
+
velocity_map = get_empty_velocity_map()
|
22 |
+
yellow_block = parse_query_obj('yellow block')
|
23 |
+
set_voxel_by_radius(velocity_map, yellow_block.position, radius_cm=9, value=0.25)
|
24 |
+
ret_val = velocity_map
|
25 |
+
|
26 |
+
# Query: quarter of the speed in the back side of the table.
|
27 |
+
velocity_map = get_empty_velocity_map()
|
28 |
+
table = parse_query_obj('table')
|
29 |
+
center_x, center_y, center_z = table.position
|
30 |
+
# a quarter of the speed in the back side so x < center_x
|
31 |
+
velocity_map[:center_x, :, :] = 0.25
|
32 |
+
ret_val = velocity_map
|
33 |
+
|
34 |
+
# Query: faster speed in the right side of the table.
|
35 |
+
velocity_map = get_empty_velocity_map()
|
36 |
+
table = parse_query_obj('table')
|
37 |
+
center_x, center_y, center_z = table.position
|
38 |
+
# faster in the right side so y > center_y
|
39 |
+
velocity_map[:, center_y:, :] = 1.5
|
40 |
+
ret_val = velocity_map
|
41 |
+
|
42 |
+
# Query: quarter of the speed when within 11cm from the brown block.
|
43 |
+
velocity_map = get_empty_velocity_map()
|
44 |
+
brown_block = parse_query_obj('brown_block')
|
45 |
+
set_voxel_by_radius(velocity_map, brown_block.position, radius_cm=11, value=0.25)
|
46 |
+
ret_val = velocity_map
|
VoxPoserApiExamples/Real/composer/real_composer_prompt.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute, reset_to_default_pose
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
from plan_utils import get_affordance_map, get_avoidance_map, get_velocity_map, get_rotation_map, get_gripper_map
|
5 |
+
|
6 |
+
# Query: move ee forward for 10cm.
|
7 |
+
movable = parse_query_obj('gripper')
|
8 |
+
affordance_map = get_affordance_map(f'a point 10cm in front of {movable.position}')
|
9 |
+
execute(movable, affordance_map)
|
10 |
+
|
11 |
+
# Query: go back to default.
|
12 |
+
reset_to_default_pose()
|
13 |
+
|
14 |
+
# Query: move the gripper behind the bowl, and slow down when near the bowl.
|
15 |
+
movable = parse_query_obj('gripper')
|
16 |
+
affordance_map = get_affordance_map('a point 15cm behind the bowl')
|
17 |
+
avoidance_map = get_avoidance_map('10cm near the bowl')
|
18 |
+
velocity_map = get_velocity_map('slow down when near the bowl')
|
19 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
20 |
+
|
21 |
+
# Query: move to the back side of the table while staying at least 5cm from the blue block.
|
22 |
+
movable = parse_query_obj('gripper')
|
23 |
+
affordance_map = get_affordance_map('a point on the back side of the table')
|
24 |
+
avoidance_map = get_avoidance_map('5cm from the blue block')
|
25 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
26 |
+
|
27 |
+
# Query: move to the top of the plate and face the plate.
|
28 |
+
movable = parse_query_obj('gripper')
|
29 |
+
affordance_map = get_affordance_map('a point 10cm above the plate')
|
30 |
+
rotation_map = get_rotation_map('face the plate')
|
31 |
+
execute(movable, affordance_map=affordance_map, rotation_map=rotation_map)
|
32 |
+
|
33 |
+
# Query: drop the toy inside container.
|
34 |
+
movable = parse_query_obj('gripper')
|
35 |
+
affordance_map = get_affordance_map('a point 15cm above the container')
|
36 |
+
gripper_map = get_gripper_map('close everywhere but open when on top of the container')
|
37 |
+
execute(movable, affordance_map=affordance_map, gripper_map=gripper_map)
|
38 |
+
|
39 |
+
# Query: push close the topmost drawer.
|
40 |
+
movable = parse_query_obj('topmost drawer handle')
|
41 |
+
affordance_map = get_affordance_map('a point 30cm into the topmost drawer handle')
|
42 |
+
execute(movable, affordance_map=affordance_map)
|
43 |
+
|
44 |
+
# Query: push the second to the left block along the red line.
|
45 |
+
movable = parse_query_obj('second to the left block')
|
46 |
+
affordance_map = get_affordance_map('the red line')
|
47 |
+
execute(movable, affordance_map=affordance_map)
|
48 |
+
|
49 |
+
# Query: grasp the blue block from the table at a quarter of the speed.
|
50 |
+
movable = parse_query_obj('gripper')
|
51 |
+
affordance_map = get_affordance_map('a point at the center of blue block')
|
52 |
+
velocity_map = get_velocity_map('quarter of the speed')
|
53 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the blue block')
|
54 |
+
execute(movable, affordance_map=affordance_map, velocity_map=velocity_map, gripper_map=gripper_map)
|
55 |
+
|
56 |
+
# Query: move to the left of the brown block.
|
57 |
+
movable = parse_query_obj('gripper')
|
58 |
+
affordance_map = get_affordance_map('a point 10cm to the left of the brown block')
|
59 |
+
execute(movable, affordance_map=affordance_map)
|
60 |
+
|
61 |
+
# Query: move to the top of the tray that contains the lemon.
|
62 |
+
movable = parse_query_obj('gripper')
|
63 |
+
affordance_map = get_affordance_map('a point 10cm above the tray that contains the lemon')
|
64 |
+
execute(movable, affordance_map=affordance_map)
|
65 |
+
|
66 |
+
# Query: close drawer by 5cm.
|
67 |
+
movable = parse_query_obj('drawer handle')
|
68 |
+
affordance_map = get_affordance_map('a point 5cm into the drawer handle')
|
69 |
+
execute(movable, affordance_map=affordance_map)
|
70 |
+
|
71 |
+
# Query: move to 5cm on top of the soda can, at 0.5x speed when within 20cm of the wooden mug, and keep at least 15cm away from the wooden mug.
|
72 |
+
movable = parse_query_obj('gripper')
|
73 |
+
affordance_map = get_affordance_map('a point 5cm above the soda can')
|
74 |
+
avoidance_map = get_avoidance_map('15cm from the wooden mug')
|
75 |
+
velocity_map = get_velocity_map('0.5x speed when within 20cm of the wooden mug')
|
76 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
77 |
+
|
78 |
+
# Query: wipe the red dot but avoid the blue block.
|
79 |
+
movable = parse_query_obj('gripper')
|
80 |
+
affordance_map = get_affordance_map('the red dot')
|
81 |
+
avoidance_map = get_avoidance_map('10cm from the blue block')
|
82 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
83 |
+
|
84 |
+
# Query: grasp the mug from the shelf.
|
85 |
+
movable = parse_query_obj('gripper')
|
86 |
+
affordance_map = get_affordance_map('a point at the center of the mug handle')
|
87 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the mug handle')
|
88 |
+
execute(movable, affordance_map=affordance_map, gripper_map=gripper_map)
|
89 |
+
|
90 |
+
# Query: move to 10cm on top of the soup bowl, and 5cm to the left of the soup bowl, while away from the glass, at 0.75x speed.
|
91 |
+
movable = parse_query_obj('gripper')
|
92 |
+
affordance_map = get_affordance_map('a point 10cm above and 5cm to the left of the soup bowl')
|
93 |
+
avoidance_map = get_avoidance_map('10cm from the glass')
|
94 |
+
velocity_map = get_velocity_map('0.75x speed')
|
95 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
96 |
+
|
97 |
+
# Query: open gripper.
|
98 |
+
movable = parse_query_obj('gripper')
|
99 |
+
gripper_map = get_gripper_map('open everywhere')
|
100 |
+
execute(movable, gripper_map=gripper_map)
|
101 |
+
|
102 |
+
# Query: turn counter-clockwise by 180 degrees.
|
103 |
+
movable = parse_query_obj('gripper')
|
104 |
+
rotation_map = get_rotation_map('turn counter-clockwise by 180 degrees')
|
105 |
+
execute(movable, rotation_map=rotation_map)
|
106 |
+
|
107 |
+
# Query: sweep all particles to the left side of the table.
|
108 |
+
particles = parse_query_obj('particles')
|
109 |
+
for particle in particles:
|
110 |
+
movable = particle
|
111 |
+
affordance_map = get_affordance_map('a point on the left side of the table')
|
112 |
+
execute(particle, affordance_map=affordance_map)
|
113 |
+
|
114 |
+
# Query: grasp the bottom drawer handle while moving at 0.5x speed.
|
115 |
+
movable = parse_query_obj('gripper')
|
116 |
+
affordance_map = get_affordance_map('a point at the center of the bottom drawer handle')
|
117 |
+
velocity_map = get_velocity_map('0.5x speed')
|
118 |
+
rotation_map = get_rotation_map('face the bottom drawer handle')
|
119 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the bottom drawer handle')
|
120 |
+
execute(movable, affordance_map=affordance_map, velocity_map=velocity_map, rotation_map=rotation_map, gripper_map=gripper_map)
|
VoxPoserApiExamples/Real/perception/real_parse_query_obj_prompt.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import detect
|
3 |
+
|
4 |
+
objects = ['table', 'gripper', 'green block', 'cardboard box']
|
5 |
+
# Query: gripper.
|
6 |
+
gripper = detect('gripper')[0]
|
7 |
+
ret_val = gripper
|
8 |
+
|
9 |
+
objects = ['table', 'gripper', 'drawer', 'egg', 'egg', 'plate']
|
10 |
+
# Query: topmost handle.
|
11 |
+
handles = detect('drawer handle')
|
12 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
13 |
+
top_handle = handles[-1]
|
14 |
+
ret_val = top_handle
|
15 |
+
|
16 |
+
objects = ['table', 'gripper', 'yellow block', 'charging cable', 'cyan block', 'magenta block']
|
17 |
+
# Query: second to the left block.
|
18 |
+
blocks = detect('block')
|
19 |
+
blocks = sorted(blocks, key=lambda x: x.position[1])
|
20 |
+
second_left_block = blocks[1]
|
21 |
+
ret_val = second_left_block
|
22 |
+
|
23 |
+
objects = ['table', 'gripper', 'iPhone', 'ruler', 'pink line', 'blue line']
|
24 |
+
# Query: the front most line on the table.
|
25 |
+
lines = detect('line')
|
26 |
+
lines = sorted(lines, key=lambda x: x.position[0])
|
27 |
+
front_most_line = lines[-1]
|
28 |
+
ret_val = front_most_line
|
29 |
+
|
30 |
+
objects = ['table', 'gripper', 'vase', 'napkin box', 'mask']
|
31 |
+
# Query: table.
|
32 |
+
table = detect('table')[0]
|
33 |
+
ret_val = table
|
34 |
+
|
35 |
+
objects = ['table', 'gripper', 'bottle', 'drawer', 'bowl', 'bag']
|
36 |
+
# Query: second to the bottom handle.
|
37 |
+
handles = detect('drawer handle')
|
38 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
39 |
+
second_bottom_handle = handles[1]
|
40 |
+
ret_val = second_bottom_handle
|
41 |
+
|
42 |
+
objects = ['table', 'gripper', 'brown line', 'red block', 'monitor']
|
43 |
+
# Query: brown line.
|
44 |
+
brown_line = detect('brown line')[0]
|
45 |
+
ret_val = brown_line
|
46 |
+
|
47 |
+
objects = ['table', 'gripper', 'green block', 'cup holder', 'black block']
|
48 |
+
# Query: block.
|
49 |
+
block = detect('green block')[0]
|
50 |
+
ret_val = block
|
51 |
+
|
52 |
+
objects = ['table', 'gripper', 'mouse', 'yellow bowl', 'brown bowl', 'sticker']
|
53 |
+
# Query: bowl closest to the sticker.
|
54 |
+
bowls = detect('bowl')
|
55 |
+
sticker = detect('sticker')[0]
|
56 |
+
closest_bowl = min(bowls, key=lambda x: np.linalg.norm(x.position - sticker.position))
|
57 |
+
ret_val = closest_bowl
|
58 |
+
|
59 |
+
objects = ['table', 'gripper', 'keyboard', 'brown bag', 'pink bag', 'red tape', 'bottle']
|
60 |
+
# Query: bag with the red tape on top.
|
61 |
+
bags = detect('bag')
|
62 |
+
red_tape = detect('red tape')[0]
|
63 |
+
bag_with_red_tape = min(bags, key=lambda x: np.linalg.norm(x.position - red_tape.position))
|
64 |
+
ret_val = bag_with_red_tape
|
65 |
+
|
66 |
+
objects = ['table', 'gripper', 'grape', 'wood tray', 'strawberry', 'white tray', 'blue tray', 'bread']
|
67 |
+
# Query: tray that contains the bread.
|
68 |
+
trays = detect('tray')
|
69 |
+
bread = detect('bread')[0]
|
70 |
+
tray_with_bread = min(trays, key=lambda x: np.linalg.norm(x.position - bread.position))
|
71 |
+
ret_val = tray_with_bread
|
72 |
+
|
73 |
+
objects = ['table', 'gripper', 'drawer']
|
74 |
+
# Query: top drawer handle.
|
75 |
+
handles = detect('drawer handle')
|
76 |
+
top_drawer_handle = max(handles, key=lambda x: x.position[2])
|
77 |
+
ret_val = top_drawer_handle
|
78 |
+
|
79 |
+
objects = ['table', 'gripper', 'door']
|
80 |
+
# Query: the thing you can open the door with.
|
81 |
+
door_handle = detect('door handle')[0]
|
82 |
+
ret_val = door_handle
|
83 |
+
|
84 |
+
objects = ['table', 'gripper', 'glass', 'vase', 'plastic bottle', 'block', 'phone case']
|
85 |
+
# Query: anything fragile.
|
86 |
+
fragile_items = []
|
87 |
+
for obj in ['glass', 'vase']:
|
88 |
+
item = detect(obj)[0]
|
89 |
+
fragile_items.append(item)
|
90 |
+
ret_val = fragile_items
|
91 |
+
|
92 |
+
objects = ['table', 'gripper', 'fridge']
|
93 |
+
# Query: fridge handle.
|
94 |
+
fridge_handle = detect('fridge handle')[0]
|
95 |
+
ret_val = fridge_handle
|
96 |
+
|
97 |
+
objects = ['table', 'gripper', 'blue block', 'red block']
|
98 |
+
# Query: green block.
|
99 |
+
ret_val = None
|
100 |
+
|
101 |
+
objects = ['table', 'gripper', 'yellow bowl', 'red spoon']
|
102 |
+
# Query: gripper.
|
103 |
+
gripper = detect('gripper')[0]
|
104 |
+
ret_val = gripper
|
VoxPoserApiExamples/Real/planner/real_planner_prompt.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
import action_utils import composer
|
5 |
+
|
6 |
+
objects = ['blue block', 'yellow block', 'mug']
|
7 |
+
# Query: place the blue block on the yellow block, and avoid the mug at all time.
|
8 |
+
composer("grasp the blue block while keeping at least 15cm away from the mug")
|
9 |
+
composer("back to default pose")
|
10 |
+
composer("move to 5cm on top of the yellow block while keeping at least 15cm away from the mug")
|
11 |
+
composer("open gripper")
|
12 |
+
# done
|
13 |
+
|
14 |
+
objects = ['airpods', 'drawer']
|
15 |
+
# Query: Open the drawer slowly.
|
16 |
+
composer("grasp the drawer handle, at 0.5x speed")
|
17 |
+
composer("move away from the drawer handle by 25cm, at 0.5x speed")
|
18 |
+
composer("open gripper, at 0.5x speed")
|
19 |
+
# done
|
20 |
+
|
21 |
+
objects = ['tissue box', 'tissue', 'bowl']
|
22 |
+
# Query: Can you pass me a tissue and place it next to the bowl?
|
23 |
+
composer("grasp the tissue")
|
24 |
+
composer("back to default pose")
|
25 |
+
composer("move to 10cm to the right of the bowl")
|
26 |
+
composer("open gripper")
|
27 |
+
composer("back to default pose")
|
28 |
+
# done
|
29 |
+
|
30 |
+
objects = ['charger', 'outlet']
|
31 |
+
# Query: unplug the charger from the wall.
|
32 |
+
composer("grasp the charger")
|
33 |
+
composer("back to default pose")
|
34 |
+
# done
|
35 |
+
|
36 |
+
objects = ['grape', 'lemon', 'drill', 'router', 'bread', 'tray']
|
37 |
+
# Query: put the sweeter fruit in the tray that contains the bread.
|
38 |
+
composer("grasp the grape")
|
39 |
+
composer("back to default pose")
|
40 |
+
composer("move to the top of the tray that contains the bread")
|
41 |
+
composer("open gripper")
|
42 |
+
# done
|
43 |
+
|
44 |
+
objects = ['marbles', 'tray', 'broom']
|
45 |
+
# Query: Can you sweep the marbles into the tray?
|
46 |
+
composer("grasp the broom")
|
47 |
+
composer("back to default pose")
|
48 |
+
composer("push the marbles into the tray")
|
49 |
+
# done
|
50 |
+
|
51 |
+
objects = ['orange', 'QR code', 'lemon', 'drawer']
|
52 |
+
# Query: put the sour fruit into the top drawer.
|
53 |
+
composer("grasp the top drawer handle")
|
54 |
+
composer("move away from the top drawer handle by 25cm")
|
55 |
+
composer("open gripper")
|
56 |
+
composer("back to default pose")
|
57 |
+
composer("grasp the lemon")
|
58 |
+
composer("move to 10cm on top of the top drawer")
|
59 |
+
composer("open gripper")
|
60 |
+
# done
|
61 |
+
|
62 |
+
objects = ['fridge', 'hot soup']
|
63 |
+
# Query: Open the fridge door and be careful around the hot soup.
|
64 |
+
composer("grasp the fridge handle and keep at least 15cm away from the hot soup")
|
65 |
+
composer("move away from the fridge handle by 25cm and keep at least 15cm away from the hot soup")
|
66 |
+
composer("open gripper")
|
67 |
+
# done
|
68 |
+
|
69 |
+
objects = ['cyan bowl', 'yellow bowl', 'box', 'ice cream']
|
70 |
+
# Query: move to the top of the cyan bowl.
|
71 |
+
composer("move to the top of the cyan bowl")
|
72 |
+
# done
|
73 |
+
|
74 |
+
objects = ['drawer', 'umbrella']
|
75 |
+
# Query: close the drawer.
|
76 |
+
composer("push close the drawer handle by 25cm")
|
77 |
+
# done
|
78 |
+
|
79 |
+
objects = ['plate', 'steak', 'fork', 'knife', 'spoon']
|
80 |
+
# Query: Could you please set up the fork for the steak for me?
|
81 |
+
composer("grasp the fork")
|
82 |
+
composer("back to default pose")
|
83 |
+
composer("move to 10cm to the right of the plate")
|
84 |
+
composer("open gripper")
|
85 |
+
composer("back to default pose")
|
86 |
+
# done
|
87 |
+
|
88 |
+
objects = ['light switch']
|
89 |
+
# Query: Press down the switch.
|
90 |
+
composer("close the gripper")
|
91 |
+
composer("move to the center of the light switch")
|
92 |
+
composer("back to default pose")
|
93 |
+
# done
|
94 |
+
|
95 |
+
objects = ['beer']
|
96 |
+
# Query: turn close the beer.
|
97 |
+
composer("grasp the beer cap")
|
98 |
+
composer("turn clockwise by 180 degrees")
|
99 |
+
composer("back to default pose")
|
100 |
+
# done
|
101 |
+
|
102 |
+
objects = ['steak', 'grill', 'plate']
|
103 |
+
# Query: Take the steak out of the grill and put it flat on the plate.
|
104 |
+
composer("grasp the steak")
|
105 |
+
composer("back to default pose")
|
106 |
+
composer("rotate the gripper to be 45 degrees slanted relative to the plate")
|
107 |
+
composer("move to 10cm on top of the plate")
|
108 |
+
composer("open gripper")
|
109 |
+
composer("back to default pose")
|
110 |
+
# done
|
111 |
+
|
112 |
+
objects = ['trash can', 'napkin']
|
113 |
+
# Query: sort napkin into trash can.
|
114 |
+
napkin = parse_query_obj("napkin")
|
115 |
+
trash_can = parse_query_obj("trash can")
|
116 |
+
while np.linalg.norm(napkin.position - trash_can.position) > 0.1:
|
117 |
+
composer("grasp the napkin")
|
118 |
+
composer("move to 10cm on top of the trash can")
|
119 |
+
composer("open gripper")
|
120 |
+
composer("back to default pose")
|
121 |
+
# done
|
VoxPoserApiExamples/Real/value_maps/real_get_affordance_map_prompt.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_affordance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: a point 10cm in front of [10, 15, 60].
|
6 |
+
affordance_map = get_empty_affordance_map()
|
7 |
+
# 10cm in front of so we add to x-axis
|
8 |
+
x = 10 + cm2index(10, 'x')
|
9 |
+
y = 15
|
10 |
+
z = 60
|
11 |
+
affordance_map[x, y, z] = 1
|
12 |
+
ret_val = affordance_map
|
13 |
+
|
14 |
+
# Query: a point on the right side of the table.
|
15 |
+
affordance_map = get_empty_affordance_map()
|
16 |
+
table = parse_query_obj('table')
|
17 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
18 |
+
center_x, center_y, center_z = table.position
|
19 |
+
# right side so y = max_y
|
20 |
+
x = center_x
|
21 |
+
y = max_y
|
22 |
+
z = center_z
|
23 |
+
affordance_map[x, y, z] = 1
|
24 |
+
ret_val = affordance_map
|
25 |
+
|
26 |
+
# Query: a point 20cm on top of the container.
|
27 |
+
affordance_map = get_empty_affordance_map()
|
28 |
+
container = parse_query_obj('container')
|
29 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = container.aabb
|
30 |
+
center_x, center_y, center_z = container.position
|
31 |
+
# 20cm on top of so we add to z-axis
|
32 |
+
x = center_x
|
33 |
+
y = center_y
|
34 |
+
z = max_z + cm2index(20, 'z')
|
35 |
+
affordance_map[x, y, z] = 1
|
36 |
+
ret_val = affordance_map
|
37 |
+
|
38 |
+
# Query: a point 1cm to the left of the brown block.
|
39 |
+
affordance_map = get_empty_affordance_map()
|
40 |
+
brown_block = parse_query_obj('brown block')
|
41 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = brown_block.aabb
|
42 |
+
center_x, center_y, center_z = brown_block.position
|
43 |
+
# 1cm to the left of so we subtract from y-axis
|
44 |
+
x = center_x
|
45 |
+
y = min_y - cm2index(1, 'y')
|
46 |
+
z = center_z
|
47 |
+
affordance_map[x, y, z] = 1
|
48 |
+
ret_val = affordance_map
|
49 |
+
|
50 |
+
# Query: anywhere within 20cm of the right most block.
|
51 |
+
affordance_map = get_empty_affordance_map()
|
52 |
+
right_most_block = parse_query_obj('the right most block')
|
53 |
+
set_voxel_by_radius(affordance_map, right_most_block.position, radius_cm=20, value=1)
|
54 |
+
|
55 |
+
# Query: a point on the back side of the table.
|
56 |
+
affordance_map = get_empty_affordance_map()
|
57 |
+
table = parse_query_obj('table')
|
58 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
59 |
+
center_x, center_y, center_z = table.position
|
60 |
+
# back side so x = min_x
|
61 |
+
x = min_x
|
62 |
+
y = center_y
|
63 |
+
z = center_z
|
64 |
+
affordance_map[x, y, z] = 1
|
65 |
+
ret_val = affordance_map
|
66 |
+
|
67 |
+
# Query: a point on the front right corner of the table.
|
68 |
+
affordance_map = get_empty_affordance_map()
|
69 |
+
table = parse_query_obj('table')
|
70 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
71 |
+
center_x, center_y, center_z = table.position
|
72 |
+
# front right corner so x = max_x and y = max_y
|
73 |
+
x = max_x
|
74 |
+
y = max_y
|
75 |
+
z = center_z
|
76 |
+
affordance_map[x, y, z] = 1
|
77 |
+
ret_val = affordance_map
|
78 |
+
|
79 |
+
# Query: a point 30cm into the topmost drawer handle.
|
80 |
+
affordance_map = get_empty_affordance_map()
|
81 |
+
top_handle = parse_query_obj('topmost drawer handle')
|
82 |
+
# negative normal because we are moving into the handle.
|
83 |
+
moving_dir = -top_handle.normal
|
84 |
+
affordance_xyz = top_handle.position + cm2index(30, moving_dir)
|
85 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
86 |
+
ret_val = affordance_map
|
87 |
+
|
88 |
+
# Query: a point 5cm above the blue block.
|
89 |
+
affordance_map = get_empty_affordance_map()
|
90 |
+
blue_block = parse_query_obj('blue block')
|
91 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = blue_block.aabb
|
92 |
+
center_x, center_y, center_z = blue_block.position
|
93 |
+
# 5cm above so we add to z-axis
|
94 |
+
x = center_x
|
95 |
+
y = center_y
|
96 |
+
z = max_z + cm2index(5, 'z')
|
97 |
+
affordance_map[x, y, z] = 1
|
98 |
+
ret_val = affordance_map
|
99 |
+
|
100 |
+
# Query: a point 20cm away from the leftmost block.
|
101 |
+
affordance_map = get_empty_affordance_map()
|
102 |
+
leftmost_block = parse_query_obj('leftmost block')
|
103 |
+
# positive normal because we are moving away from the block.
|
104 |
+
moving_dir = leftmost_block.normal
|
105 |
+
affordance_xyz = leftmost_block.position + cm2index(20, moving_dir)
|
106 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
107 |
+
ret_val = affordance_map
|
108 |
+
|
109 |
+
# Query: a point 4cm to the left of and 10cm on top of the tray that contains the lemon.
|
110 |
+
affordance_map = get_empty_affordance_map()
|
111 |
+
tray_with_lemon = parse_query_obj('tray that contains the lemon')
|
112 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = tray_with_lemon.aabb
|
113 |
+
center_x, center_y, center_z = tray_with_lemon.position
|
114 |
+
# 4cm to the left of so we subtract from y-axis, and 10cm on top of so we add to z-axis
|
115 |
+
x = center_x
|
116 |
+
y = min_y - cm2index(4, 'y')
|
117 |
+
z = max_z + cm2index(10, 'z')
|
118 |
+
affordance_map[x, y, z] = 1
|
119 |
+
ret_val = affordance_map
|
120 |
+
|
121 |
+
# Query: a point 10cm to the right of [45 49 66], and 5cm above it.
|
122 |
+
affordance_map = get_empty_affordance_map()
|
123 |
+
# 10cm to the right of so we add to y-axis, and 5cm above it so we add to z-axis
|
124 |
+
x = 45
|
125 |
+
y = 49 + cm2index(10, 'y')
|
126 |
+
z = 66 + cm2index(5, 'z')
|
127 |
+
affordance_map[x, y, z] = 1
|
128 |
+
ret_val = affordance_map
|
129 |
+
|
130 |
+
# Query: the blue circle.
|
131 |
+
affordance_map = get_empty_affordance_map()
|
132 |
+
blue_circle = parse_query_obj('blue circle')
|
133 |
+
affordance_map = blue_circle.occupancy_map
|
134 |
+
ret_val = affordance_map
|
135 |
+
|
136 |
+
# Query: a point 10cm above and 5cm to the left of the yellow bowl.
|
137 |
+
affordance_map = get_empty_affordance_map()
|
138 |
+
yellow_bowl = parse_query_obj('yellow bowl')
|
139 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = yellow_bowl.aabb
|
140 |
+
center_x, center_y, center_z = yellow_bowl.position
|
141 |
+
# 10cm above so we add to z-axis, and 5cm to the left of so we subtract from y-axis
|
142 |
+
x = center_x
|
143 |
+
y = min_y - cm2index(5, 'y')
|
144 |
+
z = max_z + cm2index(10, 'z')
|
145 |
+
affordance_map[x, y, z] = 1
|
146 |
+
ret_val = affordance_map
|
VoxPoserApiExamples/Real/value_maps/real_get_avoidance_map_prompt.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_avoidance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: 10cm from the bowl.
|
6 |
+
avoidance_map = get_empty_avoidance_map()
|
7 |
+
bowl = parse_query_obj('bowl')
|
8 |
+
set_voxel_by_radius(avoidance_map, bowl.position, radius_cm=10, value=1)
|
9 |
+
ret_val = avoidance_map
|
10 |
+
|
11 |
+
# Query: 20cm near the mug.
|
12 |
+
avoidance_map = get_empty_avoidance_map()
|
13 |
+
mug = parse_query_obj('mug')
|
14 |
+
set_voxel_by_radius(avoidance_map, mug.position, radius_cm=20, value=1)
|
15 |
+
ret_val = avoidance_map
|
16 |
+
|
17 |
+
# Query: 20cm around the mug and 10cm around the bowl.
|
18 |
+
avoidance_map = get_empty_avoidance_map()
|
19 |
+
mug = parse_query_obj('mug')
|
20 |
+
set_voxel_by_radius(avoidance_map, mug.position, radius_cm=20, value=1)
|
21 |
+
bowl = parse_query_obj('bowl')
|
22 |
+
set_voxel_by_radius(avoidance_map, bowl.position, radius_cm=10, value=1)
|
23 |
+
ret_val = avoidance_map
|
24 |
+
|
25 |
+
# Query: 10cm from anything fragile.
|
26 |
+
avoidance_map = get_empty_avoidance_map()
|
27 |
+
fragile_objects = parse_query_obj('anything fragile')
|
28 |
+
for obj in fragile_objects:
|
29 |
+
set_voxel_by_radius(avoidance_map, obj.position, radius_cm=10, value=1)
|
30 |
+
ret_val = avoidance_map
|
31 |
+
|
32 |
+
# Query: 10cm from the blue circle.
|
33 |
+
avoidance_map = get_empty_avoidance_map()
|
34 |
+
blue_circle = parse_query_obj('blue circle')
|
35 |
+
set_voxel_by_radius(avoidance_map, blue_circle.position, radius_cm=10, value=1)
|
36 |
+
ret_val = avoidance_map
|
VoxPoserApiExamples/Real/value_maps/real_get_gripper_map_prompt.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_gripper_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: open everywhere except 1cm around the green block.
|
6 |
+
gripper_map = get_empty_gripper_map()
|
7 |
+
# open everywhere
|
8 |
+
gripper_map[:, :, :] = 0
|
9 |
+
# close when 1cm around the green block
|
10 |
+
green_block = parse_query_obj('green block')
|
11 |
+
set_voxel_by_radius(gripper_map, green_block.position, radius_cm=1, value=1)
|
12 |
+
ret_val = gripper_map
|
13 |
+
|
14 |
+
# Query: close everywhere but open when on top of the back left corner of the table.
|
15 |
+
gripper_map = get_empty_gripper_map()
|
16 |
+
# close everywhere
|
17 |
+
gripper_map[:, :, :] = 1
|
18 |
+
# open when on top of the back left corner of the table
|
19 |
+
table = parse_query_obj('table')
|
20 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
21 |
+
center_x, center_y, center_z = table.position
|
22 |
+
# back so x = min_x, left so y = min_y, top so we add to z
|
23 |
+
x = min_x
|
24 |
+
y = min_y
|
25 |
+
z = max_z + cm2index(15, 'z')
|
26 |
+
set_voxel_by_radius(gripper_map, (x, y, z), radius_cm=10, value=0)
|
27 |
+
ret_val = gripper_map
|
28 |
+
|
29 |
+
# Query: always open except when you are on the right side of the table.
|
30 |
+
gripper_map = get_empty_gripper_map()
|
31 |
+
# always open
|
32 |
+
gripper_map[:, :, :] = 0
|
33 |
+
# close when you are on the right side of the table
|
34 |
+
table = parse_query_obj('table')
|
35 |
+
center_x, center_y, center_z = table.position
|
36 |
+
# right side so y is greater than center_y
|
37 |
+
gripper_map[:, center_y:, :] = 1
|
38 |
+
|
39 |
+
# Query: always close except when you are on the back side of the table.
|
40 |
+
gripper_map = get_empty_gripper_map()
|
41 |
+
# always close
|
42 |
+
gripper_map[:, :, :] = 1
|
43 |
+
# open when you are on the back side of the table
|
44 |
+
table = parse_query_obj('table')
|
45 |
+
center_x, center_y, center_z = table.position
|
46 |
+
# back side so x is less than center_x
|
47 |
+
gripper_map[:center_x, :, :] = 0
|
48 |
+
ret_val = gripper_map
|
VoxPoserApiExamples/Real/value_maps/real_get_rotation_map_prompt.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_rotation_map, set_voxel_by_radius, cm2index, vec2quat
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
from transforms3d.euler import euler2quat, quat2euler
|
5 |
+
from transforms3d.quaternions import qmult, qinverse
|
6 |
+
|
7 |
+
# Query: face the support surface of the bowl.
|
8 |
+
rotation_map = get_empty_rotation_map()
|
9 |
+
bowl = parse_query_obj('bowl')
|
10 |
+
target_rotation = vec2quat(-bowl.normal)
|
11 |
+
rotation_map[:, :, :] = target_rotation
|
12 |
+
ret_val = rotation_map
|
13 |
+
|
14 |
+
# Query: face the table when within 30cm from table center.
|
15 |
+
rotation_map = get_empty_rotation_map()
|
16 |
+
table = parse_query_obj('table')
|
17 |
+
table_center = table.position
|
18 |
+
target_rotation = vec2quat(-table.normal)
|
19 |
+
set_voxel_by_radius(rotation_map, table_center, radius_cm=30, value=target_rotation)
|
20 |
+
ret_val = rotation_map
|
21 |
+
|
22 |
+
# Query: face the blue bowl.
|
23 |
+
rotation_map = get_empty_rotation_map()
|
24 |
+
blue_bowl = parse_query_obj('brown block')
|
25 |
+
target_rotation = vec2quat(-blue_bowl.normal)
|
26 |
+
rotation_map[:, :, :] = target_rotation
|
27 |
+
ret_val = rotation_map
|
28 |
+
|
29 |
+
# Query: turn clockwise by 45 degrees when at the center of the beer cap.
|
30 |
+
rotation_map = get_empty_rotation_map()
|
31 |
+
beer_cap = parse_query_obj('beer cap')
|
32 |
+
(x, y, z) = beer_cap.position
|
33 |
+
curr_rotation = rotation_map[x, y, z]
|
34 |
+
rotation_delta = euler2quat(0, 0, np.pi / 4)
|
35 |
+
rotation_map[x, y, z] = qmult(curr_rotation, rotation_delta)
|
36 |
+
ret_val = rotation_map
|
37 |
+
|
38 |
+
# Query: turn counter-clockwise by 30 degrees.
|
39 |
+
rotation_map = get_empty_rotation_map()
|
40 |
+
curr_rotation = rotation_map[0, 0, 0]
|
41 |
+
rotation_delta = euler2quat(0, 0, -np.pi / 6)
|
42 |
+
rotation_map[:, :, :] = qmult(curr_rotation, rotation_delta)
|
43 |
+
ret_val = rotation_map
|
44 |
+
|
45 |
+
# Query: rotate the gripper to be 45 degrees slanted relative to the plate.
|
46 |
+
rotation_map = get_empty_rotation_map()
|
47 |
+
plate = parse_query_obj('plate')
|
48 |
+
face_plate_quat = vec2quat(-plate.normal)
|
49 |
+
# rotate 45 degrees around the x-axis
|
50 |
+
rotation_delta = euler2quat(-np.pi / 4, 0, 0)
|
51 |
+
target_rotation = qmult(face_plate_quat, rotation_delta)
|
52 |
+
rotation_map[:, :, :] = target_rotation
|
53 |
+
ret_val = rotation_map
|
VoxPoserApiExamples/Real/value_maps/real_get_velocity_map_prompt.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_velocity_map, set_voxel_by_radius, cm2index
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
|
5 |
+
# Query: faster when on the right side of the table and slower when on the left side of the table.
|
6 |
+
velocity_map = get_empty_velocity_map()
|
7 |
+
table = parse_query_obj('table')
|
8 |
+
center_x, center_y, center_z = table.position
|
9 |
+
# faster on right side so 1.5 when y > center_y, slower on left side so 0.5 when y < center_y
|
10 |
+
velocity_map[:, center_y:, :] = 1.5
|
11 |
+
velocity_map[:, :center_y, :] = 0.5
|
12 |
+
ret_val = velocity_map
|
13 |
+
|
14 |
+
# Query: slow down by a quarter.
|
15 |
+
velocity_map = get_empty_velocity_map()
|
16 |
+
velocity_map[:] = 0.75
|
17 |
+
ret_val = velocity_map
|
18 |
+
|
19 |
+
# Query: slow down by a half when you're near anything fragile (objects: ['block', 'fork', 'mug', 'bowl', 'chips']).
|
20 |
+
velocity_map = get_empty_velocity_map()
|
21 |
+
mug = parse_query_obj('mug')
|
22 |
+
set_voxel_by_radius(velocity_map, mug.position, radius_cm=10, value=0.5)
|
23 |
+
bowl = parse_query_obj('bowl')
|
24 |
+
set_voxel_by_radius(velocity_map, bowl.position, radius_cm=10, value=0.5)
|
25 |
+
ret_val = velocity_map
|
26 |
+
|
27 |
+
# Query: quarter of the speed when within 9cm from the yellow line.
|
28 |
+
velocity_map = get_empty_velocity_map()
|
29 |
+
yellow_line = parse_query_obj('yellow_line')
|
30 |
+
set_voxel_by_radius(velocity_map, yellow_line.position, radius_cm=9, value=0.25)
|
31 |
+
ret_val = velocity_map
|
VoxPoserApiExamples/Sim/composer/sim_composer_prompt.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute, reset_to_default_pose
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
from plan_utils import get_affordance_map, get_avoidance_map, get_velocity_map, get_rotation_map, get_gripper_map
|
5 |
+
|
6 |
+
# Query: move ee forward for 7cm.
|
7 |
+
movable = parse_query_obj('ee')
|
8 |
+
affordance_map = get_affordance_map(f'a point 7cm in front of {movable.position}')
|
9 |
+
execute(movable, affordance_map)
|
10 |
+
|
11 |
+
# Query: move to the left of the green block.
|
12 |
+
movable = parse_query_obj('ee')
|
13 |
+
affordance_map = get_affordance_map('a point 11cm to the left of the green block')
|
14 |
+
execute(movable, affordance_map=affordance_map)
|
15 |
+
|
16 |
+
# Query: move to the yellow block while staying on the front side the pink block.
|
17 |
+
movable = parse_query_obj('ee')
|
18 |
+
affordance_map = get_affordance_map('a point 11cm on top of the yellow block')
|
19 |
+
avoidance_map = get_avoidance_map('anywhere behind the pink block')
|
20 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
21 |
+
|
22 |
+
# Query: move to the back side of the table.
|
23 |
+
movable = parse_query_obj('ee')
|
24 |
+
affordance_map = get_affordance_map('a point on the back side of the table')
|
25 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map)
|
26 |
+
|
27 |
+
# Query: move to the front right corner of the table while moving at faster speed when within 7cm from the yellow block.
|
28 |
+
movable = parse_query_obj('ee')
|
29 |
+
affordance_map = get_affordance_map('a point on the front right corner of the table')
|
30 |
+
velocity_map = get_velocity_map('faster speed when within 7cm from the yellow block')
|
31 |
+
execute(movable, affordance_map=affordance_map, velocity_map=velocity_map)
|
32 |
+
|
33 |
+
# Query: move to 15cm on top of the rightmost block while avoiding the blue line and moving at a quarter of the speed on the right side of the table.
|
34 |
+
movable = parse_query_obj('ee')
|
35 |
+
affordance_map = get_affordance_map('a point 15cm on top of the rightmost block')
|
36 |
+
avoidance_map = get_avoidance_map('the blue line')
|
37 |
+
velocity_map = get_velocity_map('a quarter of the speed on the right side of the table')
|
38 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, velocity_map=velocity_map)
|
39 |
+
|
40 |
+
# Query: close the topmost drawer by pushing.
|
41 |
+
movable = parse_query_obj('topmost drawer handle')
|
42 |
+
affordance_map = get_affordance_map('a point 21cm into the topmost drawer handle')
|
43 |
+
execute(movable, affordance_map=affordance_map)
|
44 |
+
|
45 |
+
# Query: push the second to the left block along the brown line.
|
46 |
+
movable = parse_query_obj('second to the left block')
|
47 |
+
affordance_map = get_affordance_map('the brown line')
|
48 |
+
execute(movable, affordance_map=affordance_map)
|
49 |
+
|
50 |
+
# Query: grasp the blue block from the table at a quarter of the speed.
|
51 |
+
movable = parse_query_obj('ee')
|
52 |
+
affordance_map = get_affordance_map('a point at the center of blue block')
|
53 |
+
rotation_map = get_rotation_map('face the blue block')
|
54 |
+
velocity_map = get_velocity_map('quarter of the speed')
|
55 |
+
gripper_map = get_gripper_map('open everywhere except 1cm around the blue block')
|
56 |
+
execute(movable, affordance_map=affordance_map, rotation_map=rotation_map, velocity_map=velocity_map, gripper_map=gripper_map)
|
57 |
+
|
58 |
+
# Query: move to the left of the brown block.
|
59 |
+
movable = parse_query_obj('ee')
|
60 |
+
affordance_map = get_affordance_map('a point 11cm to the left of the brown block')
|
61 |
+
execute(movable, affordance_map=affordance_map)
|
62 |
+
|
63 |
+
# Query: back to default pose.
|
64 |
+
reset_to_default_pose()
|
65 |
+
|
66 |
+
# Query: open gripper.
|
67 |
+
movable = parse_query_obj('gripper')
|
68 |
+
gripper_map = get_gripper_map('open everywhere')
|
69 |
+
execute(movable, gripper_map=gripper_map)
|
70 |
+
|
71 |
+
# Query: drop the blue block to the right side of the table while staying at least 7cm away from the brown block.
|
72 |
+
movable = parse_query_obj('ee')
|
73 |
+
affordance_map = get_affordance_map('a point on the right side of the table')
|
74 |
+
avoidance_map = get_avoidance_map('7cm away from the brown block')
|
75 |
+
gripper_map = get_gripper_map('close everywhere except 1cm around the right side of the table')
|
76 |
+
execute(movable, affordance_map=affordance_map, avoidance_map=avoidance_map, gripper_map=gripper_map)
|
77 |
+
|
78 |
+
# Query: move to the front side of the yellow block.
|
79 |
+
movable = parse_query_obj('ee')
|
80 |
+
affordance_map = get_affordance_map('a point 11cm in front of the yellow block')
|
81 |
+
execute(movable, affordance_map=affordance_map)
|
82 |
+
|
83 |
+
# Query: move to the back side of the table.
|
84 |
+
movable = parse_query_obj('ee')
|
85 |
+
affordance_map = get_affordance_map('a point on the back side of the table')
|
86 |
+
execute(movable, affordance_map=affordance_map)
|
87 |
+
|
88 |
+
# Query: stay away from the brown block.
|
89 |
+
movable = parse_query_obj('ee')
|
90 |
+
avoidance_map = get_avoidance_map('3cm away from the brown block')
|
91 |
+
execute(movable, avoidance_map=avoidance_map)
|
VoxPoserApiExamples/Sim/perception/sim_parse_query_obj_prompt.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import detect
|
3 |
+
|
4 |
+
objects = ['green block', 'yellow line']
|
5 |
+
# Query: ee.
|
6 |
+
ee = detect('ee')[0]
|
7 |
+
ret_val = ee
|
8 |
+
|
9 |
+
objects = ['drawer', 'blue block', 'yellow block']
|
10 |
+
# Query: topmost handle.
|
11 |
+
handles = detect('drawer handle')
|
12 |
+
# topmost so sort by z, take the last one
|
13 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
14 |
+
top_handle = handles[-1]
|
15 |
+
ret_val = top_handle
|
16 |
+
|
17 |
+
objects = ['yellow block', 'pink block', 'brown line', 'pink block']
|
18 |
+
# Query: second to the left block.
|
19 |
+
blocks = detect('block')
|
20 |
+
# second to the left so sort by y, take the second one
|
21 |
+
blocks = sorted(blocks, key=lambda x: x.position[1])
|
22 |
+
second_left_block = blocks[1]
|
23 |
+
ret_val = second_left_block
|
24 |
+
|
25 |
+
objects = ['blue line', 'pink line', 'green block']
|
26 |
+
# Query: table.
|
27 |
+
table = detect('table')[0]
|
28 |
+
ret_val = table
|
29 |
+
|
30 |
+
objects = ['green line', 'drawer', 'yellow block']
|
31 |
+
# Query: second to the bottom handle.
|
32 |
+
handles = detect('drawer handle')
|
33 |
+
# second to the bottom so sort by z, take the second one
|
34 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
35 |
+
second_bottom_handle = handles[1]
|
36 |
+
ret_val = second_bottom_handle
|
37 |
+
|
38 |
+
objects = ['brown line', 'brown block']
|
39 |
+
# Query: brown line.
|
40 |
+
brown_line = detect('brown line')[0]
|
41 |
+
ret_val = brown_line
|
42 |
+
|
43 |
+
objects = ['green block', 'brown block', 'yellow line']
|
44 |
+
# Query: block.
|
45 |
+
block = detect('green block')[0]
|
46 |
+
ret_val = block
|
47 |
+
|
48 |
+
objects = ['pink block', 'pink line', 'blue block']
|
49 |
+
# Query: block closest to the pink line.
|
50 |
+
blocks = detect('block')
|
51 |
+
pink_line = detect('pink line')[0]
|
52 |
+
closest_block = min(blocks, key=lambda x: np.linalg.norm(x.position - pink_line.position))
|
53 |
+
ret_val = closest_block
|
54 |
+
|
55 |
+
objects = ['blue block', 'blue line', 'green block', 'pink block', 'brown block']
|
56 |
+
# Query: the block that is on top of the blue block.
|
57 |
+
blocks = detect('block')
|
58 |
+
blue_block = detect('blue block')[0]
|
59 |
+
# find the block that is on top of the blue block
|
60 |
+
for block in blocks:
|
61 |
+
if block.position[2] > blue_block.position[2]:
|
62 |
+
ret_val = block
|
63 |
+
break
|
64 |
+
|
65 |
+
objects = ['drawer']
|
66 |
+
# Query: top drawer handle.
|
67 |
+
handles = detect('drawer handle')
|
68 |
+
# top drawer handle so sort by z, take the last one
|
69 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
70 |
+
top_handle = handles[-1]
|
71 |
+
ret_val = top_handle
|
VoxPoserApiExamples/Sim/value_maps/sim_get_affordance_map_prompt.py
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_affordance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: a point 10cm in front of [10, 15, 60].
|
6 |
+
affordance_map = get_empty_affordance_map()
|
7 |
+
# in front so we add to x
|
8 |
+
x = 10 + cm2index(10, 'x')
|
9 |
+
y = 15
|
10 |
+
z = 60
|
11 |
+
affordance_map[x, y, z] = 1
|
12 |
+
ret_val = affordance_map
|
13 |
+
|
14 |
+
# Query: a point on the back side of the table.
|
15 |
+
affordance_map = get_empty_affordance_map()
|
16 |
+
table = parse_query_obj('table')
|
17 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
18 |
+
center_x, center_y, center_z = table.position
|
19 |
+
# back side so x = min_x
|
20 |
+
x = min_x
|
21 |
+
y = center_y
|
22 |
+
z = center_z
|
23 |
+
affordance_map[x, y, z] = 1
|
24 |
+
ret_val = affordance_map
|
25 |
+
|
26 |
+
# Query: a point 21cm on top of the green block.
|
27 |
+
affordance_map = get_empty_affordance_map()
|
28 |
+
green_block = parse_query_obj('green block')
|
29 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = green_block.aabb
|
30 |
+
center_x, center_y, center_z = green_block.position
|
31 |
+
# 21cm on top so z = max_z + 21cm
|
32 |
+
x = center_x
|
33 |
+
y = center_y
|
34 |
+
z = max_z + cm2index(21, 'z')
|
35 |
+
affordance_map[x, y, z] = 1
|
36 |
+
ret_val = affordance_map
|
37 |
+
|
38 |
+
# Query: a point 1cm to the left of the brown block.
|
39 |
+
affordance_map = get_empty_affordance_map()
|
40 |
+
brown_block = parse_query_obj('brown block')
|
41 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = brown_block.aabb
|
42 |
+
center_x, center_y, center_z = brown_block.position
|
43 |
+
# 1cm to the left so y = min_y - 1cm
|
44 |
+
x = center_x
|
45 |
+
y = min_y - cm2index(1, 'y')
|
46 |
+
z = center_z
|
47 |
+
affordance_map[x, y, z] = 1
|
48 |
+
ret_val = affordance_map
|
49 |
+
|
50 |
+
# Query: anywhere within 15cm of the right most block.
|
51 |
+
affordance_map = get_empty_affordance_map()
|
52 |
+
right_most_block = parse_query_obj('the right most block')
|
53 |
+
set_voxel_by_radius(affordance_map, right_most_block.position, radius_cm=15, value=1)
|
54 |
+
ret_val = affordance_map
|
55 |
+
|
56 |
+
# Query: a point on the back side of the table.
|
57 |
+
affordance_map = get_empty_affordance_map()
|
58 |
+
table = parse_query_obj('table')
|
59 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
60 |
+
center_x, center_y, center_z = table.position
|
61 |
+
# back side so x = min_x
|
62 |
+
x = min_x
|
63 |
+
y = center_y
|
64 |
+
z = center_z
|
65 |
+
affordance_map[x, y, z] = 1
|
66 |
+
ret_val = affordance_map
|
67 |
+
|
68 |
+
# Query: a point on the front right corner of the table.
|
69 |
+
affordance_map = get_empty_affordance_map()
|
70 |
+
table = parse_query_obj('table')
|
71 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
72 |
+
center_x, center_y, center_z = table.position
|
73 |
+
# front right corner -> front so x = max_x, right so y = max_y
|
74 |
+
x = max_x
|
75 |
+
y = max_y
|
76 |
+
z = center_z
|
77 |
+
affordance_map[x, y, z] = 1
|
78 |
+
ret_val = affordance_map
|
79 |
+
|
80 |
+
# Query: a point 30cm into the topmost drawer handle.
|
81 |
+
affordance_map = get_empty_affordance_map()
|
82 |
+
top_handle = parse_query_obj('topmost drawer handle')
|
83 |
+
# negative normal because we are moving into the handle.
|
84 |
+
moving_dir = -top_handle.normal
|
85 |
+
affordance_xyz = top_handle.position + cm2index(30, moving_dir)
|
86 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
87 |
+
ret_val = affordance_map
|
88 |
+
|
89 |
+
# Query: a point 9cm to the left of the blue block.
|
90 |
+
affordance_map = get_empty_affordance_map()
|
91 |
+
blue_block = parse_query_obj('blue block')
|
92 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = blue_block.aabb
|
93 |
+
center_x, center_y, center_z = blue_block.position
|
94 |
+
# 9cm to the left so y = min_y - 9cm
|
95 |
+
x = center_x
|
96 |
+
y = min_y - cm2index(9, 'y')
|
97 |
+
z = center_z
|
98 |
+
affordance_map[x, y, z] = 1
|
99 |
+
ret_val = affordance_map
|
100 |
+
|
101 |
+
# Query: a point 21cm away from the leftmost block.
|
102 |
+
affordance_map = get_empty_affordance_map()
|
103 |
+
leftmost_block = parse_query_obj('leftmost block')
|
104 |
+
# positive normal because we are moving away from the block.
|
105 |
+
moving_dir = leftmost_block.normal
|
106 |
+
affordance_xyz = leftmost_block.position + cm2index(21, moving_dir)
|
107 |
+
affordance_map[affordance_xyz[0], affordance_xyz[1], affordance_xyz[2]] = 1
|
108 |
+
ret_val = affordance_map
|
109 |
+
|
110 |
+
# Query: a point 7cm above the tray that contains the lemon.
|
111 |
+
affordance_map = get_empty_affordance_map()
|
112 |
+
tray_with_lemon = parse_query_obj('tray that contains the lemon')
|
113 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = tray_with_lemon.aabb
|
114 |
+
center_x, center_y, center_z = tray_with_lemon.position
|
115 |
+
# 7cm above so z = max_z + 7cm
|
116 |
+
x = center_x
|
117 |
+
y = center_y
|
118 |
+
z = max_z + cm2index(7, 'z')
|
119 |
+
affordance_map[x, y, z] = 1
|
120 |
+
ret_val = affordance_map
|
121 |
+
|
122 |
+
# Query: a point 3cm to the left of [45, 49, 99].
|
123 |
+
affordance_map = get_empty_affordance_map()
|
124 |
+
# left so y = 49 - 3cm
|
125 |
+
x = 45
|
126 |
+
y = 49 - cm2index(3, 'y')
|
127 |
+
z = 99
|
128 |
+
affordance_map[x, y, z] = 1
|
129 |
+
ret_val = affordance_map
|
130 |
+
|
131 |
+
# Query: the brown line.
|
132 |
+
brown_line = parse_query_obj('brown line')
|
133 |
+
affordance_map = brown_line.occupancy_map
|
134 |
+
ret_val = affordance_map
|
135 |
+
|
136 |
+
# Query: a point 13cm to the left of the gripper.
|
137 |
+
affordance_map = get_empty_affordance_map()
|
138 |
+
gripper = parse_query_obj('gripper')
|
139 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = gripper.aabb
|
140 |
+
center_x, center_y, center_z = gripper.position
|
141 |
+
# 13cm to the left so y = min_y - 13cm
|
142 |
+
x = center_x
|
143 |
+
y = min_y - cm2index(13, 'y')
|
144 |
+
z = center_z
|
145 |
+
affordance_map[x, y, z] = 1
|
146 |
+
ret_val = affordance_map
|
147 |
+
|
148 |
+
# Query: a point 17cm above the back left corner of the table.
|
149 |
+
affordance_map = get_empty_affordance_map()
|
150 |
+
table = parse_query_obj('table')
|
151 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
152 |
+
center_x, center_y, center_z = table.position
|
153 |
+
# 17cm on top of back left corner so x = min_x, y = min_y, z = max_z + 17cm
|
154 |
+
x = min_x
|
155 |
+
y = min_y
|
156 |
+
z = max_z + cm2index(17, 'z')
|
157 |
+
affordance_map[x, y, z] = 1
|
158 |
+
ret_val = affordance_map
|
159 |
+
|
160 |
+
# Query: a point at the center of the green block.
|
161 |
+
affordance_map = get_empty_affordance_map()
|
162 |
+
green_block = parse_query_obj('green block')
|
163 |
+
center_x, center_y, center_z = green_block.position
|
164 |
+
affordance_map[center_x, center_y, center_z] = 1
|
165 |
+
ret_val = affordance_map
|
166 |
+
|
167 |
+
# Query: the right side of the table.
|
168 |
+
affordance_map = get_empty_affordance_map()
|
169 |
+
table = parse_query_obj('table')
|
170 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
171 |
+
center_x, center_y, center_z = table.position
|
172 |
+
# right side so y = max_y
|
173 |
+
x = center_x
|
174 |
+
y = max_y
|
175 |
+
z = center_z
|
176 |
+
affordance_map[x, y, z] = 1
|
177 |
+
ret_val = affordance_map
|
VoxPoserApiExamples/Sim/value_maps/sim_get_avoidance_map_prompt.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_avoidance_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: 11cm from the blue block.
|
6 |
+
avoidance_map = get_empty_avoidance_map()
|
7 |
+
blue_block = parse_query_obj('blue block')
|
8 |
+
set_voxel_by_radius(avoidance_map, blue_block.position, radius_cm=11, value=1)
|
9 |
+
ret_val = avoidance_map
|
10 |
+
|
11 |
+
# Query: 7cm near the pink block.
|
12 |
+
avoidance_map = get_empty_avoidance_map()
|
13 |
+
pink_block = parse_query_obj('pink block')
|
14 |
+
set_voxel_by_radius(avoidance_map, pink_block.position, radius_cm=7, value=1)
|
15 |
+
ret_val = avoidance_map
|
16 |
+
|
17 |
+
# Query: 13cm around the brown block and 5cm around the green block.
|
18 |
+
avoidance_map = get_empty_avoidance_map()
|
19 |
+
brown_block = parse_query_obj('brown block')
|
20 |
+
set_voxel_by_radius(avoidance_map, brown_block.position, radius_cm=13, value=1)
|
21 |
+
green_block = parse_query_obj('green block')
|
22 |
+
set_voxel_by_radius(avoidance_map, green_block.position, radius_cm=5, value=1)
|
23 |
+
ret_val = avoidance_map
|
24 |
+
|
25 |
+
# Query: the blue line.
|
26 |
+
blue_line = parse_query_obj('blue_line')
|
27 |
+
avoidance_map = blue_line.occupancy_map
|
28 |
+
ret_val = avoidance_map
|
29 |
+
|
30 |
+
# Query: anywhere on the front side of the blue block.
|
31 |
+
avoidance_map = get_empty_avoidance_map()
|
32 |
+
blue_block = parse_query_obj('blue block')
|
33 |
+
center_x, center_y, center_z = blue_block.position
|
34 |
+
# front side so x > center_x
|
35 |
+
avoidance_map[center_x:, :, :] = 1
|
36 |
+
ret_val = avoidance_map
|
37 |
+
|
38 |
+
# Query: anywhere on the left of the green block.
|
39 |
+
avoidance_map = get_empty_avoidance_map()
|
40 |
+
green_block = parse_query_obj('green block')
|
41 |
+
center_x, center_y, center_z = green_block.position
|
42 |
+
# left side so y < center_y
|
43 |
+
avoidance_map[:, :center_y, :] = 1
|
44 |
+
ret_val = avoidance_map
|
45 |
+
|
46 |
+
# Query: anywhere behind the pink block.
|
47 |
+
avoidance_map = get_empty_avoidance_map()
|
48 |
+
pink_block = parse_query_obj('pink block')
|
49 |
+
center_x, center_y, center_z = pink_block.position
|
50 |
+
# behind so x < center_x
|
51 |
+
avoidance_map[:center_x, :, :] = 1
|
52 |
+
ret_val = avoidance_map
|
53 |
+
|
54 |
+
# Query: anywhere above the brown block.
|
55 |
+
avoidance_map = get_empty_avoidance_map()
|
56 |
+
brown_block = parse_query_obj('brown block')
|
57 |
+
center_x, center_y, center_z = brown_block.position
|
58 |
+
# above so z > center_z
|
59 |
+
avoidance_map[:, :, center_z:] = 1
|
60 |
+
ret_val = avoidance_map
|
VoxPoserApiExamples/Sim/value_maps/sim_get_gripper_map_prompt.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import parse_query_obj
|
3 |
+
from plan_utils import get_empty_gripper_map, set_voxel_by_radius, cm2index
|
4 |
+
|
5 |
+
# Query: open everywhere except 1cm around the green block.
|
6 |
+
gripper_map = get_empty_gripper_map()
|
7 |
+
# open everywhere
|
8 |
+
gripper_map[:, :, :] = 0
|
9 |
+
# close when 1cm around the green block
|
10 |
+
green_block = parse_query_obj('green block')
|
11 |
+
set_voxel_by_radius(gripper_map, green_block.position, radius_cm=1, value=1)
|
12 |
+
ret_val = gripper_map
|
13 |
+
|
14 |
+
# Query: close everywhere but open when on top of the back left corner of the table.
|
15 |
+
gripper_map = get_empty_gripper_map()
|
16 |
+
# close everywhere
|
17 |
+
gripper_map[:, :, :] = 1
|
18 |
+
# open when on top of the back left corner of the table
|
19 |
+
table = parse_query_obj('table')
|
20 |
+
(min_x, min_y, min_z), (max_x, max_y, max_z) = table.aabb
|
21 |
+
center_x, center_y, center_z = table.position
|
22 |
+
# back so x = min_x, left so y = min_y, top so we add to z
|
23 |
+
x = min_x
|
24 |
+
y = min_y
|
25 |
+
z = max_z + cm2index(10, 'z')
|
26 |
+
set_voxel_by_radius(gripper_map, (x, y, z), radius_cm=10, value=0)
|
27 |
+
ret_val = gripper_map
|
28 |
+
|
29 |
+
# Query: always open except when you are on the right side of the table.
|
30 |
+
gripper_map = get_empty_gripper_map()
|
31 |
+
# always open
|
32 |
+
gripper_map[:, :, :] = 0
|
33 |
+
# close when you are on the right side of the table
|
34 |
+
table = parse_query_obj('table')
|
35 |
+
center_x, center_y, center_z = table.position
|
36 |
+
# right side so y is greater than center_y
|
37 |
+
gripper_map[:, center_y:, :] = 1
|
38 |
+
|
39 |
+
# Query: always close except when you are on the back side of the table.
|
40 |
+
gripper_map = get_empty_gripper_map()
|
41 |
+
# always close
|
42 |
+
gripper_map[:, :, :] = 1
|
43 |
+
# open when you are on the back side of the table
|
44 |
+
table = parse_query_obj('table')
|
45 |
+
center_x, center_y, center_z = table.position
|
46 |
+
# back side so x is less than center_x
|
47 |
+
gripper_map[:center_x, :, :] = 0
|
48 |
+
ret_val = gripper_map
|
49 |
+
|
50 |
+
# Query: open everywhere except 1cm around the topmost drawer handle.
|
51 |
+
gripper_map = get_empty_gripper_map()
|
52 |
+
# open everywhere
|
53 |
+
gripper_map[:, :, :] = 0
|
54 |
+
# close when 1cm around the topmost drawer handle
|
55 |
+
topmost_drawer_handle = parse_query_obj('topmost drawer handle')
|
56 |
+
set_voxel_by_radius(gripper_map, topmost_drawer_handle.position, radius_cm=1, value=1)
|
57 |
+
ret_val = gripper_map
|
VoxPoserApiExamples/Sim/value_maps/sim_get_rotation_map_prompt.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_rotation_map, set_voxel_by_radius, cm2index, vec2quat
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
|
5 |
+
# Query: face the green block.
|
6 |
+
rotation_map = get_empty_rotation_map()
|
7 |
+
green_block = parse_query_obj('green block')
|
8 |
+
target_rotation = vec2quat(-green_block.normal)
|
9 |
+
rotation_map[:, :, :] = target_rotation
|
10 |
+
ret_val = rotation_map
|
11 |
+
|
12 |
+
# Query: face the table when within 30cm from table center.
|
13 |
+
rotation_map = get_empty_rotation_map()
|
14 |
+
table = parse_query_obj('table')
|
15 |
+
table_center = table.position
|
16 |
+
target_rotation = vec2quat(-table.normal)
|
17 |
+
set_voxel_by_radius(rotation_map, table_center, radius_cm=30, value=target_rotation)
|
18 |
+
ret_val = rotation_map
|
19 |
+
|
20 |
+
# Query: face the topmost drawer handle.
|
21 |
+
rotation_map = get_empty_rotation_map()
|
22 |
+
topmost_drawer_handle = parse_query_obj('topmost drawer handle')
|
23 |
+
target_rotation = vec2quat(-topmost_drawer_handle.normal)
|
24 |
+
rotation_map[:, :, :] = target_rotation
|
25 |
+
ret_val = rotation_map
|
VoxPoserApiExamples/Sim/value_maps/sim_get_velocity_map_prompt.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from plan_utils import get_empty_velocity_map, set_voxel_by_radius, cm2index
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
|
5 |
+
# Query: faster when on the left side of the table and a quarter of the speed when on the other side of the table.
|
6 |
+
velocity_map = get_empty_velocity_map()
|
7 |
+
table = parse_query_obj('table')
|
8 |
+
center_x, center_y, center_z = table.position
|
9 |
+
# faster on left side so y < center_y
|
10 |
+
velocity_map[:, :center_y, :] = 1.5
|
11 |
+
# a quarter of the speed on the other side so y > center_y
|
12 |
+
velocity_map[:, center_y:, :] = 0.25
|
13 |
+
ret_val = velocity_map
|
14 |
+
|
15 |
+
# Query: slow down by a quarter.
|
16 |
+
velocity_map = get_empty_velocity_map()
|
17 |
+
velocity_map[:] = 0.75
|
18 |
+
ret_val = velocity_map
|
19 |
+
|
20 |
+
# Query: quarter of the speed when within 9cm from the yellow block.
|
21 |
+
velocity_map = get_empty_velocity_map()
|
22 |
+
yellow_block = parse_query_obj('yellow block')
|
23 |
+
set_voxel_by_radius(velocity_map, yellow_block.position, radius_cm=9, value=0.25)
|
24 |
+
ret_val = velocity_map
|
25 |
+
|
26 |
+
# Query: quarter of the speed in the back side of the table.
|
27 |
+
velocity_map = get_empty_velocity_map()
|
28 |
+
table = parse_query_obj('table')
|
29 |
+
center_x, center_y, center_z = table.position
|
30 |
+
# a quarter of the speed in the back side so x < center_x
|
31 |
+
velocity_map[:center_x, :, :] = 0.25
|
32 |
+
ret_val = velocity_map
|
33 |
+
|
34 |
+
# Query: faster speed in the right side of the table.
|
35 |
+
velocity_map = get_empty_velocity_map()
|
36 |
+
table = parse_query_obj('table')
|
37 |
+
center_x, center_y, center_z = table.position
|
38 |
+
# faster in the right side so y > center_y
|
39 |
+
velocity_map[:, center_y:, :] = 1.5
|
40 |
+
ret_val = velocity_map
|
41 |
+
|
42 |
+
# Query: quarter of the speed when within 11cm from the brown block.
|
43 |
+
velocity_map = get_empty_velocity_map()
|
44 |
+
brown_block = parse_query_obj('brown_block')
|
45 |
+
set_voxel_by_radius(velocity_map, brown_block.position, radius_cm=11, value=0.25)
|
46 |
+
ret_val = velocity_map
|
agibot_prompts/agibot_composer.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute, reset_to_default_pose
|
3 |
+
from perception_utils import search_object
|
4 |
+
from plan_utils import get_target_pose, get_operation
|
5 |
+
|
6 |
+
# Query: move ee forward for 10cm.
|
7 |
+
while True:
|
8 |
+
movable = search_object('gripper')
|
9 |
+
target_pose = get_target_pose(f'a point 10cm in front of {movable.position}')
|
10 |
+
success = execute(movable, target_pose)
|
11 |
+
if success: break
|
12 |
+
|
13 |
+
# Query: go back to default.
|
14 |
+
reset_to_default_pose()
|
15 |
+
|
16 |
+
# Query: move the gripper behind the bowl.
|
17 |
+
while True:
|
18 |
+
movable = search_object('gripper')
|
19 |
+
target_pose = get_target_pose('a point 15cm behind the bowl')
|
20 |
+
success = execute(movable, target_pose=target_pose)
|
21 |
+
if success: break
|
22 |
+
|
23 |
+
# Query: move to the back side of the table.
|
24 |
+
while True:
|
25 |
+
movable = search_object('gripper')
|
26 |
+
target_pose = get_target_pose('a point on the back side of the table')
|
27 |
+
success = execute(movable, target_pose=target_pose)
|
28 |
+
if success: break
|
29 |
+
|
30 |
+
# Query: move to the top of the plate.
|
31 |
+
while True:
|
32 |
+
movable = search_object('gripper')
|
33 |
+
target_pose = get_target_pose('a point 10cm above the plate')
|
34 |
+
success = execute(movable, target_pose=target_pose)
|
35 |
+
if success: break
|
36 |
+
|
37 |
+
# Query: drop the toy inside container.
|
38 |
+
while True:
|
39 |
+
movable = search_object('gripper')
|
40 |
+
target_pose = get_target_pose('a point 15cm above the container')
|
41 |
+
operation = get_operation('close everywhere but open when on top of the container')
|
42 |
+
success = execute(movable, target_pose=target_pose, operation=operation)
|
43 |
+
if success: break
|
44 |
+
|
45 |
+
# Query: push close the topmost drawer.
|
46 |
+
while True:
|
47 |
+
movable = search_object('topmost drawer handle')
|
48 |
+
target_pose = get_target_pose('a point 30cm into the topmost drawer handle')
|
49 |
+
success = execute(movable, target_pose=target_pose)
|
50 |
+
if success: break
|
51 |
+
|
52 |
+
# Query: push the second to the left block along the red line.
|
53 |
+
while True:
|
54 |
+
movable = search_object('second to the left block')
|
55 |
+
target_pose = get_target_pose('the red line')
|
56 |
+
success = execute(movable, target_pose=target_pose)
|
57 |
+
if success: break
|
58 |
+
|
59 |
+
# Query: grasp the blue block from the table.
|
60 |
+
while True:
|
61 |
+
movable = search_object('gripper')
|
62 |
+
target_pose = get_target_pose('a point at the center of blue block')
|
63 |
+
operation = get_operation('open everywhere except 1cm around the blue block')
|
64 |
+
success = execute(movable, target_pose=target_pose, operation=operation)
|
65 |
+
if success: break
|
66 |
+
|
67 |
+
# Query: move to the left of the brown block.
|
68 |
+
while True:
|
69 |
+
movable = search_object('gripper')
|
70 |
+
target_pose = get_target_pose('a point 10cm to the left of the brown block')
|
71 |
+
success = execute(movable, target_pose=target_pose)
|
72 |
+
if success: break
|
73 |
+
|
74 |
+
# Query: move to the top of the tray that contains the lemon.
|
75 |
+
while True:
|
76 |
+
movable = search_object('gripper')
|
77 |
+
target_pose = get_target_pose('a point 10cm above the tray that contains the lemon')
|
78 |
+
success = execute(movable, target_pose=target_pose)
|
79 |
+
if success: break
|
80 |
+
|
81 |
+
# Query: close drawer by 5cm.
|
82 |
+
while True:
|
83 |
+
movable = search_object('drawer handle')
|
84 |
+
target_pose = get_target_pose('a point 5cm into the drawer handle')
|
85 |
+
success = execute(movable, target_pose=target_pose)
|
86 |
+
if success: break
|
87 |
+
|
88 |
+
# Query: move to 5cm on top of the soda can, when within 20cm of the wooden mug.
|
89 |
+
while True:
|
90 |
+
movable = search_object('gripper')
|
91 |
+
target_pose = get_target_pose('a point 5cm above the soda can')
|
92 |
+
success = execute(movable, target_pose=target_pose)
|
93 |
+
if success: break
|
94 |
+
|
95 |
+
# Query: wipe the red dot.
|
96 |
+
while True:
|
97 |
+
movable = search_object('gripper')
|
98 |
+
target_pose = get_target_pose('the red dot')
|
99 |
+
success = execute(movable, target_pose=target_pose)
|
100 |
+
if success: break
|
101 |
+
|
102 |
+
# Query: grasp the mug from the shelf.
|
103 |
+
while True:
|
104 |
+
movable = search_object('gripper')
|
105 |
+
target_pose = get_target_pose('a point at the center of the mug handle')
|
106 |
+
operation = get_operation('open everywhere except 1cm around the mug handle')
|
107 |
+
success = execute(movable, target_pose=target_pose, operation=operation)
|
108 |
+
if success: break
|
109 |
+
|
110 |
+
# Query: move to 10cm on top of the soup bowl, and 5cm to the left of the soup bowl.
|
111 |
+
while True:
|
112 |
+
movable = search_object('gripper')
|
113 |
+
target_pose = get_target_pose('a point 10cm above and 5cm to the left of the soup bowl')
|
114 |
+
success = execute(movable, target_pose=target_pose)
|
115 |
+
if success: break
|
116 |
+
|
117 |
+
# Query: open gripper.
|
118 |
+
while True:
|
119 |
+
movable = search_object('gripper')
|
120 |
+
operation = get_operation('open everywhere')
|
121 |
+
success = execute(movable, operation=operation)
|
122 |
+
if success: break
|
123 |
+
|
124 |
+
# Query: sweep all particles to the left side of the table.
|
125 |
+
particles = search_object('particles')
|
126 |
+
for particle in particles:
|
127 |
+
while True:
|
128 |
+
movable = particle
|
129 |
+
target_pose = get_target_pose('a point on the left side of the table')
|
130 |
+
success = execute(particle, target_pose=target_pose)
|
131 |
+
if success: break
|
132 |
+
|
133 |
+
# Query: grasp the bottom drawer handle.
|
134 |
+
while True:
|
135 |
+
movable = search_object('gripper')
|
136 |
+
target_pose = get_target_pose('a point at the center of the bottom drawer handle')
|
137 |
+
operation = get_operation('open everywhere except 1cm around the bottom drawer handle')
|
138 |
+
success = execute(movable, target_pose=target_pose, operation=operation)
|
139 |
+
if success: break
|
agibot_prompts/agibot_perceptor.py
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from perception_utils import track
|
3 |
+
|
4 |
+
objects = ['table', 'gripper', 'green block', 'cardboard box']
|
5 |
+
# Query: gripper.
|
6 |
+
gripper = track('gripper')[0]
|
7 |
+
ret_val = gripper
|
8 |
+
|
9 |
+
objects = ['table', 'gripper', 'drawer', 'egg', 'egg', 'plate']
|
10 |
+
# Query: topmost handle.
|
11 |
+
handles = track('drawer handle')
|
12 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
13 |
+
top_handle = handles[-1]
|
14 |
+
ret_val = top_handle
|
15 |
+
|
16 |
+
objects = ['table', 'gripper', 'yellow block', 'charging cable', 'cyan block', 'magenta block']
|
17 |
+
# Query: second to the left block.
|
18 |
+
blocks = track('block')
|
19 |
+
blocks = sorted(blocks, key=lambda x: x.position[1])
|
20 |
+
second_left_block = blocks[1]
|
21 |
+
ret_val = second_left_block
|
22 |
+
|
23 |
+
objects = ['table', 'gripper', 'iPhone', 'ruler', 'pink line', 'blue line']
|
24 |
+
# Query: the front most line on the table.
|
25 |
+
lines = track('line')
|
26 |
+
lines = sorted(lines, key=lambda x: x.position[0])
|
27 |
+
front_most_line = lines[-1]
|
28 |
+
ret_val = front_most_line
|
29 |
+
|
30 |
+
objects = ['table', 'gripper', 'vase', 'napkin box', 'mask']
|
31 |
+
# Query: table.
|
32 |
+
table = track('table')[0]
|
33 |
+
ret_val = table
|
34 |
+
|
35 |
+
objects = ['table', 'gripper', 'bottle', 'drawer', 'bowl', 'bag']
|
36 |
+
# Query: second to the bottom handle.
|
37 |
+
handles = track('drawer handle')
|
38 |
+
handles = sorted(handles, key=lambda x: x.position[2])
|
39 |
+
second_bottom_handle = handles[1]
|
40 |
+
ret_val = second_bottom_handle
|
41 |
+
|
42 |
+
objects = ['table', 'gripper', 'brown line', 'red block', 'monitor']
|
43 |
+
# Query: brown line.
|
44 |
+
brown_line = track('brown line')[0]
|
45 |
+
ret_val = brown_line
|
46 |
+
|
47 |
+
objects = ['table', 'gripper', 'green block', 'cup holder', 'black block']
|
48 |
+
# Query: block.
|
49 |
+
block = track('green block')[0]
|
50 |
+
ret_val = block
|
51 |
+
|
52 |
+
objects = ['table', 'gripper', 'mouse', 'yellow bowl', 'brown bowl', 'sticker']
|
53 |
+
# Query: bowl closest to the sticker.
|
54 |
+
bowls = track('bowl')
|
55 |
+
sticker = track('sticker')[0]
|
56 |
+
closest_bowl = min(bowls, key=lambda x: np.linalg.norm(x.position - sticker.position))
|
57 |
+
ret_val = closest_bowl
|
58 |
+
|
59 |
+
objects = ['table', 'gripper', 'keyboard', 'brown bag', 'pink bag', 'red tape', 'bottle']
|
60 |
+
# Query: bag with the red tape on top.
|
61 |
+
bags = track('bag')
|
62 |
+
red_tape = track('red tape')[0]
|
63 |
+
bag_with_red_tape = min(bags, key=lambda x: np.linalg.norm(x.position - red_tape.position))
|
64 |
+
ret_val = bag_with_red_tape
|
65 |
+
|
66 |
+
objects = ['table', 'gripper', 'grape', 'wood tray', 'strawberry', 'white tray', 'blue tray', 'bread']
|
67 |
+
# Query: tray that contains the bread.
|
68 |
+
trays = track('tray')
|
69 |
+
bread = track('bread')[0]
|
70 |
+
tray_with_bread = min(trays, key=lambda x: np.linalg.norm(x.position - bread.position))
|
71 |
+
ret_val = tray_with_bread
|
72 |
+
|
73 |
+
objects = ['table', 'gripper', 'drawer']
|
74 |
+
# Query: top drawer handle.
|
75 |
+
handles = track('drawer handle')
|
76 |
+
top_drawer_handle = max(handles, key=lambda x: x.position[2])
|
77 |
+
ret_val = top_drawer_handle
|
78 |
+
|
79 |
+
objects = ['table', 'gripper', 'door']
|
80 |
+
# Query: the thing you can open the door with.
|
81 |
+
door_handle = track('door handle')[0]
|
82 |
+
ret_val = door_handle
|
83 |
+
|
84 |
+
objects = ['table', 'gripper', 'glass', 'vase', 'plastic bottle', 'block', 'phone case']
|
85 |
+
# Query: anything fragile.
|
86 |
+
fragile_items = []
|
87 |
+
for obj in ['glass', 'vase']:
|
88 |
+
item = track(obj)[0]
|
89 |
+
fragile_items.append(item)
|
90 |
+
ret_val = fragile_items
|
91 |
+
|
92 |
+
objects = ['table', 'gripper', 'fridge']
|
93 |
+
# Query: fridge handle.
|
94 |
+
fridge_handle = track('fridge handle')[0]
|
95 |
+
ret_val = fridge_handle
|
96 |
+
|
97 |
+
objects = ['table', 'gripper', 'blue block', 'red block']
|
98 |
+
# Query: green block.
|
99 |
+
ret_val = None
|
100 |
+
|
101 |
+
objects = ['table', 'gripper', 'yellow bowl', 'red spoon']
|
102 |
+
# Query: gripper.
|
103 |
+
gripper = track('gripper')[0]
|
104 |
+
ret_val = gripper
|
agibot_prompts/agibot_planner.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import execute
|
3 |
+
from perception_utils import parse_query_obj
|
4 |
+
import action_utils import composer
|
5 |
+
|
6 |
+
objects = ['blue block', 'yellow block', 'mug']
|
7 |
+
# Query: place the blue block on the yellow block, and avoid the mug at all time.
|
8 |
+
composer("grasp the blue block while keeping at least 15cm away from the mug")
|
9 |
+
composer("back to default pose")
|
10 |
+
composer("move to 5cm on top of the yellow block while keeping at least 15cm away from the mug")
|
11 |
+
composer("open gripper")
|
12 |
+
# done
|
13 |
+
|
14 |
+
objects = ['airpods', 'drawer']
|
15 |
+
# Query: Open the drawer slowly.
|
16 |
+
composer("grasp the drawer handle, at 0.5x speed")
|
17 |
+
composer("move away from the drawer handle by 25cm, at 0.5x speed")
|
18 |
+
composer("open gripper, at 0.5x speed")
|
19 |
+
# done
|
20 |
+
|
21 |
+
objects = ['tissue box', 'tissue', 'bowl']
|
22 |
+
# Query: Can you pass me a tissue and place it next to the bowl?
|
23 |
+
composer("grasp the tissue")
|
24 |
+
composer("back to default pose")
|
25 |
+
composer("move to 10cm to the right of the bowl")
|
26 |
+
composer("open gripper")
|
27 |
+
composer("back to default pose")
|
28 |
+
# done
|
29 |
+
|
30 |
+
objects = ['charger', 'outlet']
|
31 |
+
# Query: unplug the charger from the wall.
|
32 |
+
composer("grasp the charger")
|
33 |
+
composer("back to default pose")
|
34 |
+
# done
|
35 |
+
|
36 |
+
objects = ['grape', 'lemon', 'drill', 'router', 'bread', 'tray']
|
37 |
+
# Query: put the sweeter fruit in the tray that contains the bread.
|
38 |
+
composer("grasp the grape")
|
39 |
+
composer("back to default pose")
|
40 |
+
composer("move to the top of the tray that contains the bread")
|
41 |
+
composer("open gripper")
|
42 |
+
# done
|
43 |
+
|
44 |
+
objects = ['marbles', 'tray', 'broom']
|
45 |
+
# Query: Can you sweep the marbles into the tray?
|
46 |
+
composer("grasp the broom")
|
47 |
+
composer("back to default pose")
|
48 |
+
composer("push the marbles into the tray")
|
49 |
+
# done
|
50 |
+
|
51 |
+
objects = ['orange', 'QR code', 'lemon', 'drawer']
|
52 |
+
# Query: put the sour fruit into the top drawer.
|
53 |
+
composer("grasp the top drawer handle")
|
54 |
+
composer("move away from the top drawer handle by 25cm")
|
55 |
+
composer("open gripper")
|
56 |
+
composer("back to default pose")
|
57 |
+
composer("grasp the lemon")
|
58 |
+
composer("move to 10cm on top of the top drawer")
|
59 |
+
composer("open gripper")
|
60 |
+
# done
|
61 |
+
|
62 |
+
objects = ['fridge', 'hot soup']
|
63 |
+
# Query: Open the fridge door and be careful around the hot soup.
|
64 |
+
composer("grasp the fridge handle and keep at least 15cm away from the hot soup")
|
65 |
+
composer("move away from the fridge handle by 25cm and keep at least 15cm away from the hot soup")
|
66 |
+
composer("open gripper")
|
67 |
+
# done
|
68 |
+
|
69 |
+
objects = ['cyan bowl', 'yellow bowl', 'box', 'ice cream']
|
70 |
+
# Query: move to the top of the cyan bowl.
|
71 |
+
composer("move to the top of the cyan bowl")
|
72 |
+
# done
|
73 |
+
|
74 |
+
objects = ['drawer', 'umbrella']
|
75 |
+
# Query: close the drawer.
|
76 |
+
composer("push close the drawer handle by 25cm")
|
77 |
+
# done
|
78 |
+
|
79 |
+
objects = ['plate', 'steak', 'fork', 'knife', 'spoon']
|
80 |
+
# Query: Could you please set up the fork for the steak for me?
|
81 |
+
composer("grasp the fork")
|
82 |
+
composer("back to default pose")
|
83 |
+
composer("move to 10cm to the right of the plate")
|
84 |
+
composer("open gripper")
|
85 |
+
composer("back to default pose")
|
86 |
+
# done
|
87 |
+
|
88 |
+
objects = ['light switch']
|
89 |
+
# Query: Press down the switch.
|
90 |
+
composer("close the gripper")
|
91 |
+
composer("move to the center of the light switch")
|
92 |
+
composer("back to default pose")
|
93 |
+
# done
|
94 |
+
|
95 |
+
objects = ['beer']
|
96 |
+
# Query: turn close the beer.
|
97 |
+
composer("grasp the beer cap")
|
98 |
+
composer("turn clockwise by 180 degrees")
|
99 |
+
composer("back to default pose")
|
100 |
+
# done
|
101 |
+
|
102 |
+
objects = ['steak', 'grill', 'plate']
|
103 |
+
# Query: Take the steak out of the grill and put it flat on the plate.
|
104 |
+
composer("grasp the steak")
|
105 |
+
composer("back to default pose")
|
106 |
+
composer("rotate the gripper to be 45 degrees slanted relative to the plate")
|
107 |
+
composer("move to 10cm on top of the plate")
|
108 |
+
composer("open gripper")
|
109 |
+
composer("back to default pose")
|
110 |
+
# done
|
111 |
+
|
112 |
+
objects = ['trash can', 'napkin']
|
113 |
+
# Query: sort napkin into trash can.
|
114 |
+
napkin = parse_query_obj("napkin")
|
115 |
+
trash_can = parse_query_obj("trash can")
|
116 |
+
while np.linalg.norm(napkin.position - trash_can.position) > 0.1:
|
117 |
+
composer("grasp the napkin")
|
118 |
+
composer("move to 10cm on top of the trash can")
|
119 |
+
composer("open gripper")
|
120 |
+
composer("back to default pose")
|
121 |
+
# done
|
app.py
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import numpy as np
|
3 |
+
from tempfile import NamedTemporaryFile
|
4 |
+
import copy
|
5 |
+
import shapely
|
6 |
+
from shapely.geometry import *
|
7 |
+
from shapely.affinity import *
|
8 |
+
from omegaconf import OmegaConf
|
9 |
+
from moviepy.editor import ImageSequenceClip
|
10 |
+
import gradio as gr
|
11 |
+
|
12 |
+
from lmp import LMP, LMPFGen
|
13 |
+
from sim import PickPlaceEnv, LMP_wrapper, VoxPoserWrapper, AgibotWrapper
|
14 |
+
from consts import ALL_BLOCKS, ALL_BOWLS
|
15 |
+
from md_logger import MarkdownLogger
|
16 |
+
from utils import get_geoip
|
17 |
+
|
18 |
+
class DemoRunner:
|
19 |
+
|
20 |
+
def __init__(self, config_file: str = 'cfg.yaml'):
|
21 |
+
self._cfg = OmegaConf.to_container(OmegaConf.load(config_file), resolve=True)
|
22 |
+
self._env = None
|
23 |
+
self._md_logger = MarkdownLogger()
|
24 |
+
|
25 |
+
def make_LMP(self, env, cfg_choice):
|
26 |
+
# LMP env wrapper
|
27 |
+
cfg = copy.deepcopy(self._cfg)
|
28 |
+
# cfg['env'] = {
|
29 |
+
# 'init_objs': list(env.obj_name_to_id.keys()),
|
30 |
+
# 'coords': cfg['tabletop_coords']
|
31 |
+
# }
|
32 |
+
|
33 |
+
if cfg_choice == "voxposer":
|
34 |
+
LMP_env = VoxPoserWrapper(env, cfg)
|
35 |
+
elif cfg_choice == "agibot":
|
36 |
+
LMP_env = AgibotWrapper(env, cfg)
|
37 |
+
|
38 |
+
# creating APIs that the LMPs can interact with
|
39 |
+
fixed_vars = {
|
40 |
+
'np': np
|
41 |
+
}
|
42 |
+
fixed_vars.update({
|
43 |
+
name: eval(name)
|
44 |
+
for name in shapely.geometry.__all__ + shapely.affinity.__all__
|
45 |
+
})
|
46 |
+
|
47 |
+
variable_vars = {
|
48 |
+
k: getattr(LMP_env, k)
|
49 |
+
for k in dir(LMP_env)
|
50 |
+
if not k.startswith("__") and callable(getattr(LMP_env, k))
|
51 |
+
}
|
52 |
+
variable_vars['say'] = lambda msg: self._md_logger.log_text(f'Robot says: "{msg}"')
|
53 |
+
|
54 |
+
# creating the function-generating LMP
|
55 |
+
lmp_fgen = LMPFGen(cfg['lmps']['fgen'], fixed_vars, variable_vars, self._md_logger)
|
56 |
+
|
57 |
+
# creating other low-level LMPs
|
58 |
+
variable_vars.update({
|
59 |
+
k: LMP(k, cfg['lmps'][k], lmp_fgen, fixed_vars, variable_vars, self._md_logger)
|
60 |
+
for k in cfg['lmps'].keys() if k != 'fgen'
|
61 |
+
})
|
62 |
+
|
63 |
+
# creating the LMP that deals w/ high-level language commands
|
64 |
+
lmp_planner = LMP(
|
65 |
+
'planner', cfg['lmps']['planner'], lmp_fgen, fixed_vars, variable_vars, self._md_logger
|
66 |
+
)
|
67 |
+
|
68 |
+
return lmp_planner
|
69 |
+
|
70 |
+
def setup(self, api_key, n_blocks, n_bowls, proxy, cfg_choice):
|
71 |
+
openai.api_key = api_key
|
72 |
+
|
73 |
+
# self._env = PickPlaceEnv(render=True, high_res=True, high_frame_rate=False)
|
74 |
+
# list_idxs = np.random.choice(len(ALL_BLOCKS), size=max(n_blocks, n_bowls), replace=False)
|
75 |
+
# block_list = [ALL_BLOCKS[i] for i in list_idxs[:n_blocks]]
|
76 |
+
# bowl_list = [ALL_BOWLS[i] for i in list_idxs[:n_bowls]]
|
77 |
+
# obj_list = block_list + bowl_list
|
78 |
+
# self._env.reset(obj_list)
|
79 |
+
|
80 |
+
self._lmp_planner = self.make_LMP(self._env, cfg_choice)
|
81 |
+
|
82 |
+
# info = '### Available Objects: \n- ' + '\n- '.join(obj_list)
|
83 |
+
# img = self._env.get_camera_image()
|
84 |
+
|
85 |
+
info, img = None, None
|
86 |
+
|
87 |
+
return info, img
|
88 |
+
|
89 |
+
def run(self, instruction):
|
90 |
+
# if self._env is None:
|
91 |
+
# return 'Please run setup first!', None, None
|
92 |
+
|
93 |
+
# self._env.cache_video = []
|
94 |
+
self._md_logger.clear()
|
95 |
+
|
96 |
+
self._lmp_planner(instruction)
|
97 |
+
|
98 |
+
# try:
|
99 |
+
# self._lmp_planner(instruction, f'objects = {self._env.object_list}')
|
100 |
+
# except Exception as e:
|
101 |
+
# return f'Error: {e}', None, None
|
102 |
+
|
103 |
+
# video_file_name = None
|
104 |
+
# if self._env.cache_video:
|
105 |
+
# rendered_clip = ImageSequenceClip(self._env.cache_video, fps=25)
|
106 |
+
# video_file_name = NamedTemporaryFile(suffix='.mp4').name
|
107 |
+
# rendered_clip.write_videofile(video_file_name, fps=25)
|
108 |
+
video_file_name = None
|
109 |
+
|
110 |
+
# return self._md_logger.get_log(), self._env.get_camera_image(), video_file_name
|
111 |
+
|
112 |
+
return self._md_logger.get_log(), None, video_file_name
|
113 |
+
|
114 |
+
|
115 |
+
def setup(api_key, n_blocks, n_bowls, proxy_addr, cfg_choice):
|
116 |
+
if not api_key:
|
117 |
+
return 'Please enter your OpenAI API key!', None, None
|
118 |
+
|
119 |
+
if not proxy_addr:
|
120 |
+
return 'Please enter your local proxy address!', None, None
|
121 |
+
|
122 |
+
if n_blocks + n_bowls == 0:
|
123 |
+
return 'Please select at least one object!', None, None
|
124 |
+
|
125 |
+
if "http://" in proxy_addr:
|
126 |
+
openai.proxy = proxy_addr
|
127 |
+
else:
|
128 |
+
openai.proxy = f"http://{proxy_addr}"
|
129 |
+
|
130 |
+
# ip_status, ip_info = get_geoip(openai.proxy)
|
131 |
+
# if ip_status == -1:
|
132 |
+
# return ip_info, None, None
|
133 |
+
# elif ip_status == 0:
|
134 |
+
# pressed_key = input('Continue with current ip location? (y/n)')
|
135 |
+
# if pressed_key.lower() != 'y':
|
136 |
+
# return ip_info, None, None
|
137 |
+
# else:
|
138 |
+
# print(f'{ip_info} IP location check passed.')
|
139 |
+
|
140 |
+
if cfg_choice == "voxposer":
|
141 |
+
cfg_file = 'cfg_voxposer.yaml'
|
142 |
+
elif cfg_choice == "agibot":
|
143 |
+
cfg_file = 'cfg_agibot.yaml'
|
144 |
+
|
145 |
+
demo_runner = DemoRunner(cfg_file)
|
146 |
+
|
147 |
+
info, img = demo_runner.setup(api_key, n_blocks, n_bowls, proxy_addr, cfg_choice)
|
148 |
+
return info, img, demo_runner
|
149 |
+
|
150 |
+
|
151 |
+
def run(instruction, demo_runner):
|
152 |
+
if demo_runner is None:
|
153 |
+
return 'Please run setup first!', None, None
|
154 |
+
return demo_runner.run(instruction)
|
155 |
+
|
156 |
+
|
157 |
+
if __name__ == '__main__':
|
158 |
+
with open('README.md', 'r') as f:
|
159 |
+
for _ in range(12):
|
160 |
+
next(f)
|
161 |
+
readme_text = f.read()
|
162 |
+
|
163 |
+
with gr.Blocks() as demo:
|
164 |
+
state = gr.State(None)
|
165 |
+
|
166 |
+
# gr.Markdown(readme_text)
|
167 |
+
gr.Markdown('# Interactive Demo')
|
168 |
+
with gr.Row():
|
169 |
+
with gr.Column():
|
170 |
+
with gr.Column():
|
171 |
+
inp_api_key = gr.Textbox(label='OpenAI API Key (this is not stored anywhere)', lines=1)
|
172 |
+
inp_proxy_addr = gr.Textbox(label='Your local proxy address', lines=1)
|
173 |
+
inp_cfg = gr.Dropdown(label='Configuration', choices=['voxposer', 'agibot'])
|
174 |
+
with gr.Row():
|
175 |
+
inp_n_blocks = gr.Slider(label='Number of Blocks', minimum=0, maximum=4, value=3, step=1)
|
176 |
+
inp_n_bowls = gr.Slider(label='Number of Bowls', minimum=0, maximum=4, value=3, step=1)
|
177 |
+
|
178 |
+
btn_setup = gr.Button("Setup/Reset Simulation")
|
179 |
+
info_setup = gr.Markdown(label='Setup Info')
|
180 |
+
with gr.Column():
|
181 |
+
img_setup = gr.Image(label='Current Simulation')
|
182 |
+
|
183 |
+
with gr.Row():
|
184 |
+
with gr.Column():
|
185 |
+
inp_instruction = gr.Textbox(label='Instruction', lines=1)
|
186 |
+
btn_run = gr.Button("Run (this may take 30+ seconds)")
|
187 |
+
info_run = gr.Markdown(label='Generated Code')
|
188 |
+
with gr.Column():
|
189 |
+
video_run = gr.Video(label='Video of Last Instruction')
|
190 |
+
|
191 |
+
btn_setup.click(
|
192 |
+
setup,
|
193 |
+
inputs=[inp_api_key, inp_n_blocks, inp_n_bowls, inp_proxy_addr, inp_cfg],
|
194 |
+
outputs=[info_setup, img_setup, state]
|
195 |
+
)
|
196 |
+
btn_run.click(
|
197 |
+
run,
|
198 |
+
inputs=[inp_instruction, state],
|
199 |
+
outputs=[info_run, img_setup, video_run]
|
200 |
+
)
|
201 |
+
|
202 |
+
demo.launch()
|
bowl/bowl.urdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:505058761a89c12542f9ba28c04061774a4016a65b53c3bfd822cf5a9dd19d1b
|
3 |
+
size 806
|
bowl/cup.obj
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:624cba3eaf09307b766ef791eea49a188a28f8969ec8b28c724ae1df4d4ce446
|
3 |
+
size 27464
|
bowl/textured-0008192.obj
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3fee6d4c3f8b4fe40de17801e9a475463c435b9e3f151fc5a9bcfc5a91355f2a
|
3 |
+
size 724293
|
cfg.yaml
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
lmps:
|
3 |
+
tabletop_ui:
|
4 |
+
prompt_path: prompts/tabletop_ui.py
|
5 |
+
engine: text-davinci-003
|
6 |
+
max_tokens: 256
|
7 |
+
temperature: 0
|
8 |
+
query_prefix: '# '
|
9 |
+
query_suffix: '.'
|
10 |
+
stop: ['#', 'objects = [']
|
11 |
+
maintain_session: True
|
12 |
+
debug_mode: False
|
13 |
+
include_context: True
|
14 |
+
has_return: False
|
15 |
+
return_val_name: ret_val
|
16 |
+
parse_obj_name:
|
17 |
+
prompt_path: prompts/parse_obj_name.py
|
18 |
+
engine: text-davinci-003
|
19 |
+
max_tokens: 512
|
20 |
+
temperature: 0
|
21 |
+
query_prefix: '# '
|
22 |
+
query_suffix: '.'
|
23 |
+
stop: ['#', 'objects = [']
|
24 |
+
maintain_session: False
|
25 |
+
debug_mode: False
|
26 |
+
include_context: True
|
27 |
+
has_return: True
|
28 |
+
return_val_name: ret_val
|
29 |
+
parse_position:
|
30 |
+
prompt_path: prompts/parse_position.py
|
31 |
+
engine: text-davinci-003
|
32 |
+
max_tokens: 512
|
33 |
+
temperature: 0
|
34 |
+
query_prefix: '# '
|
35 |
+
query_suffix: '.'
|
36 |
+
stop: ['#']
|
37 |
+
maintain_session: False
|
38 |
+
debug_mode: False
|
39 |
+
include_context: True
|
40 |
+
has_return: True
|
41 |
+
return_val_name: ret_val
|
42 |
+
parse_question:
|
43 |
+
prompt_path: prompts/parse_question.py
|
44 |
+
engine: text-davinci-003
|
45 |
+
max_tokens: 512
|
46 |
+
temperature: 0
|
47 |
+
query_prefix: '# '
|
48 |
+
query_suffix: '.'
|
49 |
+
stop: ['#', 'objects = [']
|
50 |
+
maintain_session: False
|
51 |
+
debug_mode: False
|
52 |
+
include_context: True
|
53 |
+
has_return: True
|
54 |
+
return_val_name: ret_val
|
55 |
+
transform_shape_pts:
|
56 |
+
prompt_path: prompts/transform_shape_pts.py
|
57 |
+
engine: text-davinci-003
|
58 |
+
max_tokens: 512
|
59 |
+
temperature: 0
|
60 |
+
query_prefix: '# '
|
61 |
+
query_suffix: '.'
|
62 |
+
stop: ['#']
|
63 |
+
maintain_session: False
|
64 |
+
debug_mode: False
|
65 |
+
include_context: True
|
66 |
+
has_return: True
|
67 |
+
return_val_name: new_shape_pts
|
68 |
+
fgen:
|
69 |
+
prompt_path: prompts/fgen.py
|
70 |
+
engine: text-davinci-003
|
71 |
+
max_tokens: 512
|
72 |
+
temperature: 0
|
73 |
+
query_prefix: '# define function: '
|
74 |
+
query_suffix: '.'
|
75 |
+
stop: ['# define', '# example']
|
76 |
+
maintain_session: False
|
77 |
+
debug_mode: False
|
78 |
+
include_context: True
|
79 |
+
|
80 |
+
tabletop_coords:
|
81 |
+
top_left: [-0.25, -0.25]
|
82 |
+
top_side: [0, -0.25]
|
83 |
+
top_right: [0.25, -0.25]
|
84 |
+
left_side: [-0.25, -0.5]
|
85 |
+
middle: [0, -0.5]
|
86 |
+
right_side: [0.25, -0.5]
|
87 |
+
bottom_left: [-0.25, -0.75]
|
88 |
+
bottom_side: [0, -0.75]
|
89 |
+
bottom_right: [0.25, -0.75]
|
90 |
+
table_z: 0
|
cfg_agibot.yaml
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
lmps:
|
2 |
+
planner:
|
3 |
+
prompt_path: agibot_prompts/agibot_planner.py
|
4 |
+
model: gpt-4
|
5 |
+
max_tokens: 1024
|
6 |
+
temperature: 0
|
7 |
+
query_prefix: '# Query: '
|
8 |
+
query_suffix: '.'
|
9 |
+
stop: ['#', 'objects = [']
|
10 |
+
maintain_session: True
|
11 |
+
debug_mode: False
|
12 |
+
include_context: True
|
13 |
+
has_return: False
|
14 |
+
return_val_name: ret_val
|
15 |
+
composer:
|
16 |
+
prompt_path: agibot_prompts/agibot_composer.py
|
17 |
+
model: gpt-4
|
18 |
+
max_tokens: 1024
|
19 |
+
temperature: 0
|
20 |
+
query_prefix: '# Query: '
|
21 |
+
query_suffix: '.'
|
22 |
+
stop: ['#', 'objects = [']
|
23 |
+
maintain_session: False
|
24 |
+
debug_mode: False
|
25 |
+
include_context: True
|
26 |
+
has_return: False
|
27 |
+
return_val_name: ret_val
|
28 |
+
search_object:
|
29 |
+
prompt_path: agibot_prompts/agibot_perceptor.py
|
30 |
+
model: gpt-4
|
31 |
+
max_tokens: 512
|
32 |
+
temperature: 0
|
33 |
+
query_prefix: '# Query: '
|
34 |
+
query_suffix: '.'
|
35 |
+
stop: ['#']
|
36 |
+
maintain_session: False
|
37 |
+
debug_mode: True
|
38 |
+
include_context: True
|
39 |
+
has_return: True
|
40 |
+
return_val_name: ret_val
|
41 |
+
fgen:
|
42 |
+
prompt_path: prompts/fgen.py
|
43 |
+
engine: gpt-4
|
44 |
+
max_tokens: 512
|
45 |
+
temperature: 0
|
46 |
+
query_prefix: '# define function: '
|
47 |
+
query_suffix: '.'
|
48 |
+
stop: ['# define', '# example']
|
49 |
+
maintain_session: False
|
50 |
+
debug_mode: False
|
51 |
+
include_context: True
|
cfg_voxposer.yaml
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
lmps:
|
3 |
+
planner:
|
4 |
+
prompt_path: VoxPoserApiExamples/Real/planner/real_planner_prompt.py
|
5 |
+
model: gpt-4
|
6 |
+
max_tokens: 1024
|
7 |
+
temperature: 0
|
8 |
+
query_prefix: '# Query: '
|
9 |
+
query_suffix: '.'
|
10 |
+
stop: ['#', 'objects = [']
|
11 |
+
maintain_session: True
|
12 |
+
debug_mode: False
|
13 |
+
include_context: True
|
14 |
+
has_return: False
|
15 |
+
return_val_name: ret_val
|
16 |
+
composer:
|
17 |
+
prompt_path: VoxPoserApiExamples/Real/composer/real_composer_prompt.py
|
18 |
+
model: gpt-4
|
19 |
+
max_tokens: 1024
|
20 |
+
temperature: 0
|
21 |
+
query_prefix: '# Query: '
|
22 |
+
query_suffix: '.'
|
23 |
+
stop: ['#', 'objects = [']
|
24 |
+
maintain_session: False
|
25 |
+
debug_mode: False
|
26 |
+
include_context: True
|
27 |
+
has_return: False
|
28 |
+
return_val_name: ret_val
|
29 |
+
get_affordance_map:
|
30 |
+
prompt_path: VoxPoserApiExamples/Real/value_maps/real_get_affordance_map_prompt.py
|
31 |
+
model: gpt-4
|
32 |
+
max_tokens: 512
|
33 |
+
temperature: 0
|
34 |
+
query_prefix: '# Query: '
|
35 |
+
query_suffix: '.'
|
36 |
+
stop: ['#']
|
37 |
+
maintain_session: False
|
38 |
+
debug_mode: True
|
39 |
+
include_context: True
|
40 |
+
has_return: True
|
41 |
+
return_val_name: ret_val
|
42 |
+
get_avoidance_map:
|
43 |
+
prompt_path: VoxPoserApiExamples/Real/value_maps/real_get_avoidance_map_prompt.py
|
44 |
+
model: gpt-4
|
45 |
+
max_tokens: 512
|
46 |
+
temperature: 0
|
47 |
+
query_prefix: '# Query: '
|
48 |
+
query_suffix: '.'
|
49 |
+
stop: ['#', 'objects = [']
|
50 |
+
maintain_session: False
|
51 |
+
debug_mode: True
|
52 |
+
include_context: True
|
53 |
+
has_return: True
|
54 |
+
return_val_name: ret_val
|
55 |
+
get_gripper_map:
|
56 |
+
prompt_path: VoxPoserApiExamples/Real/value_maps/real_get_gripper_map_prompt.py
|
57 |
+
model: gpt-4
|
58 |
+
max_tokens: 512
|
59 |
+
temperature: 0
|
60 |
+
query_prefix: '# Query: '
|
61 |
+
query_suffix: '.'
|
62 |
+
stop: ['#']
|
63 |
+
maintain_session: False
|
64 |
+
debug_mode: True
|
65 |
+
include_context: True
|
66 |
+
has_return: True
|
67 |
+
return_val_name: new_shape_pts
|
68 |
+
get_rotation_map:
|
69 |
+
prompt_path: VoxPoserApiExamples/Real/value_maps/real_get_rotation_map_prompt.py
|
70 |
+
model: gpt-4
|
71 |
+
max_tokens: 512
|
72 |
+
temperature: 0
|
73 |
+
query_prefix: '# define function: '
|
74 |
+
query_suffix: '.'
|
75 |
+
stop: ['# define', '# example']
|
76 |
+
maintain_session: False
|
77 |
+
debug_mode: True
|
78 |
+
include_context: True
|
79 |
+
has_return: True
|
80 |
+
get_velocity_map:
|
81 |
+
prompt_path: VoxPoserApiExamples/Real/value_maps/real_get_velocity_map_prompt.py
|
82 |
+
model: gpt-4
|
83 |
+
max_tokens: 512
|
84 |
+
temperature: 0
|
85 |
+
query_prefix: '# define function: '
|
86 |
+
query_suffix: '.'
|
87 |
+
stop: ['# define', '# example']
|
88 |
+
maintain_session: False
|
89 |
+
debug_mode: True
|
90 |
+
include_context: True
|
91 |
+
has_return: True
|
92 |
+
fgen:
|
93 |
+
prompt_path: prompts/fgen.py
|
94 |
+
engine: gpt-4
|
95 |
+
max_tokens: 512
|
96 |
+
temperature: 0
|
97 |
+
query_prefix: '# define function: '
|
98 |
+
query_suffix: '.'
|
99 |
+
stop: ['# define', '# example']
|
100 |
+
maintain_session: False
|
101 |
+
debug_mode: False
|
102 |
+
include_context: True
|
103 |
+
|
104 |
+
tabletop_coords:
|
105 |
+
top_left: [-0.25, -0.25]
|
106 |
+
top_side: [0, -0.25]
|
107 |
+
top_right: [0.25, -0.25]
|
108 |
+
left_side: [-0.25, -0.5]
|
109 |
+
middle: [0, -0.5]
|
110 |
+
right_side: [0.25, -0.5]
|
111 |
+
bottom_left: [-0.25, -0.75]
|
112 |
+
bottom_side: [0, -0.75]
|
113 |
+
bottom_right: [0.25, -0.75]
|
114 |
+
table_z: 0
|
consts.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
# # Global constants: pick and place objects, colors, workspace bounds
|
4 |
+
COLORS = {
|
5 |
+
'blue': (78/255, 121/255, 167/255, 255/255),
|
6 |
+
'red': (255/255, 87/255, 89/255, 255/255),
|
7 |
+
'green': (89/255, 169/255, 79/255, 255/255),
|
8 |
+
'orange': (242/255, 142/255, 43/255, 255/255),
|
9 |
+
'yellow': (237/255, 201/255, 72/255, 255/255),
|
10 |
+
'purple': (176/255, 122/255, 161/255, 255/255),
|
11 |
+
'pink': (255/255, 157/255, 167/255, 255/255),
|
12 |
+
'cyan': (118/255, 183/255, 178/255, 255/255),
|
13 |
+
'brown': (156/255, 117/255, 95/255, 255/255),
|
14 |
+
'gray': (186/255, 176/255, 172/255, 255/255),
|
15 |
+
}
|
16 |
+
|
17 |
+
CORNER_POS = {
|
18 |
+
'top left corner': (-0.3 + 0.05, -0.2 - 0.05, 0),
|
19 |
+
'top side': (0, -0.2 - 0.05, 0),
|
20 |
+
'top right corner': (0.3 - 0.05, -0.2 - 0.05, 0),
|
21 |
+
'left side': (-0.3 + 0.05, -0.5, 0),
|
22 |
+
'middle': (0, -0.5, 0),
|
23 |
+
'right side': (0.3 - 0.05, -0.5, 0),
|
24 |
+
'bottom left corner': (-0.3 + 0.05, -0.8 + 0.05, 0),
|
25 |
+
'bottom side': (0, -0.8 + 0.05, 0),
|
26 |
+
'bottom right corner': (0.3 - 0.05, -0.8 + 0.05, 0),
|
27 |
+
}
|
28 |
+
|
29 |
+
ALL_BLOCKS = ['blue block', 'red block', 'green block', 'orange block', 'yellow block', 'purple block', 'pink block', 'cyan block', 'brown block', 'gray block']
|
30 |
+
ALL_BOWLS = ['blue bowl', 'red bowl', 'green bowl', 'orange bowl', 'yellow bowl', 'purple bowl', 'pink bowl', 'cyan bowl', 'brown bowl', 'gray bowl']
|
31 |
+
|
32 |
+
PIXEL_SIZE = 0.00267857
|
33 |
+
BOUNDS = np.float32([[-0.3, 0.3], [-0.8, -0.2], [0, 0.15]]) # X Y Z
|
lmp.py
ADDED
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from time import sleep
|
2 |
+
import ast
|
3 |
+
import astunparse
|
4 |
+
import openai
|
5 |
+
from openai.error import RateLimitError, APIConnectionError
|
6 |
+
from pygments import highlight
|
7 |
+
from pygments.lexers import PythonLexer
|
8 |
+
from pygments.formatters import TerminalFormatter
|
9 |
+
|
10 |
+
from utils import retrieve_proxy, chat_completion_request, generate_messages
|
11 |
+
|
12 |
+
class LMP:
|
13 |
+
|
14 |
+
def __init__(self, name, cfg, lmp_fgen, fixed_vars, variable_vars, md_logger):
|
15 |
+
self._name = name
|
16 |
+
self._cfg = cfg
|
17 |
+
self._md_logger = md_logger
|
18 |
+
|
19 |
+
with open(self._cfg['prompt_path'], 'r') as f:
|
20 |
+
self._base_prompt = f.read()
|
21 |
+
|
22 |
+
self._stop_tokens = list(self._cfg['stop'])
|
23 |
+
|
24 |
+
self._lmp_fgen = lmp_fgen
|
25 |
+
|
26 |
+
self._fixed_vars = fixed_vars
|
27 |
+
self._variable_vars = variable_vars
|
28 |
+
self.exec_hist = ''
|
29 |
+
|
30 |
+
def clear_exec_hist(self):
|
31 |
+
self.exec_hist = ''
|
32 |
+
|
33 |
+
def build_prompt(self, query, context=''):
|
34 |
+
if len(self._variable_vars) > 0:
|
35 |
+
variable_vars_imports_str = f"from utils import {', '.join(self._variable_vars.keys())}"
|
36 |
+
else:
|
37 |
+
variable_vars_imports_str = ''
|
38 |
+
prompt = self._base_prompt.replace('{variable_vars_imports}', variable_vars_imports_str)
|
39 |
+
|
40 |
+
if self._cfg['maintain_session']:
|
41 |
+
prompt += f'\n{self.exec_hist}'
|
42 |
+
|
43 |
+
if context != '':
|
44 |
+
prompt += f'\n{context}'
|
45 |
+
|
46 |
+
use_query = f'{self._cfg["query_prefix"]}{query}{self._cfg["query_suffix"]}'
|
47 |
+
prompt += f'\n{use_query}'
|
48 |
+
|
49 |
+
return prompt, use_query
|
50 |
+
|
51 |
+
def __call__(self, query, context='', **kwargs):
|
52 |
+
prompt, use_query = self.build_prompt(query, context=context)
|
53 |
+
|
54 |
+
response = chat_completion_request(
|
55 |
+
generate_messages(prompt),
|
56 |
+
# stop=self._stop_tokens,
|
57 |
+
temperature=self._cfg['temperature'],
|
58 |
+
model=self._cfg['model'],
|
59 |
+
max_tokens=self._cfg['max_tokens'],
|
60 |
+
proxy=openai.proxy,
|
61 |
+
)
|
62 |
+
code_str = response.json()["choices"][0]["message"]['content']
|
63 |
+
|
64 |
+
if self._cfg['include_context'] and context != '':
|
65 |
+
to_exec = f'{context}\n{code_str}'
|
66 |
+
to_log = f'{context}\n{use_query}\n{code_str}'
|
67 |
+
else:
|
68 |
+
to_exec = code_str
|
69 |
+
to_log = f'{use_query}\n{to_exec}'
|
70 |
+
|
71 |
+
to_log_pretty = highlight(to_log, PythonLexer(), TerminalFormatter())
|
72 |
+
print(f'LMP {self._name} generated code:\n{to_log_pretty}')
|
73 |
+
self._md_logger.log_text(f'LMP {self._name} Generated Code:')
|
74 |
+
self._md_logger.log_code(to_log)
|
75 |
+
|
76 |
+
new_fs = self._lmp_fgen.create_new_fs_from_code(code_str)
|
77 |
+
self._variable_vars.update(new_fs)
|
78 |
+
|
79 |
+
gvars = merge_dicts([self._fixed_vars, self._variable_vars])
|
80 |
+
lvars = kwargs
|
81 |
+
|
82 |
+
if not self._cfg['debug_mode']:
|
83 |
+
exec_safe(to_exec, gvars, lvars)
|
84 |
+
|
85 |
+
self.exec_hist += f'\n{to_exec}'
|
86 |
+
|
87 |
+
if self._cfg['maintain_session']:
|
88 |
+
self._variable_vars.update(lvars)
|
89 |
+
|
90 |
+
if self._cfg['has_return'] and not self._cfg['debug_mode']:
|
91 |
+
return lvars[self._cfg['return_val_name']]
|
92 |
+
|
93 |
+
class LMPFGen:
|
94 |
+
|
95 |
+
def __init__(self, cfg, fixed_vars, variable_vars, md_logger):
|
96 |
+
self._cfg = cfg
|
97 |
+
|
98 |
+
self._stop_tokens = list(self._cfg['stop'])
|
99 |
+
self._fixed_vars = fixed_vars
|
100 |
+
self._variable_vars = variable_vars
|
101 |
+
self._md_logger = md_logger
|
102 |
+
|
103 |
+
with open(self._cfg['prompt_path'], 'r') as f:
|
104 |
+
self._base_prompt = f.read()
|
105 |
+
|
106 |
+
def create_f_from_sig(self, f_name, f_sig, other_vars=None, fix_bugs=False, return_src=False):
|
107 |
+
print(f'Creating function: {f_sig}')
|
108 |
+
|
109 |
+
use_query = f'{self._cfg["query_prefix"]}{f_sig}{self._cfg["query_suffix"]}'
|
110 |
+
prompt = f'{self._base_prompt}\n{use_query}'
|
111 |
+
|
112 |
+
response = chat_completion_request(
|
113 |
+
generate_messages(prompt),
|
114 |
+
temperature=self._cfg['temperature'],
|
115 |
+
model=self._cfg['model'],
|
116 |
+
max_tokens=self._cfg['max_tokens'],
|
117 |
+
proxy=openai.proxy,
|
118 |
+
)
|
119 |
+
f_src = response.json()["choices"][0]["message"]['content']
|
120 |
+
|
121 |
+
if fix_bugs:
|
122 |
+
f_src = openai.Edit.create(
|
123 |
+
model='code-davinci-edit-001',
|
124 |
+
input='# ' + f_src,
|
125 |
+
temperature=0,
|
126 |
+
instruction='Fix the bug if there is one. Improve readability. Keep same inputs and outputs. Only small changes. No comments.',
|
127 |
+
)['choices'][0]['text'].strip()
|
128 |
+
|
129 |
+
if other_vars is None:
|
130 |
+
other_vars = {}
|
131 |
+
gvars = merge_dicts([self._fixed_vars, self._variable_vars, other_vars])
|
132 |
+
lvars = {}
|
133 |
+
|
134 |
+
exec_safe(f_src, gvars, lvars)
|
135 |
+
|
136 |
+
f = lvars[f_name]
|
137 |
+
|
138 |
+
to_print = f'{use_query}\n{f_src}'
|
139 |
+
to_print_pretty = highlight(to_print, PythonLexer(), TerminalFormatter())
|
140 |
+
print(f'LMPFGen generated code:\n{to_print_pretty}')
|
141 |
+
self._md_logger.log_text('Generated Function:')
|
142 |
+
self._md_logger.log_code(to_print)
|
143 |
+
|
144 |
+
if return_src:
|
145 |
+
return f, f_src
|
146 |
+
return f
|
147 |
+
|
148 |
+
def create_new_fs_from_code(self, code_str, other_vars=None, fix_bugs=False, return_src=False):
|
149 |
+
fs, f_assigns = {}, {}
|
150 |
+
f_parser = FunctionParser(fs, f_assigns)
|
151 |
+
f_parser.visit(ast.parse(code_str))
|
152 |
+
for f_name, f_assign in f_assigns.items():
|
153 |
+
if f_name in fs:
|
154 |
+
fs[f_name] = f_assign
|
155 |
+
|
156 |
+
if other_vars is None:
|
157 |
+
other_vars = {}
|
158 |
+
|
159 |
+
new_fs = {}
|
160 |
+
srcs = {}
|
161 |
+
for f_name, f_sig in fs.items():
|
162 |
+
all_vars = merge_dicts([self._fixed_vars, self._variable_vars, new_fs, other_vars])
|
163 |
+
if not var_exists(f_name, all_vars):
|
164 |
+
f, f_src = self.create_f_from_sig(f_name, f_sig, new_fs, fix_bugs=fix_bugs, return_src=True)
|
165 |
+
|
166 |
+
# recursively define child_fs in the function body if needed
|
167 |
+
f_def_body = astunparse.unparse(ast.parse(f_src).body[0].body)
|
168 |
+
child_fs, child_f_srcs = self.create_new_fs_from_code(
|
169 |
+
f_def_body, other_vars=all_vars, fix_bugs=fix_bugs, return_src=True
|
170 |
+
)
|
171 |
+
|
172 |
+
if len(child_fs) > 0:
|
173 |
+
new_fs.update(child_fs)
|
174 |
+
srcs.update(child_f_srcs)
|
175 |
+
|
176 |
+
# redefine parent f so newly created child_fs are in scope
|
177 |
+
gvars = merge_dicts([self._fixed_vars, self._variable_vars, new_fs, other_vars])
|
178 |
+
lvars = {}
|
179 |
+
|
180 |
+
exec_safe(f_src, gvars, lvars)
|
181 |
+
|
182 |
+
f = lvars[f_name]
|
183 |
+
|
184 |
+
new_fs[f_name], srcs[f_name] = f, f_src
|
185 |
+
|
186 |
+
if return_src:
|
187 |
+
return new_fs, srcs
|
188 |
+
return new_fs
|
189 |
+
|
190 |
+
|
191 |
+
class FunctionParser(ast.NodeTransformer):
|
192 |
+
|
193 |
+
def __init__(self, fs, f_assigns):
|
194 |
+
super().__init__()
|
195 |
+
self._fs = fs
|
196 |
+
self._f_assigns = f_assigns
|
197 |
+
|
198 |
+
def visit_Call(self, node):
|
199 |
+
self.generic_visit(node)
|
200 |
+
if isinstance(node.func, ast.Name):
|
201 |
+
f_sig = astunparse.unparse(node).strip()
|
202 |
+
f_name = astunparse.unparse(node.func).strip()
|
203 |
+
self._fs[f_name] = f_sig
|
204 |
+
return node
|
205 |
+
|
206 |
+
def visit_Assign(self, node):
|
207 |
+
self.generic_visit(node)
|
208 |
+
if isinstance(node.value, ast.Call):
|
209 |
+
assign_str = astunparse.unparse(node).strip()
|
210 |
+
f_name = astunparse.unparse(node.value.func).strip()
|
211 |
+
self._f_assigns[f_name] = assign_str
|
212 |
+
return node
|
213 |
+
|
214 |
+
|
215 |
+
def var_exists(name, all_vars):
|
216 |
+
try:
|
217 |
+
eval(name, all_vars)
|
218 |
+
except:
|
219 |
+
exists = False
|
220 |
+
else:
|
221 |
+
exists = True
|
222 |
+
return exists
|
223 |
+
|
224 |
+
|
225 |
+
def merge_dicts(dicts):
|
226 |
+
return {
|
227 |
+
k : v
|
228 |
+
for d in dicts
|
229 |
+
for k, v in d.items()
|
230 |
+
}
|
231 |
+
|
232 |
+
|
233 |
+
import traceback
|
234 |
+
def exec_safe(code_str, gvars=None, lvars=None):
|
235 |
+
banned_phrases = ['import', '__']
|
236 |
+
for phrase in banned_phrases:
|
237 |
+
assert phrase not in code_str
|
238 |
+
|
239 |
+
if gvars is None:
|
240 |
+
gvars = {}
|
241 |
+
if lvars is None:
|
242 |
+
lvars = {}
|
243 |
+
empty_fn = lambda *args, **kwargs: None
|
244 |
+
custom_gvars = merge_dicts([
|
245 |
+
gvars,
|
246 |
+
{'exec': empty_fn, 'eval': empty_fn}
|
247 |
+
])
|
248 |
+
|
249 |
+
try:
|
250 |
+
exec(code_str, custom_gvars, lvars)
|
251 |
+
except Exception as e:
|
252 |
+
traceback.print_exc()
|
253 |
+
# exec(code_str, custom_gvars, lvars)
|
md_logger.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class MarkdownLogger:
|
2 |
+
|
3 |
+
def __init__(self):
|
4 |
+
self._log = ''
|
5 |
+
|
6 |
+
def log_text(self, text):
|
7 |
+
self._log += '\n' + text + '\n'
|
8 |
+
|
9 |
+
def log_code(self, code):
|
10 |
+
self._log += f'\n```python\n{code}\n```\n'
|
11 |
+
|
12 |
+
def clear(self):
|
13 |
+
self._log = ''
|
14 |
+
|
15 |
+
def get_log(self):
|
16 |
+
return self._log
|
prompts/fgen.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from shapely.geometry import *
|
3 |
+
from shapely.affinity import *
|
4 |
+
|
5 |
+
from env_utils import get_obj_pos, get_obj_names
|
6 |
+
from ctrl_utils import put_first_on_second
|
7 |
+
|
8 |
+
# define function: total = get_total(xs=numbers).
|
9 |
+
def get_total(xs):
|
10 |
+
return np.sum(xs)
|
11 |
+
|
12 |
+
# define function: y = eval_line(x, slope, y_intercept=0).
|
13 |
+
def eval_line(x, slope, y_intercept):
|
14 |
+
return x * slope + y_intercept
|
15 |
+
|
16 |
+
# define function: pt = get_pt_to_the_left(pt, dist).
|
17 |
+
def get_pt_to_the_left(pt, dist):
|
18 |
+
return pt + [-dist, 0]
|
19 |
+
|
20 |
+
# define function: pt = get_pt_to_the_top(pt, dist).
|
21 |
+
def get_pt_to_the_top(pt, dist):
|
22 |
+
return pt + [0, dist]
|
23 |
+
|
24 |
+
# define function line = make_line_by_length(length=x).
|
25 |
+
def make_line_by_length(length):
|
26 |
+
line = LineString([[0, 0], [length, 0]])
|
27 |
+
return line
|
28 |
+
|
29 |
+
# define function: line = make_vertical_line_by_length(length=x).
|
30 |
+
def make_vertical_line_by_length(length):
|
31 |
+
line = make_line_by_length(length)
|
32 |
+
vertical_line = rotate(line, 90)
|
33 |
+
return vertical_line
|
34 |
+
|
35 |
+
# define function: pt = interpolate_line(line, t=0.5).
|
36 |
+
def interpolate_line(line, t):
|
37 |
+
pt = line.interpolate(t, normalized=True)
|
38 |
+
return np.array(pt.coords[0])
|
39 |
+
|
40 |
+
# example: scale a line by 2.
|
41 |
+
line = make_line_by_length(1)
|
42 |
+
new_shape = scale(line, xfact=2, yfact=2)
|
43 |
+
|
44 |
+
# example: put object1 on top of object0.
|
45 |
+
put_first_on_second('object1', 'object0')
|
46 |
+
|
47 |
+
# example: get the position of the first object.
|
48 |
+
obj_names = get_obj_names()
|
49 |
+
pos_2d = get_obj_pos(obj_names[0])
|
prompts/parse_obj_name.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from env_utils import get_obj_pos, parse_position
|
3 |
+
from utils import get_obj_positions_np
|
4 |
+
|
5 |
+
objects = ['blue block', 'cyan block', 'purple bowl', 'gray bowl', 'brown bowl', 'pink block', 'purple block']
|
6 |
+
# the block closest to the purple bowl.
|
7 |
+
block_names = ['blue block', 'cyan block', 'purple block']
|
8 |
+
closest_block_idx = get_closest_idx(points=get_obj_positions_np(block_names), point=get_obj_pos('purple bowl'))
|
9 |
+
closest_block_name = block_names[closest_block_idx]
|
10 |
+
ret_val = closest_block_name
|
11 |
+
objects = ['brown bowl', 'banana', 'brown block', 'apple', 'blue bowl', 'blue block']
|
12 |
+
# the blocks.
|
13 |
+
ret_val = ['brown block', 'blue block']
|
14 |
+
objects = ['brown bowl', 'banana', 'brown block', 'apple', 'blue bowl', 'blue block']
|
15 |
+
# the brown objects.
|
16 |
+
ret_val = ['brown bowl', 'brown block']
|
17 |
+
objects = ['brown bowl', 'banana', 'brown block', 'apple', 'blue bowl', 'blue block']
|
18 |
+
# a fruit that's not the apple
|
19 |
+
fruit_names = ['banana', 'apple']
|
20 |
+
for fruit_name in fruit_names:
|
21 |
+
if fruit_name != 'apple':
|
22 |
+
ret_val = fruit_name
|
23 |
+
objects = ['blue block', 'cyan block', 'purple bowl', 'brown bowl', 'purple block']
|
24 |
+
# blocks above the brown bowl.
|
25 |
+
block_names = ['blue block', 'cyan block', 'purple block']
|
26 |
+
brown_bowl_pos = get_obj_pos('brown bowl')
|
27 |
+
use_block_names = []
|
28 |
+
for block_name in block_names:
|
29 |
+
if get_obj_pos(block_name)[1] > brown_bowl_pos[1]:
|
30 |
+
use_block_names.append(block_name)
|
31 |
+
ret_val = use_block_names
|
32 |
+
objects = ['blue block', 'cyan block', 'purple bowl', 'brown bowl', 'purple block']
|
33 |
+
# the blue block.
|
34 |
+
ret_val = 'blue block'
|
35 |
+
objects = ['blue block', 'cyan block', 'purple bowl', 'brown bowl', 'purple block']
|
36 |
+
# the block closest to the bottom right corner.
|
37 |
+
corner_pos = parse_position('bottom right corner')
|
38 |
+
block_names = ['blue block', 'cyan block', 'purple block']
|
39 |
+
closest_block_idx = get_closest_idx(points=get_obj_positions_np(block_names), point=corner_pos)
|
40 |
+
closest_block_name = block_names[closest_block_idx]
|
41 |
+
ret_val = closest_block_name
|
42 |
+
objects = ['brown bowl', 'green block', 'brown block', 'green bowl', 'blue bowl', 'blue block']
|
43 |
+
# the left most block.
|
44 |
+
block_names = ['green block', 'brown block', 'blue block']
|
45 |
+
left_block_idx = np.argsort(get_obj_positions_np(block_names)[:, 0])[0]
|
46 |
+
left_block_name = block_names[left_block_idx]
|
47 |
+
ret_val = left_block_name
|
48 |
+
objects = ['brown bowl', 'green block', 'brown block', 'green bowl', 'blue bowl', 'blue block']
|
49 |
+
# the bowl on near the top.
|
50 |
+
bowl_names = ['brown bowl', 'green bowl', 'blue bowl']
|
51 |
+
top_bowl_idx = np.argsort(get_obj_positions_np(bowl_names)[:, 1])[-1]
|
52 |
+
top_bowl_name = bowl_names[top_bowl_idx]
|
53 |
+
ret_val = top_bowl_name
|
54 |
+
objects = ['yellow bowl', 'purple block', 'yellow block', 'purple bowl', 'pink bowl', 'pink block']
|
55 |
+
# the third bowl from the right.
|
56 |
+
bowl_names = ['yellow bowl', 'purple bowl', 'pink bowl']
|
57 |
+
bowl_idx = np.argsort(get_obj_positions_np(bowl_names)[:, 0])[-3]
|
58 |
+
bowl_name = bowl_names[bowl_idx]
|
59 |
+
ret_val = bowl_name
|