walk-these-ways-go2/README.md

157 lines
6.1 KiB
Markdown
Raw Normal View History

2024-01-28 21:59:15 +08:00
# Sim-to-Real project on Unitree Go2
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
## Overview
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
This repository is forked from [walk-these-ways](https://github.com/Improbable-AI/walk-these-ways), which is a Go1 Sim-to-Real Locomotion Starter Kit. It seems that [walk-these-ways](https://github.com/Improbable-AI/walk-these-ways) can be untilized on Unitree [A1](https://github.com/fan-ziqi/dog_rl_deploy) with simple modifications, since those robots are base on [unitree-legged-sdk](https://github.com/unitreerobotics/unitree_legged_sdk).
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
However, the brand-new architecture [unitree-sdk2 ](https://github.com/unitreerobotics/unitree_sdk2)is not base on UDP anymore, so this project aims to train and deploy walk-these-ways on Unitree Go2 by modifying SDK interfaces.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
## Requirements
* pytorch 1.10 with cuda-11.3
* Isaac Gym
* Nvidia GPU with at least 8GB of VRAM
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
---
## Train
2024-01-29 14:07:10 +08:00
Clone this repository and install:
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
``` bash
git clone https://github.com/Teddy-Liao/walk-these-ways-go2.git
2024-01-29 14:07:10 +08:00
cd walk-these-ways-go2
pip install -e .
2024-01-28 21:59:15 +08:00
```
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
Start training:
2024-01-28 17:11:38 +08:00
```bash
2024-01-28 21:59:15 +08:00
python scripts/train.py
2024-01-28 17:11:38 +08:00
```
`go2_gym` and `go2_gym_learn` folders are the main folders for training process.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
Play the model:
2024-01-28 17:11:38 +08:00
```bash
cd scripts
python play.py
2024-01-28 17:11:38 +08:00
```
![Alt text](media/go2_training.jpg)
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
Go2 pretrained model is provided in [./runs](runs/gait-conditioned-agility/pretrain-go2), you can choose whether to use provide pretrained model by modifying the label line `label = "gait-conditioned-agility/pretrain-go2/train"` to your own trained model.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
### Known Issues
* `flip_visual_attachments` in [go1_config](go1_gym/envs/go1/go1_config.py) should be set to `True`, otherwise errors would occur when visualizing.
* To change configuration parameters of env or the robot, you should modify parameters in [go1_config](go1_gym/envs/go1/go1_config.py), not in [legged_robot_config](go1_gym/envs/base/legged_robot_config.py)
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
---
## Deploy
Trained policy is only supported to be deployed through your PC or laptop now, because I am not familiar with Jetson Orin, and hope I can fix it and deploy on Jetson Orin.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
### Requirements
#### Install LCM
Since [walk-these-ways](https://github.com/Improbable-AI/walk-these-ways) implement an interface based on Lightweight Communications and Marshalling ([LCM](https://github.com/lcm-proj/lcm)) to pass sensor data, motor commands, and joystick state between their code and the low-level control SDK provided by Unitree, LCM should be installed firstly in your PC or laptlop.
2024-01-28 17:11:38 +08:00
Clone LCM repository to any location (where you usually place installed softwares), then install LCM:
2024-01-28 17:11:38 +08:00
```bash
2024-01-28 21:59:15 +08:00
git clone https://github.com/lcm-proj/lcm.git
mkdir build
cd build
cmake ..
make
sudo make install
2024-01-28 17:11:38 +08:00
```
#### Unitree_SDK2
2024-01-28 21:59:15 +08:00
unitree_sdk2 has been inclued in `go2_gym_deploy/unitree_sdk2_bin/library/unitree_sdk2`, you can also clone from [Unitree Robotics](https://github.com/unitreerobotics/unitree_sdk2) to make sure the sdk is updated version.
2024-01-28 17:11:38 +08:00
```bash
2024-01-28 21:59:15 +08:00
cd go2_gym_deploy
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
Delete build file
2024-01-28 17:11:38 +08:00
```bash
2024-01-28 21:59:15 +08:00
rm -r build
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
Install and build:
2024-01-28 17:11:38 +08:00
```bash
2024-01-28 21:59:15 +08:00
sudo ./install.sh
mkdir build
cd build
cmake ..
make
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
### Build lcm_position_go2
`go2_gym_deploy/unitree_sdk2_bin/lcm_position_go2.cpp` is the core file of this project, which is similar to `lcm_position.cpp` in [walk-these-ways](https://github.com/Improbable-AI/walk-these-ways), but replace unitree_legged_sdk with unitree_sdk2.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
Build lcm_position_go2 and generate runfile `lcm_position_go2`
2024-01-28 17:11:38 +08:00
```bash
2024-01-28 21:59:15 +08:00
cd go2_gym_deploy
rm -r build
mkdir build
cd build
cmake ..
make -j
2024-01-28 17:11:38 +08:00
```
All LCM messages files in `go2_gym_deploy/lcm_types` are set as the same format shown in [walk-these-ways](https://github.com/Improbable-AI/walk-these-ways) to ensure successful connection with python files. LCM message files are provided in this project, and you can also generate customized LCM message files through the following instructions:
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
`xxx_lcmt.hpp` files are generated by:
```bash
lcm-gen -x xxx.lcm
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
### Verify connection
Connect your PC/Laptop with Go2 robot with ethernet cable and check connection by:
```bash
ping 192.168.123.161
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
Check the network interface address, and copy the network interface address.
```bash
ifconfig
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
If error occurs, please check [Unitree Support](https://support.unitree.com/home/zh/developer/Quick_start) for details.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
### Test communication between LCM and unitree_sdk2
```bash
cd go2_gym_deploy/build
sudo ./lcm_position_go2 enx10086
```
Aeplace `enx10086` with your own network interface address. According to the messages shown in terminal, press `Enter` for several times and the communication between LCM and unitree_sdk2 will set up.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
This command will automatically shut down Unitree sport_mode Service and set the robot to LOW-LEVEL. Please make sure This will Go2 is hung up or lie on the ground.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
You can verify LCM send by opening a new terminal:
```bash
cd go2_gym_deploy/build
sudo ./lcm_receive
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
### Load and run policy
Open a new terminate and run:
```bash
cd go2_gym_deploy/scripts
python deploy_policy.py
2024-01-28 17:11:38 +08:00
```
2024-01-28 21:59:15 +08:00
According to the hints shown in terminal, Press [R2] to start the controller. You can check RC mapping from [walk-these-ways](https://github.com/Improbable-AI/walk-these-ways) page.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
**Caution**:
* Press [L2+B] if any unexpected situation occurs!!!
* This is research code; use at your own risk; we do not take responsibility for any damage.
2024-01-28 17:11:38 +08:00
Test Video on Unitree Go2:
- Test in my bedroom: https://www.bilibili.com/video/BV1tQ4y1c7ZG/?spm_id_from=333.999.0.0&vd_source=07873ebe2a113dac57775e264a210929
- Test by other contributors: https://www.bilibili.com/video/BV1Ut421H7Fr/?spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=07873ebe2a113dac57775e264a210929
2024-01-28 17:11:38 +08:00
2024-01-28 22:01:48 +08:00
**Please star this repository if it does help you! Many Thanks!**
2024-01-28 22:01:48 +08:00
2024-01-28 21:59:15 +08:00
## Acknowledgements
2024-03-01 18:20:44 +08:00
* Many thanks to [Leolar](https://github.com/NihaoyaLeolar), who provide Nvidia 3060ti and supporting.
* Many thanks to [Jony](https://github.com/jonyzhang2023) and Peter for their support and encourage me to learn basic kownledge about RL.
2024-01-29 10:08:25 +08:00
* Many thanks to [Simonforyou](https://github.com/Simonforyou), who provide Go2 pretrained model.
2024-01-28 17:11:38 +08:00
2024-01-28 21:59:15 +08:00
## TO DO
- [x] Do not inherit config and env from go1_gym, build customized config and env files for Go2
- [ ] Deploy on Jeston Orin Nano