Quadruped robot reinforcement learning deployment method based on the unitree_guide state machine. The model trained through Isaac gym is successfully simulated in gazebo and deployed on the real robot. By modifying CMakeLists.txt
, the switch between simulation and deployment can be achieved.
Considering the file size, only go1_description
is reserved in src/unitree_ros/robots
. If you need to use other robots, please add the urdf file yourself.
A trained weight file for Unitree Go1 walking on flat ground is provided.
If this repository is helpful to you, please help click stars, thank you.
Download libtorch: libtorch-cxx11-abi-shared-with-deps-1.10.0+cu113.zip
https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.10.0%2Bcu113.zip
Remember the folder path after decompression: /yourpath/libtorch
Download the repository:
git clone https://github.com/dstx123/unitree_rl.git
Modify the libtorch path in the file unitree_guide/unitree_guide/CMakeLists.txt
:
set(Torch_DIR /yourpath/libtorch/share/cmake/Torch)
Run in the directory where src
is located
catkin_make
If you need to load a model you trained yourself, you may need to make the following adjustments to the code:
Modify the model path in the file unitree_guide/unitree_guide/CMakeLists.txt
:
set(BODY_MODEL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/model/body.jit")
set(ADAPT_MODEL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/model/adapt.jit")
add_definitions(-DBODY_MODEL_PATH="${BODY_MODEL_PATH}")
add_definitions(-DADAPT_MODEL_PATH="${ADAPT_MODEL_PATH}")
Here you can customize and add your own models.
Modify the corresponding model loading method in unitree_guide\unitree_guide\src\FSM\State_RL.cpp
. Please pay attention to the function void State_RL::_loadPolicy()
and void State_RL::_action_compute()
Please check the order of input and output variables and related parameters. Mainly seen in unitree_guide\unitree_guide\src\FSM\State_RL.cpp
and unitree_guide\unitree_guide\include\FSM\State_RL.h
start gazebo:
source devel/setup.bash
roslaunch unitree_guide gazeboSim.launch
Create a new terminal and run the controller:
source devel/setup.bash
sudo ./devel/lib/unitree_guide/junior_ctrl
Press the key 2
and the robot will stand up. Then press the key 4
, the robot will enter the reinforcement learning state machine. After the robot stands firm, control the movement through the keyboard.
In the terminal, you can use the 'w' 's' 'a' 'd' keys to control the robot's x and y-axis speed, and the 'j' 'l' keys to control the robot's rotation.
Make the following changes in the file unitree_guide/unitree_guide/CMakeLists.txt
:
set(SIMULATION OFF) # Use Gazebo or not, ON or OFF
set(REAL_ROBOT ON) # Link real robot or not, ON or OFF
Recompile:
catkin_make
Connect the computer and the robot through a network cable. Please make sure you can ping the robot. Please refer to Unitree repository for details.
Start the robot, and after the robot stands up, run this in the terminal:
sudo ./devel/lib/unitree_guide/junior_ctrl
At this time, the robot will sit down and enter the passive state. Press L2+A
, the robot will stands up. Then press 'start'. At this time, the robot enters the reinforcement learning state machine, controlling the robot's x- and y-axis speeds through the left joystick, and controlling the robot's rotation through the right joystick.
Thanks to Unitree official for providing the rl_ws
project.