Skip to content

Commit 54b1098

Browse files
authored
Sim2Real Deployment: Functionality to deploy the policy to Unitree H1
From pull request #6
2 parents 1399089 + a0b71cc commit 54b1098

17 files changed

+1219
-5
lines changed

Diff for: README.md

+38-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,23 @@ To apply these custom settings, pass the path to your YAML file using the `--env
304304
option when running the script. If the YAML file contains keys that do not exist in the default
305305
configuration, those keys will be ignored.
306306
307-
# Sim-to-Sim Validation
307+
# Validation
308+
The trained policy in Isaac Lab can be validated in two ways - Sim-to-Sim and Sim-to-Real.
309+
310+
<div align="center">
311+
<table>
312+
<tr>
313+
<td><img src="docs/stable_punch.gif" width="400"/></td>
314+
<td><img src="docs/stable_wave.gif" width="385"/></td>
315+
</tr>
316+
<tr>
317+
<td align="center"><font size="1"><em>Stable Punch - Mujoco (left) & Real Robot (right)</em></font></td>
318+
<td align="center"><font size="1"><em>Stable Wave - Mujoco (left) & Real Robot (right)</em></font></td>
319+
</tr>
320+
</table>
321+
</div>
322+
323+
## Sim-to-Sim Validation
308324
309325
We also provide a [Mujoco environment](./neural_wbc/mujoco_wrapper/) for conducting sim-to-sim validation of the trained policy.
310326
To run the evaluation of Sim2Sim,
@@ -317,7 +333,26 @@ ${ISAACLAB_PATH:?}/isaaclab.sh -p neural_wbc/inference_env/scripts/eval.py \
317333
--student_checkpoint model_<iteration_number>.pt
318334
```
319335
320-
Please be aware that the `mujoco_wrapper` only supports one environment at a time. For a reference, it will take up to `5h` to evaluate `8k` reference motions. The inference_env is designed for maximum versatility. It's also suitable for Sim2Real deployment when the user provides the real robot interface.
336+
Please be aware that the `mujoco_wrapper` only supports one environment at a time. For a reference, it will take up to `5h` to evaluate `8k` reference motions. The inference_env is designed for maximum versatility.
337+
338+
## Sim-to-Real Deployment
339+
340+
For sim-to-real validation, we provide a [Hardware environment](./neural_wbc/hw_wrappers/) for Unitree H1.
341+
To install the required dependencies and environment setup, please refer to the [README of sim2real deployment](./neural_wbc/hw_wrappers/README.md).
342+
343+
To deploy the trained policy on the [Unitree H1 robot](https://unitree.com/h1),
344+
345+
```bash
346+
${ISAACLAB_PATH:?}/isaaclab.sh -p neural_wbc/inference_env/scripts/s2r_player.py \
347+
--student_path neural_wbc/data/data/policy/h1:student/ \
348+
--student_checkpoint model_<iteration_number>.pt \
349+
--reference_motion_path neural_wbc/data/data/motions/<motion_name>.pkl \
350+
--robot unitree_h1 \
351+
--max_iterations 5000 \
352+
--num_envs 1
353+
```
354+
355+
> **_NOTE:_** The sim-to-real deployment wrapper currently only supports the Unitree H1 robot. It can be extended to other robots by implementing the corresponding hardware wrapper interface.
321356
322357
# Developing
323358
@@ -410,6 +445,7 @@ We would like to acknowledge the following projects where parts of the codes in
410445
- [Mujoco Python Viewer](https://github.com/rohanpsingh/mujoco-python-viewer)
411446
- [RSL RL](https://github.com/leggedrobotics/rsl_rl)
412447
- [human2humanoid](https://github.com/LeCAR-Lab/human2humanoid)
448+
- [Unitree Python SDK](https://github.com/unitreerobotics/unitree_sdk2_python)
413449
414450
[omnih2o_paper]: https://arxiv.org/abs/2406.08858
415451
[hover_paper]: https://arxiv.org/abs/2410.21229

Diff for: docs/stable_punch.gif

+3
Loading

Diff for: docs/stable_wave.gif

+3
Loading

Diff for: neural_wbc/core/neural_wbc/core/observations/student_observations.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ def compute_student_observations(
3333
history: torch.Tensor,
3434
mask: torch.Tensor,
3535
ref_episodic_offset: torch.Tensor | None = None,
36+
local_base_ang_velocity: torch.Tensor | None = None,
3637
) -> tuple[torch.Tensor, dict[str, torch.Tensor]]:
3738
"""Computes observations for a student policy."""
3839
obs_dict = {
3940
"distilled_robot_state": compute_distilled_robot_state_observation(
4041
body_state=body_state,
4142
base_id=base_id,
4243
projected_gravity=projected_gravity,
44+
local_base_ang_velocity=local_base_ang_velocity,
4345
),
4446
"distilled_imitation": compute_distilled_imitation_observations(
4547
ref_motion_state=ref_motion_state,
@@ -193,14 +195,18 @@ def compute_distilled_robot_state_observation(
193195
body_state: BodyState,
194196
base_id: int,
195197
projected_gravity: torch.Tensor,
198+
local_base_ang_velocity: torch.Tensor | None = None,
196199
) -> torch.Tensor:
197200
"""Root body state in the robot root frame."""
198201
# for normalization
199202
joint_pos = body_state.joint_pos.clone()
200203
joint_vel = body_state.joint_vel.clone()
201204

202-
base_rot = body_state.body_rot_extend[:, base_id, :].clone()
203-
base_ang_vel = body_state.body_ang_vel_extend[:, base_id, :].clone()
204-
local_base_ang_vel = math_utils.quat_rotate_inverse(base_rot, base_ang_vel)
205+
local_base_ang_vel = local_base_ang_velocity
206+
207+
if local_base_ang_velocity is None:
208+
local_base_ang_vel = math_utils.quat_rotate_inverse(
209+
body_state.body_rot_extend[:, base_id, :], body_state.body_ang_vel_extend[:, base_id, :]
210+
)
205211

206212
return torch.cat([joint_pos, joint_vel, local_base_ang_vel, projected_gravity], dim=-1)

Diff for: neural_wbc/hw_wrappers/README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Neural WBC - Hardware Wrapper for Unitree H1
2+
3+
This module is a high-level wrapper for the [Unitree H1](https://unitree.com/h1) robot hardware. It is designed to provide convenient interfaces to deploy the trained policy on the Unitree H1 robot. The main purpose of this wrapper is to validate Whole Body Control (WBC) policies trained in IsaacLab on the real robot.
4+
> **Note:** The sim-to-real deployment wrapper currently only supports the Unitree H1 robot. It can be extended to other robots by implementing the corresponding hardware wrapper interface.
5+
6+
## Setup
7+
Our deployment setup uses an Ubuntu PC with GPU for running policy inference, connected to the H1 robot via Ethernet. For network configuration, please refer to the [Unitree H1 Quick Start Guide](https://support.unitree.com/home/en/H1_developer/start).
8+
<div align="center">
9+
<div style="background-color: #f5f5f5; padding: 20px; border-radius: 8px; display: inline-block;">
10+
<img src="docs/unitree_h1_setup.png" width="400"/>
11+
<br>
12+
<font size="1"><em>Unitree H1 setup</em></font>
13+
</div>
14+
</div>
15+
16+
> **Note:** This guide assumes familiarity with basic Unitree H1 operation. Please refer to the official [Unitree H1 Operation Guide](https://support.unitree.com/home/en/H1_developer/quick_start) for fundamental robot operations, as these are outside the scope of this guide.
17+
18+
## Installation
19+
20+
To install the required dependencies:
21+
22+
```bash
23+
${ISAACLAB_PATH:?}/isaaclab.sh -p -m pip install -r requirements_deploy.txt
24+
```
25+
For any issues with Unitree SDK installation, see the [Unitree Python SDK](https://github.com/unitreerobotics/unitree_sdk2_python).
26+
27+
## Usage
28+
29+
### Check for successful connection with the robot
30+
- Make sure the robot is in develop mode using the joystick before executing the below example. Use the [Unitree Operation guide](https://support.unitree.com/home/en/H1_developer/quick_start) to transition the robot to develop mode.
31+
- Make sure robot is safely mounted on gantry with enough space around it.
32+
```bash
33+
cd ~/unitree_sdk2_python
34+
python3 example/h1/low_level/h1_low_level_example.py <network interface>
35+
```
36+
If the robot responds to the low-level example commands, your setup and network connection are working correctly. You can proceed to the next steps after exiting the example program.
37+
38+
### Check for successful setup of the Hover stack:
39+
- Execute the below commands from the hover stack root directory.
40+
- First ensure that all dependencies are installed using the common script
41+
[./install_deps.sh](../../install_deps.sh)
42+
43+
- Run the simple viewer with:
44+
45+
```sh
46+
${ISAACLAB_PATH}/isaaclab.sh -p neural_wbc/inference_env/scripts/mujoco_viewer_player.py
47+
```
48+
49+
The viewer is paused on start by default, press `SPACE` key to start simulation or `RIGHT` arrow key
50+
to step forward once. By default this script will load the UniTree H1 robot model scene from
51+
[data/mujoco/models](../data/data/mujoco/models/scene.xml).
52+
53+
## Deployment
54+
55+
> **Note:** Current deployment does not use external sensors for robot root tracking. The setup supports deploying stable motions where the robot stabilizes in place while executing upper body motions.
56+
57+
By default the policy is deployed in OmniH2O mode (tracking head and hand positions). In order to deploy a different mode, change the configuration in [config_file](../inference_env/inference_env/neural_wbc_env_cfg_real_h1.py).
58+
59+
Once sim-to-sim validation is done, the policy can be deployed on the real robot using the following steps.
60+
61+
1. Follow the [Unitree H1 Operation Guide](https://support.unitree.com/home/en/H1_developer/quick_start) to:
62+
- Boot the robot (Steps 1-5 under "Boot Process")
63+
- Switch to develop mode using the joystick (Steps under "Develop Mode")
64+
2. Once the H1 robot is transitioned to develop mode, execute this command to deploy the policy while the robot is securely mounted on the gantry:
65+
```bash
66+
${ISAACLAB_PATH:?}/isaaclab.sh -p neural_wbc/inference_env/scripts/s2r_player.py \
67+
--student_path neural_wbc/data/data/policy/h1:student/ \
68+
--student_checkpoint model_<iteration_number>.pt \
69+
--reference_motion_path neural_wbc/data/data/motions/<motion_name>.pkl \
70+
--robot unitree_h1 \
71+
--max_iterations 5000 \
72+
--num_envs 1
73+
```
74+
You can now deploy the policy on the real robot in headless mode by passing the `--headless` option.
75+
76+
2. Upon command execution, the robot will automatically move to match the starting pose of the reference motion. You can preview this motion in the Mujoco viewer UI, where the reference trajectory is visualized as red dots.
77+
78+
3. Once the robot is in the starting pose:
79+
- Gradually lower the gantry until the robot's feet make contact with the ground
80+
- Press the space bar in the Mujoco viewer UI to begin policy execution
81+
- Completely lower the gantry to allow free movement of the robot
82+
83+
<div align="center">
84+
<img src="docs/push_recovery.gif" width="400"/>
85+
<br>
86+
<font size="1"><em> Policy deployment of stable motion</em></font>
87+
</div>
88+
89+
> **Note:** If the robot loses motor torque and becomes unresponsive to joystick commands, restart the robot and contact Unitree support for troubleshooting.
90+
91+
## Unit Tests
92+
93+
The tests are located in the `tests` directory and can be run with the `unittest` module.
94+
95+
```bash
96+
cd neural_wbc/hw_wrappers
97+
${ISAACLAB_PATH:?}/isaaclab.sh -p -m unittest
98+
```

Diff for: neural_wbc/hw_wrappers/docs/push_recovery.gif

+3
Loading

Diff for: neural_wbc/hw_wrappers/docs/unitree_h1_setup.png

+3
Loading

Diff for: neural_wbc/hw_wrappers/hw_wrappers/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Needed to have the robot registry 'activated'
17+
from hw_wrappers.unitree_h1 import UnitreeH1 # noqa

0 commit comments

Comments
 (0)