├── .gitignore
├── LICENSE
├── README.md
├── environment.yml
├── readme_imgs
├── concept_figure.png
└── poster.mp4
└── src
├── config
└── __init__.py
├── door_lock_verifier.py
├── door_locker.py
├── env
├── __init__.py
├── hand_manipulation_suite
│ ├── Adroit
│ │ ├── .gitignore
│ │ ├── Adroit_hand.xml
│ │ ├── Adroit_hand_withOverlay.xml
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── gallery
│ │ │ ├── news.JPG
│ │ │ └── projects.JPG
│ │ └── resources
│ │ │ ├── assets.xml
│ │ │ ├── chain.xml
│ │ │ ├── chain1.xml
│ │ │ ├── joint_position_actuation.xml
│ │ │ ├── meshes
│ │ │ ├── F1.stl
│ │ │ ├── F2.stl
│ │ │ ├── F3.stl
│ │ │ ├── TH1_z.stl
│ │ │ ├── TH2_z.stl
│ │ │ ├── TH3_z.stl
│ │ │ ├── arm_base.stl
│ │ │ ├── arm_trunk.stl
│ │ │ ├── arm_trunk_asmbly.stl
│ │ │ ├── distal_ellipsoid.stl
│ │ │ ├── elbow_flex.stl
│ │ │ ├── elbow_rotate_motor.stl
│ │ │ ├── elbow_rotate_muscle.stl
│ │ │ ├── forearm_Cy_PlateAsmbly(muscle_cone).stl
│ │ │ ├── forearm_Cy_PlateAsmbly.stl
│ │ │ ├── forearm_PlateAsmbly.stl
│ │ │ ├── forearm_electric.stl
│ │ │ ├── forearm_electric_cvx.stl
│ │ │ ├── forearm_muscle.stl
│ │ │ ├── forearm_simple.stl
│ │ │ ├── forearm_simple_cvx.stl
│ │ │ ├── forearm_weight.stl
│ │ │ ├── hand_base_link.STL
│ │ │ ├── hook_0.STL
│ │ │ ├── hook_1.STL
│ │ │ ├── hook_2.STL
│ │ │ ├── hook_3.STL
│ │ │ ├── knuckle.stl
│ │ │ ├── lfmetacarpal.stl
│ │ │ ├── palm.stl
│ │ │ ├── upper_arm.stl
│ │ │ ├── upper_arm_asmbl_shoulder.stl
│ │ │ ├── upper_arm_ass.stl
│ │ │ └── wrist.stl
│ │ │ └── tendon_torque_actuation.xml
│ ├── __init__.py
│ ├── assets
│ │ ├── DAPG_Adroit.xml
│ │ ├── DAPG_assets.xml
│ │ ├── DAPG_assets_hook.xml
│ │ ├── DAPG_door.xml
│ │ ├── DAPG_hammer.xml
│ │ ├── DAPG_pen.xml
│ │ ├── DAPG_relocate.xml
│ │ ├── door_xknob_adroit.xml
│ │ ├── door_xknob_adroit_extrageom.xml
│ │ ├── door_xknob_hook.xml
│ │ └── tasks.jpg
│ ├── door_lock_adroit_simple.py
│ ├── door_lock_verify_adroit_simple.py
│ └── door_v0.py
└── robel
│ └── dclaw_env.py
└── robel_screw_pi_task.py
/.gitignore:
--------------------------------------------------------------------------------
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 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
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 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | venv/
108 | ENV/
109 | env.bak/
110 | venv.bak/
111 |
112 | # Spyder project settings
113 | .spyderproject
114 | .spyproject
115 |
116 | # Rope project settings
117 | .ropeproject
118 |
119 | # mkdocs documentation
120 | /site
121 |
122 | # mypy
123 | .mypy_cache/
124 | .dmypy.json
125 | dmypy.json
126 |
127 | # Pyre type checker
128 | .pyre/
129 |
130 | .vscode/
131 | demos/
132 | videos/
133 | .DS_Store
134 | draft.py
135 | checkpoints/
136 | figures/
137 | MUJOCO_LOG.TXT
138 | *.zip
139 | *.npy
140 |
141 | nohup.out
142 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Training Robots to Evaluate Robots: Example-Based Interactive Reward Functions for Policy Learning
2 |
3 | CoRL 2022 (Oral)\
4 | [Kun Huang](https://www.linkedin.com/in/kun-huang-620034171/), [Edward S. Hu](https://edwardshu.com/), [Dinesh Jayaraman](https://www.seas.upenn.edu/~dineshj/)
5 | #### [[Paper (Openreview)]](https://openreview.net/forum?id=sK2aWU7X9b8) [[Project Website]](https://sites.google.com/view/lirf-corl-2022/) [[Poster]](https://github.com/penn-pal-lab/interactive_reward_functions/blob/main/readme_imgs/poster.mp4)
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Physical interactions can often help reveal information that is not readily apparent. For example, we may tug at a table leg to evaluate whether it is built well, or turn a water bottle upside down to check that it is watertight. We propose to train robots to acquire such interactive behaviors automatically, for the purpose of evaluating the result of an attempted robotic skill execution. These evaluations in turn serve as "interactive reward functions" (IRFs) for training reinforcement learning policies to perform the target skill, such as screwing the table leg tightly. In addition, even after task policies are fully trained, IRFs can serve as verification mechanisms that improve online task execution. For any given task, our IRFs can be conveniently trained using only examples of successful outcomes, and no further specification is needed to train the task policy thereafter. In our evaluations on door locking and weighted block stacking in simulation, and screw tightening on a real robot, IRFs enable large performance improvements, even outperforming baselines with access to demonstrations or carefully engineered rewards.
14 |
15 | If you find this work useful in your research, please cite:
16 | ```
17 | @inproceedings{
18 | huang2022training,
19 | title={Training Robots to Evaluate Robots: Example-Based Interactive Reward Functions for Policy Learning},
20 | author={Kun Huang and Edward S. Hu and Dinesh Jayaraman},
21 | booktitle={6th Annual Conference on Robot Learning},
22 | year={2022},
23 | url={https://openreview.net/forum?id=sK2aWU7X9b8}
24 | }
25 | ```
26 |
27 |
28 |
29 | ## Install Python Environment
30 |
31 | ### Roboaware
32 |
33 | 1. Run `conda env create -f environment.yml`, then activate this conda environment.
34 | 2. Clone the [`d4rl`](https://github.com/voyager1998/d4rl.git)
35 | 3. cd into the d4rl repo, run `pip install -e .`
36 |
37 | ### ROBEL
38 |
39 | WARNING: Do not install robel package inside `Roboaware` conda env, it's incompatible.
40 |
41 | 1. Clone [ROBEL](https://github.com/voyager1998/robel.git) repo into another folder.
42 | 2. Run `pip install -e .` inside robel.
43 | 3. For the rest, follow exactly the [instructions](https://github.com/google-research/robel). May need to download MuJoCo 2.0 if not installed, but it's fine to have multiple versions of MoJoCo.
44 | 4. Use Dynamixel Wizard to figure out the port etc of the motors.
45 | 5. After modifying ROBEL code, reinstall robel by running
46 |
47 | ```bash
48 | pip uninstall robel
49 | pip install -e .
50 | ```
51 |
52 | ## Trouble Shooting
53 |
54 | If the error `Failed to initialize OpenGL` appears, refer to [link](https://github.com/openai/mujoco-py/issues/187), and try `unset LD_PRELOAD`.
55 |
56 | If the error `GLEW initialization error: Missing GL version` appears, refer to [link](https://github.com/openai/mujoco-py/issues/408), and try
57 |
58 | ```bash
59 | export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so
60 | ```
61 |
--------------------------------------------------------------------------------
/environment.yml:
--------------------------------------------------------------------------------
1 | name: roboaware
2 | channels:
3 | - conda-forge
4 | - anaconda
5 | - defaults
6 | dependencies:
7 | - _libgcc_mutex=0.1
8 | - _openmp_mutex=4.5
9 | - _pytorch_select=0.1
10 | - _tflow_select=2.3.0
11 | - absl-py=0.13.0
12 | - aiohttp=3.8.1
13 | - aiosignal=1.2.0
14 | - astor=0.8.1
15 | - async-timeout=4.0.1
16 | - asynctest=0.13.0
17 | - attrs=21.2.0
18 | - autopep8=1.5.5
19 | - blas=1.0
20 | - blinker=1.4
21 | - blosc=1.21.0
22 | - bottleneck=1.3.2
23 | - brotli=1.0.9
24 | - brotlipy=0.7.0
25 | - brunsli=0.1
26 | - bzip2=1.0.8
27 | - c-ares=1.17.1
28 | - ca-certificates=2020.10.14
29 | - cachetools=4.2.2
30 | - cairo=1.16.0
31 | - catkin_pkg=0.4.23
32 | - certifi=2020.6.20
33 | - cfitsio=3.470
34 | - charls=2.2.0
35 | - charset-normalizer=2.0.4
36 | - click=8.0.3
37 | - colorlog=4.4.0
38 | - cryptography=3.4.8
39 | - cython=0.29.21
40 | - cytoolz=0.11.0
41 | - dask-core=2021.10.0
42 | - dataclasses=0.8
43 | - distro=1.5.0
44 | - docutils=0.18.1
45 | - ffmpeg=4.0
46 | - fontconfig=2.13.1
47 | - fonttools=4.25.0
48 | - freeglut=3.0.0
49 | - freetype=2.11.0
50 | - frozenlist=1.2.0
51 | - fsspec=2021.10.1
52 | - future=0.18.2
53 | - gast=0.2.2
54 | - giflib=5.2.1
55 | - glib=2.69.1
56 | - google-auth=1.33.0
57 | - google-auth-oauthlib=0.4.4
58 | - google-pasta=0.2.0
59 | - graphite2=1.3.14
60 | - grpcio=1.42.0
61 | - h5py=2.8.0
62 | - harfbuzz=1.8.8
63 | - hdf5=1.10.2
64 | - icu=58.2
65 | - idna=3.3
66 | - imagecodecs=2021.8.26
67 | - imageio=2.9.0
68 | - intel-openmp=2019.4
69 | - jasper=2.0.14
70 | - joblib=1.1.0
71 | - jpeg=9d
72 | - jxrlib=1.1
73 | - keras-applications=1.0.8
74 | - keras-preprocessing=1.1.2
75 | - krb5=1.19.2
76 | - lcms2=2.12
77 | - ld_impl_linux-64=2.35.1
78 | - lerc=3.0
79 | - libaec=1.0.4
80 | - libcurl=7.78.0
81 | - libdeflate=1.8
82 | - libedit=3.1.20210910
83 | - libev=4.33
84 | - libffi=3.3
85 | - libgcc-ng=9.3.0
86 | - libgfortran-ng=7.5.0
87 | - libgfortran4=7.5.0
88 | - libglu=9.0.0
89 | - libgomp=9.3.0
90 | - libmklml=2019.0.5
91 | - libnghttp2=1.46.0
92 | - libopencv=3.4.2
93 | - libopus=1.3.1
94 | - libpng=1.6.37
95 | - libprotobuf=3.17.2
96 | - libssh2=1.9.0
97 | - libstdcxx-ng=9.3.0
98 | - libtiff=4.2.0
99 | - libuuid=1.0.3
100 | - libvpx=1.7.0
101 | - libwebp=1.2.0
102 | - libwebp-base=1.2.0
103 | - libxcb=1.14
104 | - libxml2=2.9.12
105 | - libzopfli=1.0.3
106 | - locket=0.2.1
107 | - lz4-c=1.9.3
108 | - markdown=3.3.4
109 | - matplotlib-base=3.5.0
110 | - mkl=2020.2
111 | - mkl-service=2.3.0
112 | - mkl_fft=1.3.0
113 | - mkl_random=1.1.1
114 | - multidict=5.1.0
115 | - munkres=1.1.4
116 | - ncurses=6.3
117 | - networkx=2.6.3
118 | - ninja=1.10.2
119 | - numexpr=2.7.3
120 | - numpy-base=1.19.2
121 | - oauthlib=3.1.1
122 | - olefile=0.46
123 | - opencv=3.4.2
124 | - openjpeg=2.4.0
125 | - openssl=1.1.1l
126 | - opt_einsum=3.3.0
127 | - packaging=21.3
128 | - pandas=1.3.4
129 | - partd=1.2.0
130 | - pcre=8.45
131 | - pip=21.2.2
132 | - pixman=0.40.0
133 | - py-opencv=3.4.2
134 | - pyasn1=0.4.8
135 | - pyasn1-modules=0.2.8
136 | - pycodestyle=2.8.0
137 | - pycparser=2.21
138 | - pyjwt=2.1.0
139 | - pyopenssl=21.0.0
140 | - pyparsing=3.0.4
141 | - pysocks=1.7.1
142 | - python=3.7.9
143 | - python-dateutil=2.8.2
144 | - python_abi=3.7
145 | - pytorch=1.7.1
146 | - pytz=2021.3
147 | - pywavelets=1.1.1
148 | - quaternion=2020.9.5.14.42.2
149 | - readline=8.1
150 | - requests-oauthlib=1.3.0
151 | - rospkg=1.2.10
152 | - rsa=4.7.2
153 | - scikit-image=0.17.2
154 | - scikit-learn=1.0.1
155 | - scipy=1.6.1
156 | - setuptools=58.0.4
157 | - six=1.16.0
158 | - snappy=1.1.8
159 | - sqlite=3.36.0
160 | - stable-baselines3=1.1.0
161 | - tensorboard=2.4.0
162 | - tensorboard-plugin-wit=1.6.0
163 | - tensorflow=2.1.0
164 | - tensorflow-base=2.1.0
165 | - tensorflow-estimator=2.6.0
166 | - termcolor=1.1.0
167 | - threadpoolctl=2.2.0
168 | - tifffile=2021.7.2
169 | - tk=8.6.11
170 | - toml=0.10.2
171 | - toolz=0.11.2
172 | - torchvision=0.8.2
173 | - typing-extensions=3.10.0.2
174 | - typing_extensions=3.10.0.2
175 | - werkzeug=2.0.2
176 | - wheel=0.37.0
177 | - wrapt=1.13.3
178 | - xorg-fixesproto=5.0
179 | - xorg-kbproto=1.0.7
180 | - xorg-libx11=1.7.2
181 | - xorg-libxcursor=1.2.0
182 | - xorg-libxext=1.3.4
183 | - xorg-libxfixes=5.0.3
184 | - xorg-libxinerama=1.1.4
185 | - xorg-libxrandr=1.5.2
186 | - xorg-libxrender=0.9.10
187 | - xorg-randrproto=1.5.0
188 | - xorg-renderproto=0.11.1
189 | - xorg-xextproto=7.3.0
190 | - xorg-xproto=7.0.31
191 | - xz=5.2.5
192 | - yaml=0.2.5
193 | - yapf=0.31.0
194 | - yarl=1.6.3
195 | - zfp=0.5.5
196 | - zlib=1.2.11
197 | - zstd=1.4.9
198 | - pip:
199 | - appnope==0.1.0
200 | - backcall==0.2.0
201 | - cffi==1.14.2
202 | - cloudpickle==1.3.0
203 | - configparser==5.0.1
204 | - cycler==0.10.0
205 | - docker-pycreds==0.4.0
206 | - fasteners==0.15
207 | - flake8==3.8.3
208 | - gitdb==4.0.5
209 | - gitpython==3.1.11
210 | - glfw==2.3.0
211 | - gym==0.17.2
212 | - importlib-metadata==2.0.0
213 | - ipdb==0.13.3
214 | - ipython==7.18.1
215 | - ipython-genutils==0.2.0
216 | - jedi==0.17.2
217 | - kiwisolver==1.2.0
218 | - matplotlib==3.3.1
219 | - mccabe==0.6.1
220 | - monotonic==1.5
221 | - mujoco-py<2.2,>=2.1
222 | - numpy==1.19.1
223 | - opencv-contrib-python==4.5.1.48
224 | - parso==0.7.1
225 | - pathtools==0.1.2
226 | - pexpect==4.8.0
227 | - pickleshare==0.7.5
228 | - pillow==7.2.0
229 | - promise==2.3
230 | - prompt-toolkit==3.0.7
231 | - protobuf==3.13.0
232 | - psutil==5.7.3
233 | - ptyprocess==0.6.0
234 | - pupil-apriltags==1.0.4
235 | - pyflakes==2.2.0
236 | - pyglet==1.5.0
237 | - pygments==2.6.1
238 | - pyquaternion==0.9.9
239 | - pyyaml==5.3.1
240 | - requests==2.24.0
241 | - sentry-sdk==0.19.2
242 | - shortuuid==1.0.1
243 | - smmap==3.0.4
244 | - subprocess32==3.5.4
245 | - torch==1.6.0
246 | - tqdm==4.48.2
247 | - traitlets==4.3.3
248 | - urllib3
249 | - wandb==0.10.10
250 | - watchdog==0.10.3
251 | - wcwidth==0.2.5
252 | - zipp==3.4.0
253 |
--------------------------------------------------------------------------------
/readme_imgs/concept_figure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/readme_imgs/concept_figure.png
--------------------------------------------------------------------------------
/readme_imgs/poster.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/readme_imgs/poster.mp4
--------------------------------------------------------------------------------
/src/config/__init__.py:
--------------------------------------------------------------------------------
1 | import argparse
2 | from argparse import ArgumentParser
3 |
4 |
5 | def str2bool(v):
6 | return v.lower() == "true"
7 |
8 |
9 | def str2intlist(value):
10 | if not value:
11 | return value
12 | else:
13 | return [int(num) for num in value.split(",")]
14 |
15 |
16 | def str2list(value):
17 | if not value:
18 | return value
19 | else:
20 | return [num for num in value.split(",")]
21 |
22 |
23 | def create_parser():
24 | """
25 | Creates the argparser. Use this to add additional arguments
26 | to the parser later.
27 | """
28 | parser = argparse.ArgumentParser(
29 | "Robot Aware Cost",
30 | formatter_class=argparse.ArgumentDefaultsHelpFormatter,
31 | )
32 | parser.add_argument("--jobname", type=str, default=None)
33 | parser.add_argument("--log_dir", type=str, default="logs")
34 | parser.add_argument("--wandb", type=str2bool, default=False)
35 | parser.add_argument("--wandb_entity", type=str, default="pal")
36 | parser.add_argument("--wandb_project", type=str, default="roboaware")
37 | parser.add_argument("--wandb_group", type=str, default=None)
38 | parser.add_argument("--wandb_job_type", type=str, default=None)
39 |
40 | parser.add_argument("--visualize_mode", type=str2bool, default=False)
41 |
42 | add_method_arguments(parser)
43 | add_ensemble_arguments(parser)
44 |
45 | return parser
46 |
47 |
48 | def add_method_arguments(parser: ArgumentParser):
49 | # method arguments
50 | parser.add_argument(
51 | "--reward_type",
52 | type=str,
53 | default="gt",
54 | choices=[
55 | "gt", "success_classifier", "weighted", "dense", "inpaint",
56 | "sparse"
57 | "blackrobot", "inpaint-blur", "eef_inpaint", "dontcare"
58 | ],
59 | )
60 | # for use with inpaint blur
61 | parser.add_argument("--most_recent_background",
62 | type=str2bool,
63 | default=False)
64 | # inpaint-blur
65 | parser.add_argument("--blur_sigma", type=float, default=10)
66 | parser.add_argument("--unblur_cost_scale", type=float, default=3)
67 | # switch at step L - unblur_timestep
68 | parser.add_argument("--unblur_timestep", type=float, default=1)
69 |
70 | # control algorithm
71 | parser.add_argument(
72 | "--mbrl_algo",
73 | type=str,
74 | default="cem",
75 | choices=["cem"],
76 | )
77 |
78 | # training
79 | parser.add_argument("--gpu", type=int, default=None)
80 | parser.add_argument("--seed", type=int, default=0)
81 | parser.add_argument("--num_episodes", type=int, default=100)
82 | parser.add_argument("--record_trajectory", type=str2bool, default=False)
83 | parser.add_argument("--record_trajectory_interval", type=int, default=5)
84 | parser.add_argument("--record_video_interval", type=int, default=1)
85 |
86 | # environment
87 | parser.add_argument("--env", type=str, default="FetchPush")
88 | args, unparsed = parser.parse_known_args()
89 |
90 | add_prediction_arguments(parser)
91 | add_dataset_arguments(parser)
92 | add_cost_arguments(parser)
93 |
94 | if args.mbrl_algo == "cem":
95 | add_cem_arguments(parser)
96 |
97 | # env specific args
98 | if args.env == "FetchPush":
99 | add_fetch_push_arguments(parser)
100 |
101 | return parser
102 |
103 |
104 | # Env Hyperparameters
105 | def add_fetch_push_arguments(parser: ArgumentParser):
106 | # override prediction dimension stuff
107 | parser.set_defaults(robot_dim=6, robot_enc_dim=6)
108 | parser.add_argument("--img_dim", type=int, default=64)
109 | parser.add_argument(
110 | "--camera_name",
111 | type=str,
112 | default="external_camera_0",
113 | choices=[
114 | "head_camera_rgb", "gripper_camera_rgb", "lidar",
115 | "external_camera_0"
116 | ],
117 | )
118 | parser.add_argument("--multiview", type=str2bool, default=False)
119 | parser.add_argument("--camera_ids", type=str2intlist, default=[0, 4])
120 | parser.add_argument("--pixels_ob", type=str2bool, default=True)
121 | parser.add_argument("--norobot_pixels_ob", type=str2bool, default=False)
122 | parser.add_argument("--robot_mask_with_obj", type=str2bool, default=False)
123 | parser.add_argument("--inpaint_eef", type=str2bool, default=True)
124 | parser.add_argument("--depth_ob", type=str2bool, default=False)
125 | parser.add_argument("--object_dist_threshold", type=float, default=0.01)
126 | parser.add_argument("--gripper_dist_threshold", type=float, default=0.025)
127 | parser.add_argument("--push_dist", type=float, default=0.2)
128 | parser.add_argument("--max_episode_length", type=int, default=10)
129 | parser.add_argument(
130 | "--robot_goal_distribution",
131 | type=str,
132 | default="random",
133 | choices=["random", "behind_block"],
134 | )
135 | parser.add_argument("--large_block", type=str2bool, default=False)
136 | parser.add_argument("--red_robot", type=str2bool, default=False)
137 | parser.add_argument("--invisible_demo", type=str2bool, default=False)
138 | parser.add_argument("--demo_dir", type=str, default="demos/fetch_push")
139 |
140 |
141 | def add_prediction_arguments(parser):
142 | parser.add_argument("--lr",
143 | default=0.0003,
144 | type=float,
145 | help="learning rate")
146 | parser.add_argument("--beta1",
147 | default=0.9,
148 | type=float,
149 | help="momentum term for adam")
150 | parser.add_argument("--batch_size",
151 | default=100,
152 | type=int,
153 | help="batch size")
154 | parser.add_argument("--test_batch_size",
155 | default=16,
156 | type=int,
157 | help="test batch size")
158 | parser.add_argument("--optimizer",
159 | default="adam",
160 | help="optimizer to train with")
161 | parser.add_argument("--niter",
162 | type=int,
163 | default=300,
164 | help="number of epochs to train for")
165 | parser.add_argument("--epoch_size",
166 | type=int,
167 | default=600,
168 | help="epoch size")
169 | parser.add_argument("--channels", default=3, type=int)
170 | parser.add_argument("--dataset",
171 | default="smmnist",
172 | help="dataset to train with")
173 | parser.add_argument("--n_past",
174 | type=int,
175 | default=1,
176 | help="number of frames to condition on")
177 | parser.add_argument(
178 | "--n_future",
179 | type=int,
180 | default=9,
181 | help="number of frames to predict during training",
182 | )
183 | parser.add_argument("--n_eval",
184 | type=int,
185 | default=10,
186 | help="number of frames to predict during eval")
187 | parser.add_argument("--checkpoint_interval", type=int, default=5)
188 | parser.add_argument("--eval_interval", type=int, default=5)
189 | parser.add_argument("--rnn_size",
190 | type=int,
191 | default=256,
192 | help="dimensionality of hidden layer")
193 | parser.add_argument("--prior_rnn_layers",
194 | type=int,
195 | default=2,
196 | help="number of layers")
197 | parser.add_argument("--posterior_rnn_layers",
198 | type=int,
199 | default=2,
200 | help="number of layers")
201 | parser.add_argument("--predictor_rnn_layers",
202 | type=int,
203 | default=2,
204 | help="number of layers")
205 | parser.add_argument("--z_dim",
206 | type=int,
207 | default=10,
208 | help="dimensionality of z_t")
209 | parser.add_argument(
210 | "--g_dim",
211 | type=int,
212 | default=128,
213 | help="dimensionality of encoder output vector and decoder input vector",
214 | )
215 | parser.add_argument("--action_dim", type=int, default=2)
216 | parser.add_argument("--action_enc_dim", type=int, default=2)
217 | parser.add_argument("--robot_dim", type=int, default=6)
218 | parser.add_argument("--robot_enc_dim", type=int, default=6)
219 | parser.add_argument("--robot_joint_dim", type=int, default=7)
220 |
221 | parser.add_argument("--beta",
222 | type=float,
223 | default=0.0001,
224 | help="weighting on KL to prior")
225 |
226 | parser.add_argument(
227 | "--last_frame_skip",
228 | type=str2bool,
229 | default=False,
230 | help=
231 | "if true, skip connections go between frame t and frame t+t rather than last ground truth frame",
232 | )
233 |
234 | parser.add_argument("--model",
235 | default="svg",
236 | choices=["svg", "det", "copy"])
237 | parser.add_argument("--model_use_mask", type=str2bool, default=True)
238 | parser.add_argument("--model_use_robot_state", type=str2bool, default=True)
239 | parser.add_argument("--reconstruction_loss",
240 | default="mse",
241 | choices=["mse", "l1", "dontcare_mse"])
242 | parser.add_argument("--scheduled_sampling", type=str2bool, default=False)
243 | parser.add_argument("--robot_pixel_weight",
244 | type=float,
245 | default=0,
246 | help="weighting on robot pixels")
247 |
248 | parser.add_argument("--learned_robot_model", type=str2bool, default=False)
249 | parser.add_argument("--robot_model_ckpt", type=str, default=None)
250 | parser.add_argument("--use_xy_channel", type=str2bool, default=False)
251 | parser.add_argument("--load_checkpoint", type=str, default=None)
252 |
253 |
254 | def add_dataset_arguments(parser):
255 | parser.add_argument("--data_threads",
256 | type=int,
257 | default=5,
258 | help="number of data loading threads")
259 | parser.add_argument("--data_root",
260 | default="data",
261 | help="root directory for data")
262 | parser.add_argument("--train_val_split", type=float, default=0.8)
263 | # data collection policy arguments
264 | parser.add_argument("--temporal_beta", type=float, default=1)
265 | parser.add_argument("--demo_length", type=int, default=12)
266 | parser.add_argument("--action_noise", type=float, default=0)
267 | parser.add_argument(
268 | "--video_type",
269 | default="object_inpaint_demo",
270 | choices=["object_inpaint_demo", "robot_demo", "object_only_demo"],
271 | )
272 | # robonet video prediction dataset arguments
273 | parser.add_argument(
274 | "--video_length",
275 | type=int,
276 | default=31,
277 | help="max length of the video, used for evaluation dataloader")
278 | parser.add_argument("--impute_autograsp_action",
279 | type=str2bool,
280 | default=True)
281 | parser.add_argument("--preload_ram", type=str2bool, default=False)
282 | parser.add_argument("--training_regime",
283 | type=str,
284 | choices=[
285 | "multirobot", "singlerobot", "finetune",
286 | "train_sawyer_multiview", "finetune_sawyer_view",
287 | "finetune_widowx"
288 | ],
289 | default="multirobot")
290 | parser.add_argument(
291 | "--preprocess_action",
292 | type=str,
293 | choices=["raw", "camera_raw", "state_infer", "camera_state_infer"],
294 | default="raw")
295 | parser.add_argument("--img_augmentation", type=str2bool, default=False)
296 | parser.add_argument("--color_jitter_range", type=float, default=0.1)
297 | parser.add_argument("--random_crop_size", type=int, default=59)
298 | parser.add_argument("--dropout", type=float, default=None)
299 | parser.add_argument("--world_error_dict", type=str, default=None)
300 | parser.add_argument("--finetune_num_train", type=int, default=400)
301 | parser.add_argument("--finetune_num_test", type=int, default=100)
302 | parser.add_argument("--num_train", type=int, default=400)
303 | parser.add_argument("--num_test", type=int, default=100)
304 |
305 |
306 | # CEM Hyperparameters
307 | def add_cem_arguments(parser):
308 | parser.add_argument("--horizon", type=int, default=3)
309 | parser.add_argument("--opt_iter", type=int, default=10)
310 | parser.add_argument("--action_candidates", type=int, default=30)
311 | parser.add_argument("--topk", type=int, default=5)
312 | parser.add_argument("--replan_every", type=int, default=1)
313 | parser.add_argument("--dynamics_model_ckpt", type=str, default=None)
314 | parser.add_argument("--candidates_batch_size", type=int, default=200)
315 | parser.add_argument("--use_env_dynamics", type=str2bool, default=False)
316 | parser.add_argument("--debug_trajectory_path", type=str, default=None)
317 | parser.add_argument("--debug_cem", type=str2bool, default=False)
318 | parser.add_argument("--object_demo_dir", type=str, default=None)
319 | parser.add_argument("--subgoal_start", type=int, default=0)
320 | parser.add_argument("--sequential_subgoal", type=str2bool, default=True)
321 | parser.add_argument("--demo_cost", type=str2bool, default=False)
322 | parser.add_argument("--demo_timescale", type=int, default=1)
323 | parser.add_argument("--action_repeat", type=int, default=1)
324 | parser.add_argument(
325 | "--demo_type",
326 | default="object_only_demo",
327 | choices=["object_inpaint_demo", "object_only_demo", "robot_demo"],
328 | )
329 | parser.add_argument("--cem_init_std", type=float, default=1)
330 | parser.add_argument("--sparse_cost", type=str2bool, default=False)
331 |
332 |
333 | # Cost Fn Hyperparameters
334 |
335 |
336 | def add_cost_arguments(parser):
337 | # cost thresholds for determining goal success
338 | parser.add_argument("--world_cost_success", type=float, default=4000)
339 | parser.add_argument("--robot_cost_success", type=float, default=0.01)
340 | # weight of the costs
341 | parser.add_argument("--robot_cost_weight", type=float, default=0)
342 | parser.add_argument("--world_cost_weight", type=float, default=1)
343 | # checks if pixel diff > threshold before counting it
344 | parser.add_argument("--img_cost_threshold", type=float, default=None)
345 | # only used by img don't care cost, divide by number of world pixels
346 | parser.add_argument("--img_cost_world_norm", type=str2bool, default=True)
347 |
348 |
349 | def add_ensemble_arguments(parser):
350 | parser.add_argument("--load_traj_length", type=int, default=10)
351 | parser.add_argument("--num_ensembles", type=int, default=10)
352 | parser.add_argument("--train_data_per_ensemble", type=int, default=500)
353 |
354 |
355 | def argparser():
356 | """ Directly parses the arguments. """
357 | parser = create_parser()
358 | args, unparsed = parser.parse_known_args()
359 | assert len(unparsed) == 0, unparsed
360 | return args, unparsed
361 |
--------------------------------------------------------------------------------
/src/door_lock_verifier.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 | from stable_baselines3 import SAC
4 |
5 | from src.env.hand_manipulation_suite.door_v0 import DoorEnvV0
6 | from src.env.hand_manipulation_suite.door_lock_verify_adroit_simple import DoorLockVerifyEnv
7 |
8 | if __name__ == "__main__":
9 | from src.config import argparser
10 |
11 | config, _ = argparser()
12 | config.jobname = "door_lock_verifier"
13 | checkpoint_path = os.path.join("checkpoints", config.jobname)
14 | os.makedirs(checkpoint_path, exist_ok=True)
15 |
16 | env = DoorLockVerifyEnv()
17 | env.reset()
18 |
19 | model = SAC("MlpPolicy", env, verbose=1)
20 |
21 | # Training/Continue training
22 | total_timesteps = 2000000
23 | save_per_timesteps = 10000
24 | timestep = []
25 | success_rates = []
26 | rewards = []
27 | continue_training = 2000000
28 | for i in range(int(total_timesteps / save_per_timesteps)):
29 | print("======================================")
30 | start = time.time()
31 | model.learn(total_timesteps=save_per_timesteps)
32 |
33 | # Save model
34 | model.save(checkpoint_path + "/mfrl_sc_" +
35 | str((i + 1) * save_per_timesteps + continue_training))
36 | print("Model saved after",
37 | (i + 1) * save_per_timesteps + continue_training, "timesteps")
38 |
--------------------------------------------------------------------------------
/src/door_locker.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 | from stable_baselines3 import SAC
4 |
5 | from src.env.hand_manipulation_suite.door_v0 import DoorEnvV0
6 | from src.env.hand_manipulation_suite.door_lock_adroit_simple import DoorLockEnvAdroitSimple
7 |
8 | if __name__ == "__main__":
9 | from src.config import argparser
10 |
11 | config, _ = argparser()
12 | config.jobname = "door_locker"
13 | checkpoint_path = os.path.join("checkpoints", config.jobname)
14 | os.makedirs(checkpoint_path, exist_ok=True)
15 |
16 | env = DoorLockEnvAdroitSimple()
17 | env.reset()
18 |
19 | model = SAC(
20 | "MlpPolicy",
21 | env,
22 | verbose=1,
23 | )
24 |
25 | # Training/Continue training
26 | total_timesteps = 4000000
27 | save_per_timesteps = 10000
28 | timestep = []
29 | success_rates = []
30 | door_closed_rates = []
31 | rewards = []
32 | continue_training = 0
33 |
34 | for i in range(int(total_timesteps / save_per_timesteps)):
35 | print("======================================")
36 | start = time.time()
37 | model.learn(total_timesteps=save_per_timesteps)
38 |
39 | # Save model
40 | model.save(checkpoint_path + "/mfrl_sc_" +
41 | str((i + 1) * save_per_timesteps + continue_training))
42 | print("Model saved after",
43 | (i + 1) * save_per_timesteps + continue_training, "timesteps")
44 |
--------------------------------------------------------------------------------
/src/env/__init__.py:
--------------------------------------------------------------------------------
1 | # from src.env.robotics.fetch_env import FetchEnv
2 | # from src.env.robotics.fetch_push import FetchPushEnv
3 | def get_env(name):
4 | if name == "FetchPush":
5 | from src.env.robotics.fetch_push import FetchPushEnv
6 |
7 | return FetchPushEnv
8 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/Adroit_hand.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/Adroit_hand_withOverlay.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/README.md:
--------------------------------------------------------------------------------
1 | # Adroit Manipulation Platform
2 |
3 | Adroit manipulation platform is reconfigurable, tendon-driven, pneumatically-actuated platform designed and developed by [Vikash Kumar](https://vikashplus.github.io/) during this Ph.D. ([Thesis: Manipulators and Manipulation in high dimensional spaces](https://digital.lib.washington.edu/researchworks/handle/1773/38104)) to study dynamic dexterous manipulation. Adroit is comprised of the [Shadow Hand](https://www.shadowrobot.com/products/dexterous-hand/) skeleton (developed by [Shadow Robot company](https://www.shadowrobot.com/)) and a custom arm, and is powered by a custom actuation sysem. This custom actuation system allows Adroit to move the ShadowHand skeleton faster than a human hand (70 msec limit-to-limit movement, 30 msec overall reflex latency), generate sufficient forces (40 N at each finger tendon, 125N at each wrist tendon), and achieve high compliance on the mechanism level (6 grams of external force at the fingertip displaces the finger when the system is powered.) This combination of speed, force, and compliance is a prerequisite for dexterous manipulation, yet it has never before been achieved with a tendon-driven system, let alone a system with 24 degrees of freedom and 40 tendons.
4 |
5 | ## Mujoco Model
6 | Adroit is a 28 degree of freedom system which consists of a 24 degrees of freedom **ShadowHand** and a 4 degree of freedom arm. This repository contains the Mujoco Models of the system developed with extreme care and great attention to the details.
7 |
8 |
9 | ## In Projects
10 | Adroit has been used in a wide variety of project. A small list is appended below. Details of these projects can be found [here](https://vikashplus.github.io/).
11 | [](https://vikashplus.github.io/)
12 | ## In News and Media
13 | Adroit has found quite some attention in the world media. Details can be found [here](https://vikashplus.github.io/news.html)
14 |
15 | [](https://vikashplus.github.io/news.html)
16 |
17 |
18 | ## Citation
19 | If the contents of this repo helped you, please consider citing
20 |
21 | ```
22 | @phdthesis{Kumar2016thesis,
23 | title = {Manipulators and Manipulation in high dimensional spaces},
24 | school = {University of Washington, Seattle},
25 | author = {Kumar, Vikash},
26 | year = {2016},
27 | url = {https://digital.lib.washington.edu/researchworks/handle/1773/38104}
28 | }
29 | ```
30 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/gallery/news.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/gallery/news.JPG
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/gallery/projects.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/gallery/projects.JPG
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/assets.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
30 |
31 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/chain.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/chain1.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/joint_position_actuation.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/F1.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/F1.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/F2.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/F2.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/F3.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/F3.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/TH1_z.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/TH1_z.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/TH2_z.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/TH2_z.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/TH3_z.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/TH3_z.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/arm_base.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/arm_base.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/arm_trunk.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/arm_trunk.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/arm_trunk_asmbly.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/arm_trunk_asmbly.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/distal_ellipsoid.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/distal_ellipsoid.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/elbow_flex.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/elbow_flex.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/elbow_rotate_motor.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/elbow_rotate_motor.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/elbow_rotate_muscle.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/elbow_rotate_muscle.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_Cy_PlateAsmbly(muscle_cone).stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_Cy_PlateAsmbly(muscle_cone).stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_Cy_PlateAsmbly.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_Cy_PlateAsmbly.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_PlateAsmbly.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_PlateAsmbly.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_electric.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_electric.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_electric_cvx.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_electric_cvx.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_muscle.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_muscle.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_simple.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_simple.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_simple_cvx.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_simple_cvx.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_weight.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/forearm_weight.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/hand_base_link.STL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/hand_base_link.STL
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_0.STL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_0.STL
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_1.STL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_1.STL
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_2.STL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_2.STL
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_3.STL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/hook_3.STL
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/knuckle.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/knuckle.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/lfmetacarpal.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/lfmetacarpal.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/palm.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/palm.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/upper_arm.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/upper_arm.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/upper_arm_asmbl_shoulder.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/upper_arm_asmbl_shoulder.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/upper_arm_ass.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/upper_arm_ass.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/meshes/wrist.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/Adroit/resources/meshes/wrist.stl
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/Adroit/resources/tendon_torque_actuation.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/__init__.py
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/DAPG_Adroit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/DAPG_assets_hook.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/DAPG_door.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/DAPG_hammer.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/DAPG_pen.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/DAPG_relocate.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/door_xknob_adroit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/door_xknob_adroit_extrageom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/door_xknob_hook.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/assets/tasks.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/penn-pal-lab/interactive_reward_functions/645618a29c2e3f266794e15c6f27231c20fd01b6/src/env/hand_manipulation_suite/assets/tasks.jpg
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/door_lock_adroit_simple.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | from gym import utils
3 | from gym import spaces
4 | from mjrl.envs import mujoco_env
5 | from mujoco_py import MjViewer
6 | from d4rl import offline_env
7 | import os
8 | import time
9 | from stable_baselines3 import SAC
10 |
11 |
12 | def get_aliased_angle(pose):
13 | aliased_pose = pose
14 | while aliased_pose > 1.57 / 2.0:
15 | aliased_pose -= 1.57
16 | while aliased_pose < -1.57 / 2.0:
17 | aliased_pose += 1.57
18 | return aliased_pose
19 |
20 |
21 | def get_aliased_angle_ndarray(poses):
22 | # change the poses to aliased poses in place
23 | while True:
24 | over_poses = poses > 1.57 / 2.0
25 | if not np.any(over_poses):
26 | break
27 | else:
28 | poses[over_poses] -= 1.57
29 | while True:
30 | under_poses = poses < -1.57 / 2.0
31 | if not np.any(under_poses):
32 | break
33 | else:
34 | poses[under_poses] += 1.57
35 |
36 |
37 | class DoorLockEnvAdroitSimple(mujoco_env.MujocoEnv, utils.EzPickle,
38 | offline_env.OfflineEnv):
39 | def __init__(self, **kwargs):
40 | offline_env.OfflineEnv.__init__(self, **kwargs)
41 | self.door_hinge_did = 0
42 | self.door_bid = 0
43 | self.grasp_sid = 0
44 | self.handle_sid = 0
45 | self.knob_sid = 0
46 | self.extra_knob_sid = 0
47 | self.action_dim_simple = 5
48 | # Override action_space to -1, 1
49 | self.action_space = spaces.Box(low=-1.0,
50 | high=1.0,
51 | dtype=np.float32,
52 | shape=(self.action_dim_simple, ))
53 |
54 | # Use a sequence of states as observation
55 | self.obs_horizon = 1
56 | self.latch_obs_list = []
57 | self.use_whole_state_obs = False
58 |
59 | self.t = 0
60 | self.max_traj_length = 100
61 |
62 | curr_dir = os.path.dirname(os.path.abspath(__file__))
63 | self.sim = mujoco_env.get_sim(
64 | curr_dir + '/assets/door_xknob_adroit_extrageom.xml')
65 | self.data = self.sim.data
66 | self.model = self.sim.model
67 |
68 | self.frame_skip = 5
69 | self.metadata = {
70 | 'render.modes': ['human', 'rgb_array'],
71 | 'video.frames_per_second': int(np.round(1.0 / self.dt))
72 | }
73 | self.mujoco_render_frames = False
74 |
75 | self.init_qpos = self.data.qpos.ravel().copy()
76 | self.init_qvel = self.data.qvel.ravel().copy()
77 | observation = self.get_obs(hist_len=self.obs_horizon)
78 | self.obs_dim = np.sum([
79 | o.size for o in observation
80 | ]) if type(observation) is tuple else observation.size
81 |
82 | high = np.inf * np.ones(self.obs_dim)
83 | low = -high
84 | self.observation_space = spaces.Box(low, high, dtype=np.float32)
85 |
86 | self.seed()
87 |
88 | # change actuator sensitivity
89 | self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id(
90 | 'A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0') +
91 | 1, :3] = np.array([10, 0, 0])
92 | self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id(
93 | 'A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0') +
94 | 1, :3] = np.array([1, 0, 0])
95 | self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id(
96 | 'A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0') +
97 | 1, :3] = np.array([0, -10, 0])
98 | self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id(
99 | 'A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0') +
100 | 1, :3] = np.array([0, -1, 0])
101 |
102 | utils.EzPickle.__init__(self)
103 | self.act_mid = np.mean(self.model.actuator_ctrlrange, axis=1)
104 | self.act_rng = 0.5 * (self.model.actuator_ctrlrange[:, 1] -
105 | self.model.actuator_ctrlrange[:, 0])
106 | self.door_hinge_did = self.model.jnt_dofadr[self.model.joint_name2id(
107 | 'door_hinge')]
108 | self.grasp_sid = self.model.site_name2id('S_grasp')
109 | self.handle_sid = self.model.site_name2id('S_handle')
110 | self.door_bid = self.model.body_name2id('frame')
111 | self.knob_sid = self.model.site_name2id('knob_hinge')
112 | self.extra_knob_sid = self.model.site_name2id('extra_knob')
113 |
114 | self.use_latch_pose_reward = False
115 | self.use_dense_reward = True
116 | self.use_engineered_reward = False
117 | self.use_verification_reward = False
118 | # TODO(for users): train an IRF policy first and put the checkpoint path below
119 | self.verifier_checkpoint_path = "checkpoints/door_lock_verifier"
120 | if self.use_verification_reward:
121 | self.pi_v = SAC.load(self.verifier_checkpoint_path)
122 | self.latch_random_reset = True
123 | self.terminate_early = False
124 |
125 | def step(self, a):
126 | a = np.clip(a, -1.0, 1.0)
127 | whole_action = np.zeros(28)
128 | whole_action[:4] = np.copy(a[:4])
129 | whole_action[4:] = np.ones(24) * a[4]
130 |
131 | try:
132 | whole_action = self.act_mid + whole_action * \
133 | self.act_rng # mean center and scale
134 | except:
135 | whole_action = whole_action # only for the initialization phase
136 | self.do_simulation(whole_action, self.frame_skip)
137 |
138 | done = False
139 | if self.t >= self.max_traj_length:
140 | done = True
141 |
142 | ob = self.get_obs(hist_len=self.obs_horizon)
143 | door_pose = self.data.qpos[self.door_hinge_did]
144 |
145 | reward = 0.0
146 | if self.use_dense_reward:
147 | palm_pos = self.data.site_xpos[self.grasp_sid].ravel()
148 | knob_pos = self.data.site_xpos[self.knob_sid].ravel()
149 | # close door
150 | reward += -0.1 * (door_pose - 0.0)**2
151 | reward += -1.0 * np.linalg.norm(palm_pos - knob_pos)
152 |
153 | door_closed = (door_pose <= 0.05)
154 | latch_pose = self.data.get_joint_qpos("latch")
155 | goal_achieved = True if door_closed and -0.7 < latch_pose < 0.7 else False
156 | if self.terminate_early and goal_achieved:
157 | done = True
158 | if self.use_latch_pose_reward:
159 | reward += 3.0 * door_closed
160 | reward += 10.0 * goal_achieved
161 | else:
162 | reward += 3.0 * door_closed
163 |
164 | if self.use_verification_reward and done:
165 | is_door_locked = self.verify_by_pi_v(num_steps=100)
166 | reward += 1000.0 * is_door_locked
167 |
168 | if self.use_engineered_reward and door_closed:
169 | latch_v = self.data.get_joint_qvel("latch")
170 | reward += (-latch_v)
171 |
172 | self.t += 1
173 |
174 | self.sim.model.site_rgba[self.knob_sid] = [1, 0, 0, 1]
175 | self.sim.model.site_rgba[self.extra_knob_sid] = [0, 1, 0, 0]
176 |
177 | return ob, reward, done, dict(goal_achieved=goal_achieved,
178 | door_closed=door_closed)
179 |
180 | def get_obs(self, hist_len=1):
181 | adroit_qpos = self.data.qpos.ravel()[
182 | 1:-2] # last 2 dimensions are about door hinge and latch
183 | palm_pos = self.data.site_xpos[self.grasp_sid].ravel()
184 | door_pose = np.array([self.data.qpos[self.door_hinge_did]])
185 | knob_pos = self.data.site_xpos[self.knob_sid].ravel()
186 |
187 | latch_pose = self.data.get_joint_qpos("latch")
188 | latch_visual_pose = get_aliased_angle(latch_pose)
189 | if len(self.latch_obs_list) < self.obs_horizon:
190 | self.latch_obs_list = [latch_visual_pose] * self.obs_horizon
191 | else:
192 | self.latch_obs_list.pop(0)
193 | self.latch_obs_list.append(latch_visual_pose)
194 |
195 | door_close = 1.0 if door_pose < 0.05 else -1.0
196 |
197 | if self.use_whole_state_obs:
198 | obs = np.concatenate([
199 | adroit_qpos, palm_pos, door_pose, knob_pos, [latch_pose],
200 | [door_close]
201 | ])
202 | else:
203 | obs = np.concatenate([
204 | adroit_qpos, palm_pos, door_pose, knob_pos,
205 | self.latch_obs_list[-hist_len:], [door_close]
206 | ])
207 |
208 | return obs
209 |
210 | def reset_model(self):
211 | qp = self.init_qpos.copy()
212 | qv = self.init_qvel.copy()
213 | self.set_state(qp, qv)
214 |
215 | self.model.body_pos[self.door_bid,
216 | 0] = self.np_random.uniform(low=-0.3, high=-0.2)
217 | self.model.body_pos[self.door_bid,
218 | 1] = self.np_random.uniform(low=0.25, high=0.35)
219 | self.model.body_pos[self.door_bid,
220 | 2] = self.np_random.uniform(low=0.252, high=0.35)
221 |
222 | self.sim.data.set_joint_qpos("latch", 1.57)
223 | self.sim.data.set_joint_qpos(
224 | "door_hinge", self.np_random.uniform(low=0.25, high=0.4))
225 | if self.latch_random_reset:
226 | self.sim.data.set_joint_qpos(
227 | "latch", self.np_random.uniform(low=1.57, high=3.14))
228 | self.sim.data.set_joint_qpos(
229 | "door_hinge", self.np_random.uniform(low=0.25, high=1.3))
230 |
231 | self.sim.forward()
232 |
233 | self.t = 0
234 | return self.get_obs(hist_len=self.obs_horizon)
235 |
236 | def verify_by_pi_v(self, num_steps=100):
237 | # Reset hand pose first
238 | # Necessary to prevent Pi_t from exploiting Pi_v
239 | qp = self.init_qpos.copy()
240 | qv = self.init_qvel.copy()
241 | curr_qp = self.data.qpos.ravel().copy()
242 | curr_qp[0:-2] = qp[0:-2]
243 | self.set_state(curr_qp, qv)
244 | self.sim.forward()
245 |
246 | self.sim.model.site_rgba[self.knob_sid] = [1, 0, 0, 0]
247 | self.sim.model.site_rgba[self.extra_knob_sid] = [0, 1, 0, 1]
248 |
249 | is_door_locked = True
250 | for t in range(num_steps):
251 | self.mj_render()
252 |
253 | obs = self.get_obs(hist_len=1)
254 | action, _states = self.pi_v.predict(obs, deterministic=True)
255 |
256 | action = np.clip(action, -1.0, 1.0)
257 | whole_action = np.zeros(28)
258 | whole_action[:4] = np.copy(action[:4])
259 | whole_action[4:] = np.ones(24) * action[4]
260 |
261 | try:
262 | whole_action = self.act_mid + whole_action * self.act_rng
263 | except:
264 | whole_action = whole_action # only for the initialization phase
265 | self.do_simulation(whole_action, self.frame_skip)
266 |
267 | door_pose = np.array([self.data.qpos[self.door_hinge_did]])
268 | if door_pose > 0.1:
269 | is_door_locked = False
270 | break
271 | return is_door_locked
272 |
273 | def get_env_state(self):
274 | """
275 | Get state of hand as well as objects and targets in the scene
276 | """
277 | qp = self.data.qpos.ravel().copy()
278 | qv = self.data.qvel.ravel().copy()
279 | door_body_pos = self.model.body_pos[self.door_bid].ravel().copy()
280 | return dict(qpos=qp, qvel=qv, door_body_pos=door_body_pos)
281 |
282 | def set_env_state(self, state_dict):
283 | """
284 | Set the state which includes hand as well as objects and targets in the scene
285 | """
286 | qp = state_dict['qpos']
287 | qv = state_dict['qvel']
288 | self.set_state(qp, qv)
289 | self.model.body_pos[self.door_bid] = state_dict['door_body_pos']
290 | self.sim.forward()
291 |
292 | def mj_viewer_setup(self):
293 | self.viewer = MjViewer(self.sim)
294 | self.viewer.cam.azimuth = 90
295 | self.sim.forward()
296 | self.viewer.cam.distance = 1.5
297 |
298 | def evaluate_success(self, paths):
299 | num_success = 0
300 | num_paths = len(paths)
301 | # success if door open for 25 steps
302 | for path in paths:
303 | if np.sum(path['env_infos']['goal_achieved']) > 25:
304 | num_success += 1
305 | success_percentage = num_success * 100.0 / num_paths
306 | return success_percentage
307 |
308 |
309 | if __name__ == "__main__":
310 | import time
311 |
312 | env = DoorLockEnvAdroitSimple()
313 | env.reset()
314 | env.mj_render()
315 | for i in range(1000):
316 | env.reset()
317 | for t in range(1000):
318 | action = env.action_space.sample()
319 | obs, reward, done, info = env.step(action)
320 | env.mj_render()
321 | if done:
322 | break
323 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/door_lock_verify_adroit_simple.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | from gym import utils
3 | from gym import spaces
4 | from mjrl.envs import mujoco_env
5 | from mujoco_py import MjViewer
6 | from d4rl import offline_env
7 | import os
8 |
9 | from src.env.hand_manipulation_suite.door_lock_adroit_simple import get_aliased_angle
10 |
11 | USE_EXTRA_KNOB_ENV = True
12 |
13 |
14 | class DoorLockVerifyEnv(mujoco_env.MujocoEnv, utils.EzPickle,
15 | offline_env.OfflineEnv):
16 | def __init__(self, **kwargs):
17 | offline_env.OfflineEnv.__init__(self, **kwargs)
18 | self.door_hinge_did = 0
19 | self.door_bid = 0
20 | self.grasp_sid = 0
21 | self.handle_sid = 0
22 | self.knob_sid = 0
23 | self.extra_knob_sid = 0
24 | self.is_init_locked = 0
25 | self.action_dim_simple = 5
26 | # Override action_space to -1, 1
27 | self.action_space = spaces.Box(low=-1.0,
28 | high=1.0,
29 | dtype=np.float32,
30 | shape=(self.action_dim_simple, ))
31 |
32 | self.t = 0
33 | self.max_traj_length = 100
34 |
35 | curr_dir = os.path.dirname(os.path.abspath(__file__))
36 | self.sim = mujoco_env.get_sim(
37 | curr_dir + '/assets/door_xknob_adroit_extrageom.xml')
38 | self.data = self.sim.data
39 | self.model = self.sim.model
40 |
41 | self.frame_skip = 5
42 | self.metadata = {
43 | 'render.modes': ['human', 'rgb_array'],
44 | 'video.frames_per_second': int(np.round(1.0 / self.dt))
45 | }
46 | self.mujoco_render_frames = False
47 |
48 | self.init_qpos = self.data.qpos.ravel().copy()
49 | self.init_qvel = self.data.qvel.ravel().copy()
50 | observation = self.get_obs()
51 | self.obs_dim = np.sum([
52 | o.size for o in observation
53 | ]) if type(observation) is tuple else observation.size
54 |
55 | high = np.inf * np.ones(self.obs_dim)
56 | low = -high
57 | self.observation_space = spaces.Box(low, high, dtype=np.float32)
58 |
59 | self.seed()
60 |
61 | # change actuator sensitivity
62 | self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id(
63 | 'A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0') +
64 | 1, :3] = np.array([10, 0, 0])
65 | self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id(
66 | 'A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0') +
67 | 1, :3] = np.array([1, 0, 0])
68 | self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id(
69 | 'A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0') +
70 | 1, :3] = np.array([0, -10, 0])
71 | self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id(
72 | 'A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0') +
73 | 1, :3] = np.array([0, -1, 0])
74 |
75 | utils.EzPickle.__init__(self)
76 | ob = self.reset_model()
77 | self.act_mid = np.mean(self.model.actuator_ctrlrange, axis=1)
78 | self.act_rng = 0.5 * (self.model.actuator_ctrlrange[:, 1] -
79 | self.model.actuator_ctrlrange[:, 0])
80 | self.door_hinge_did = self.model.jnt_dofadr[self.model.joint_name2id(
81 | 'door_hinge')]
82 | self.grasp_sid = self.model.site_name2id('S_grasp')
83 | self.handle_sid = self.model.site_name2id('S_handle')
84 | self.door_bid = self.model.body_name2id('frame')
85 | self.knob_sid = self.model.site_name2id('knob_hinge')
86 | if USE_EXTRA_KNOB_ENV:
87 | self.extra_knob_sid = self.model.site_name2id('extra_knob')
88 |
89 | def step(self, a):
90 | a = np.clip(a, -1.0, 1.0)
91 | whole_action = np.zeros(28)
92 | whole_action[:4] = np.copy(a[:4])
93 | whole_action[4:] = np.ones(24) * a[4]
94 |
95 | try:
96 | whole_action = self.act_mid + whole_action * self.act_rng # mean center and scale
97 | except:
98 | whole_action = whole_action # only for the initialization phase
99 | self.do_simulation(whole_action, self.frame_skip)
100 |
101 | done = False
102 | if self.t >= self.max_traj_length:
103 | done = True
104 |
105 | ob = self.get_obs()
106 | door_pose = self.data.qpos[self.door_hinge_did]
107 | knob_pos = self.data.site_xpos[self.knob_sid].ravel()
108 | if USE_EXTRA_KNOB_ENV:
109 | knob_pos = self.data.site_xpos[self.extra_knob_sid].ravel()
110 | palm_pos = self.data.site_xpos[self.grasp_sid].ravel()
111 |
112 | reward = 0.0
113 | # dense reward for approaching knob
114 | reward += -4.0 * np.linalg.norm(palm_pos - knob_pos)
115 | # Decrease the rew scale to increase exploration
116 | # Investigate whether SAC subtracts the baseline reward
117 | if self.is_init_locked:
118 | # door should be closed after verification
119 | reward += -0.1 * (door_pose - 0.0)**2
120 |
121 | goal_achieved = True if door_pose <= 0.1 else False
122 | reward += 1.0 * goal_achieved
123 |
124 | if door_pose > 0.2:
125 | reward -= 3.0
126 | else:
127 | # door should be open after verification
128 | reward += -0.1 * (door_pose - 1.57)**2
129 |
130 | goal_achieved = True if door_pose >= 0.2 else False
131 | reward += 10.0 * goal_achieved
132 |
133 | if door_pose < 0.1:
134 | reward -= 3.0
135 |
136 | self.t += 1
137 |
138 | self.sim.model.site_rgba[self.knob_sid] = [1, 0, 0, 0]
139 | self.sim.model.site_rgba[self.extra_knob_sid] = [0, 1, 0, 1]
140 |
141 | return ob, reward, done, dict(goal_achieved=goal_achieved)
142 |
143 | def get_obs(self):
144 | adroit_qpos = self.data.qpos.ravel()[
145 | 1:-2] # last 2 dimensions are about door hinge and latch
146 | palm_pos = self.data.site_xpos[self.grasp_sid].ravel()
147 | door_pose = np.array([self.data.qpos[self.door_hinge_did]])
148 | knob_pos = self.data.site_xpos[self.knob_sid].ravel()
149 | if USE_EXTRA_KNOB_ENV:
150 | knob_pos = self.data.site_xpos[self.extra_knob_sid].ravel()
151 |
152 | latch_pose = self.data.get_joint_qpos("latch")
153 | latch_visual_pose = get_aliased_angle(latch_pose)
154 |
155 | door_close = 1.0 if door_pose < 0.05 else -1.0
156 | return np.concatenate([
157 | adroit_qpos, palm_pos, door_pose, knob_pos, [latch_visual_pose],
158 | [door_close]
159 | ])
160 |
161 | def reset_model(self):
162 | qp = self.init_qpos.copy()
163 | qv = self.init_qvel.copy()
164 | self.set_state(qp, qv)
165 |
166 | self.model.body_pos[self.door_bid,
167 | 0] = self.np_random.uniform(low=-0.3, high=-0.2)
168 | self.model.body_pos[self.door_bid,
169 | 1] = self.np_random.uniform(low=0.25, high=0.35)
170 | self.model.body_pos[self.door_bid,
171 | 2] = self.np_random.uniform(low=0.252, high=0.35)
172 |
173 | pos_or_neg_example = self.np_random.choice(np.array([0, 1]))
174 | if pos_or_neg_example < 0.5:
175 | # init as a positive example: door locked
176 | latch_init_pose = self.np_random.uniform(low=-0.7, high=1.0)
177 | self.is_init_locked = True
178 | else:
179 | # init as a negative example: example generated by policy
180 | # TODO (for user): here the latch_init_pose should load from pre-collected
181 | # policy rollouts
182 | latch_init_pose = self.np_random.uniform(low=1.0, high=3.1)
183 | self.is_init_locked = False
184 |
185 | self.sim.data.set_joint_qpos("latch", latch_init_pose)
186 |
187 | self.sim.forward()
188 |
189 | self.t = 0
190 | return self.get_obs()
191 |
192 | def get_env_state(self):
193 | """
194 | Get state of hand as well as objects and targets in the scene
195 | """
196 | qp = self.data.qpos.ravel().copy()
197 | qv = self.data.qvel.ravel().copy()
198 | door_body_pos = self.model.body_pos[self.door_bid].ravel().copy()
199 | return dict(qpos=qp, qvel=qv, door_body_pos=door_body_pos)
200 |
201 | def set_env_state(self, state_dict):
202 | """
203 | Set the state which includes hand as well as objects and targets in the scene
204 | """
205 | qp = state_dict['qpos']
206 | qv = state_dict['qvel']
207 | self.set_state(qp, qv)
208 | self.model.body_pos[self.door_bid] = state_dict['door_body_pos']
209 | self.sim.forward()
210 |
211 | def mj_viewer_setup(self):
212 | self.viewer = MjViewer(self.sim)
213 | self.viewer.cam.azimuth = 90
214 | self.sim.forward()
215 | self.viewer.cam.distance = 1.5
216 |
217 | def evaluate_success(self, paths):
218 | num_success = 0
219 | num_paths = len(paths)
220 | # success if door open for 25 steps
221 | for path in paths:
222 | if np.sum(path['env_infos']['goal_achieved']) > 25:
223 | num_success += 1
224 | success_percentage = num_success * 100.0 / num_paths
225 | return success_percentage
226 |
227 |
228 | if __name__ == "__main__":
229 | env = DoorLockVerifyEnv()
230 | env.reset()
231 | env.mj_render()
232 | for i in range(1000):
233 | obs = env.reset()
234 | for t in range(50):
235 | action = np.zeros(env.action_space.sample().shape)
236 | obs, reward, done, info = env.step(action)
237 | env.mj_render()
238 |
--------------------------------------------------------------------------------
/src/env/hand_manipulation_suite/door_v0.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | from gym import utils
3 | from gym import spaces
4 | from mjrl.envs import mujoco_env
5 | from mujoco_py import MjViewer
6 | from d4rl import offline_env
7 | import os
8 |
9 | ADD_BONUS_REWARDS = True
10 |
11 |
12 | class DoorEnvV0(mujoco_env.MujocoEnv, utils.EzPickle, offline_env.OfflineEnv):
13 | def __init__(self, **kwargs):
14 | offline_env.OfflineEnv.__init__(self, **kwargs)
15 | self.door_hinge_did = 0
16 | self.door_bid = 0
17 | self.grasp_sid = 0
18 | self.handle_sid = 0
19 | curr_dir = os.path.dirname(os.path.abspath(__file__))
20 | mujoco_env.MujocoEnv.__init__(self, curr_dir + '/assets/DAPG_door.xml',
21 | 5)
22 |
23 | # Override action_space to -1, 1
24 | self.action_space = spaces.Box(low=-1.0,
25 | high=1.0,
26 | dtype=np.float32,
27 | shape=self.action_space.shape)
28 |
29 | # change actuator sensitivity
30 | self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id(
31 | 'A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0') +
32 | 1, :3] = np.array([10, 0, 0])
33 | self.sim.model.actuator_gainprm[self.sim.model.actuator_name2id(
34 | 'A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0') +
35 | 1, :3] = np.array([1, 0, 0])
36 | self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id(
37 | 'A_WRJ1'):self.sim.model.actuator_name2id('A_WRJ0') +
38 | 1, :3] = np.array([0, -10, 0])
39 | self.sim.model.actuator_biasprm[self.sim.model.actuator_name2id(
40 | 'A_FFJ3'):self.sim.model.actuator_name2id('A_THJ0') +
41 | 1, :3] = np.array([0, -1, 0])
42 |
43 | utils.EzPickle.__init__(self)
44 | ob = self.reset_model()
45 | self.act_mid = np.mean(self.model.actuator_ctrlrange, axis=1)
46 | self.act_rng = 0.5 * (self.model.actuator_ctrlrange[:, 1] -
47 | self.model.actuator_ctrlrange[:, 0])
48 | self.door_hinge_did = self.model.jnt_dofadr[self.model.joint_name2id(
49 | 'door_hinge')]
50 | self.grasp_sid = self.model.site_name2id('S_grasp')
51 | self.handle_sid = self.model.site_name2id('S_handle')
52 | self.door_bid = self.model.body_name2id('frame')
53 |
54 | def step(self, a):
55 | a = np.clip(a, -1.0, 1.0)
56 | try:
57 | a = self.act_mid + a * self.act_rng # mean center and scale
58 | except:
59 | a = a # only for the initialization phase
60 | self.do_simulation(a, self.frame_skip)
61 | ob = self.get_obs()
62 | handle_pos = self.data.site_xpos[self.handle_sid].ravel()
63 | palm_pos = self.data.site_xpos[self.grasp_sid].ravel()
64 | door_pos = self.data.qpos[self.door_hinge_did]
65 |
66 | # get to handle
67 | reward = -0.1 * np.linalg.norm(palm_pos - handle_pos)
68 | # open door
69 | reward += -0.1 * (door_pos - 1.57) * (door_pos - 1.57)
70 | # velocity cost
71 | reward += -1e-5 * np.sum(self.data.qvel**2)
72 |
73 | if ADD_BONUS_REWARDS:
74 | # Bonus
75 | if door_pos > 0.2:
76 | reward += 2
77 | if door_pos > 1.0:
78 | reward += 8
79 | if door_pos > 1.35:
80 | reward += 10
81 |
82 | goal_achieved = True if door_pos >= 1.35 else False
83 |
84 | return ob, reward, False, dict(goal_achieved=goal_achieved)
85 |
86 | def get_obs(self):
87 | # qpos for hand
88 | # xpos for obj
89 | # xpos for target
90 | qp = self.data.qpos.ravel()
91 | handle_pos = self.data.site_xpos[self.handle_sid].ravel()
92 | palm_pos = self.data.site_xpos[self.grasp_sid].ravel()
93 | door_pos = np.array([self.data.qpos[self.door_hinge_did]])
94 | if door_pos > 1.0:
95 | door_open = 1.0
96 | else:
97 | door_open = -1.0
98 | latch_pos = qp[-1]
99 | return np.concatenate([
100 | qp[1:-2], [latch_pos], door_pos, palm_pos, handle_pos,
101 | palm_pos - handle_pos, [door_open]
102 | ])
103 |
104 | def reset_model(self):
105 | qp = self.init_qpos.copy()
106 | qv = self.init_qvel.copy()
107 | self.set_state(qp, qv)
108 |
109 | self.model.body_pos[self.door_bid,
110 | 0] = self.np_random.uniform(low=-0.3, high=-0.2)
111 | self.model.body_pos[self.door_bid,
112 | 1] = self.np_random.uniform(low=0.25, high=0.35)
113 | self.model.body_pos[self.door_bid,
114 | 2] = self.np_random.uniform(low=0.252, high=0.35)
115 | self.sim.forward()
116 | return self.get_obs()
117 |
118 | def get_env_state(self):
119 | """
120 | Get state of hand as well as objects and targets in the scene
121 | """
122 | qp = self.data.qpos.ravel().copy()
123 | qv = self.data.qvel.ravel().copy()
124 | door_body_pos = self.model.body_pos[self.door_bid].ravel().copy()
125 | return dict(qpos=qp, qvel=qv, door_body_pos=door_body_pos)
126 |
127 | def set_env_state(self, state_dict):
128 | """
129 | Set the state which includes hand as well as objects and targets in the scene
130 | """
131 | qp = state_dict['qpos']
132 | qv = state_dict['qvel']
133 | self.set_state(qp, qv)
134 | self.model.body_pos[self.door_bid] = state_dict['door_body_pos']
135 | self.sim.forward()
136 |
137 | def mj_viewer_setup(self):
138 | self.viewer = MjViewer(self.sim)
139 | self.viewer.cam.azimuth = 90
140 | self.sim.forward()
141 | self.viewer.cam.distance = 1.5
142 |
143 | def evaluate_success(self, paths):
144 | num_success = 0
145 | num_paths = len(paths)
146 | # success if door open for 25 steps
147 | for path in paths:
148 | if np.sum(path['env_infos']['goal_achieved']) > 25:
149 | num_success += 1
150 | success_percentage = num_success * 100.0 / num_paths
151 | return success_percentage
152 |
153 |
154 | if __name__ == "__main__":
155 | import time
156 |
157 | env = DoorEnvV0()
158 | env.reset()
159 | env.mj_render()
160 |
161 | for i in range(1000):
162 | env.reset()
163 | for t in range(50):
164 | action = np.zeros(env.action_space.sample().shape)
165 | action[4:] = -1.5
166 | # action = env.action_space.sample()
167 | obs, reward, done, info = env.step(action)
168 | env.mj_render()
169 | time.sleep(0.02)
170 |
171 | for t in range(50):
172 | action = np.zeros(env.action_space.sample().shape)
173 | action[4:] = 1.5
174 | # action = env.action_space.sample()
175 | obs, reward, done, info = env.step(action)
176 | env.mj_render()
177 | time.sleep(0.02)
178 |
--------------------------------------------------------------------------------
/src/robel_screw_pi_task.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 |
4 | from stable_baselines3 import SAC
5 |
6 | from robel.dclaw.turn import (DCLAW3_ASSET_PATH, DCLAW4_ASSET_PATH)
7 | from src.env.robel.dclaw_env import DClawScrewTask
8 |
9 | if __name__ == "__main__":
10 | from src.config import argparser
11 |
12 | config, _ = argparser()
13 | config.jobname = "real_robel_screw_valve4"
14 | figures_path = os.path.join("figures", config.jobname)
15 | os.makedirs(figures_path, exist_ok=True)
16 | checkpoint_path = os.path.join("checkpoints", config.jobname)
17 | os.makedirs(checkpoint_path, exist_ok=True)
18 |
19 | env = DClawScrewTask(
20 | asset_path=DCLAW4_ASSET_PATH,
21 | # frame_skip=80,
22 | verification_mode=False,
23 | use_verification_reward=True,
24 | # device_path='/dev/ttyUSB0',
25 | # action_mode="fixed_last_joint",
26 | use_engineered_rew=False,
27 | )
28 | env.use_hist_obs = True
29 | env.reset()
30 |
31 | model = SAC(
32 | "MlpPolicy",
33 | env,
34 | verbose=1,
35 | gamma=0.99,
36 | batch_size=1024,
37 | target_entropy=-3.0,
38 | )
39 |
40 | # Training/Continue training
41 | total_timesteps = 4000000
42 | save_per_timesteps = 10000
43 |
44 | for i in range(int(total_timesteps / save_per_timesteps)):
45 | print("======================================")
46 | start = time.time()
47 | model.learn(total_timesteps=save_per_timesteps)
48 |
49 | # Save model
50 | model.save(checkpoint_path + "/mfrl_sc_" +
51 | str((i + 1) * save_per_timesteps))
52 | print("Model saved after", (i + 1) * save_per_timesteps, "timesteps")
53 |
--------------------------------------------------------------------------------