2024-03-14 12:42:00 +08:00
|
|
|
# rl_sar
|
2024-03-06 17:32:15 +08:00
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
[中文文档](README.md)
|
|
|
|
|
|
|
|
Gazebo simulation verification and UnitreeA1 physical deployment for reinforcement learning. "sar" stands for "simulation and real".
|
2024-03-06 17:32:15 +08:00
|
|
|
|
2024-03-07 11:54:33 +08:00
|
|
|
## Preparation
|
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
Clone the code (sync submodules)
|
2024-03-07 11:54:33 +08:00
|
|
|
|
|
|
|
```bash
|
2024-03-14 12:42:00 +08:00
|
|
|
git clone --recursive https://github.com/fan-ziqi/rl_sar.git
|
2024-03-07 11:54:33 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
If there are updates:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
git pull
|
|
|
|
git submodule update --remote --recursive
|
|
|
|
```
|
|
|
|
|
|
|
|
Download and deploy `libtorch` at any location
|
2024-03-06 17:32:15 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
cd /path/to/your/torchlib
|
|
|
|
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.0.1%2Bcpu.zip
|
|
|
|
unzip libtorch-cxx11-abi-shared-with-deps-2.0.1+cpu.zip -d ./
|
|
|
|
echo 'export Torch_DIR=/path/to/your/torchlib' >> ~/.bashrc
|
|
|
|
```
|
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
Install `teleop-twist-keyboard`
|
2024-03-06 17:32:15 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo apt install ros-noetic-teleop-twist-keyboard
|
|
|
|
```
|
|
|
|
|
2024-03-07 11:54:33 +08:00
|
|
|
## Compilation
|
2024-03-06 17:32:15 +08:00
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
Customize the following two functions in your code to adapt to different models:
|
2024-03-06 17:32:15 +08:00
|
|
|
|
|
|
|
```cpp
|
|
|
|
torch::Tensor forward() override;
|
|
|
|
torch::Tensor compute_observation() override;
|
|
|
|
```
|
|
|
|
|
2024-03-07 11:54:33 +08:00
|
|
|
Then compile in the root directory
|
2024-03-06 17:32:15 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
cd ..
|
|
|
|
catkin build
|
|
|
|
```
|
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
## Running
|
|
|
|
|
2024-03-14 13:11:01 +08:00
|
|
|
Before running, copy the trained pt model file to `rl_sar/src/rl_sar/models`
|
2024-03-06 17:32:15 +08:00
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
### Simulation
|
2024-03-06 17:32:15 +08:00
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
Open a new terminal, launch the gazebo simulation environment
|
2024-03-06 17:32:15 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
source devel/setup.bash
|
2024-03-14 13:11:01 +08:00
|
|
|
roslaunch rl_sar start_env.launch
|
2024-03-06 17:32:15 +08:00
|
|
|
```
|
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
Open a new terminal, run the control program
|
2024-03-06 17:32:15 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
source devel/setup.bash
|
2024-03-14 13:11:01 +08:00
|
|
|
rosrun rl_sar unitree_rl
|
2024-03-06 17:32:15 +08:00
|
|
|
```
|
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
Open a new terminal, run the keyboard control program
|
2024-03-06 17:32:15 +08:00
|
|
|
|
|
|
|
```bash
|
|
|
|
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
|
|
|
|
```
|
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
### Physical Deployment
|
|
|
|
|
|
|
|
Open a new terminal, run the control program
|
2024-03-06 17:32:15 +08:00
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
```bash
|
|
|
|
source devel/setup.bash
|
2024-03-14 13:11:01 +08:00
|
|
|
rosrun rl_sar unitree_rl_real
|
2024-03-14 12:42:00 +08:00
|
|
|
```
|
2024-03-06 17:32:15 +08:00
|
|
|
|
2024-03-14 12:42:00 +08:00
|
|
|
> Some code references: https://github.com/mertgungor/unitree_model_control
|