Reinforcement Learning Case (Lab Version)
0. Overview
This case briefly introduces how to use Leju's open-source reinforcement learning locomotion control repository leju_robot_rl to train and deploy the Leju Kuavo robot.
1. Demo
- sim2sim
- sim2real
2. Environment Preparation
- System requirements: Ubuntu 20.04/22.04 LTS
Before you begin, make sure the following environment setup steps are completed. It is recommended to use Conda to create an isolated virtual environment.
-
Download the required software
- Download Isaac Sim 4.2 by following the instructions here:
- Download Isaac Lab 1.4.1 (in this example, Isaac Lab is downloaded to the home directory) by following the instructions here:
- If you cannot find the Isaac Sim 4.2 installation page at the above URL, you can refer to the 4.5 version page, as shown below:

- Download rsl_rl. The recommended commit is
commit 386875591808cfd1462a42446b1fa0a22ac161d0
git clone https://github.com/leggedrobotics/rsl_rl.git cd rsl_rl git checkout 386875591808cfd1462a42446b1fa0a22ac161d0 - Download Isaac Sim 4.2 by following the instructions here:
-
Set up symbolic links
- Create a symbolic link to Isaac Sim in the Isaac Lab directory.
ln -s {isaacsim_path} _isaac_sim -
Create and configure a Conda virtual environment (recommended)
Important: Before you begin, make sure Conda's package search channels are configured correctly, with
conda-forgeas the primary channel and strict channel priority enabled.# 添加 conda-forge 渠道 conda config --add channels conda-forge # 设置通道优先级为严格 conda config --set channel_priority strictNext, use Isaac Lab's script to create and activate the Conda environment.
# 创建名为 your_envs_name 的 Conda 环境 ./isaaclab.sh --conda your_envs_name # 激活环境 conda activate your_envs_name -
Configure the Python environment and install dependencies
Note: If you do not use a Conda virtual environment, all subsequent
pythoncommands must be replaced with~/IsaacLab/isaaclab.sh -p, and allpipcommands must be replaced with~/IsaacLab/isaaclab.sh -p -m pip. Using Conda is much more convenient.# 进入 Isaac Sim 根目录,执行官方脚本设置环境 # cd /{isaacsim_path} source setup_python_env.sh # 进入 Isaac Lab 根目录,安装 rl_games # cd ~/IsaacLab ./isaaclab.sh --install rl_games # 进入 leju_robot_rl 项目目录,安装自定义扩展 # cd ~/leju_robot_rl pip install -e leju_robot_rl/exts/ext_template # 进入 rsl_rl 库目录,进行本地安装 # cd {rsl_rl_path} pip install -e . -
Verify that Isaac Lab 1.4.1 is successfully installed
- Please use the Isaac Lab official documentation website to verify that your Isaac Lab installation is successful before proceeding to the following steps.
3. Train Your Model
- Clone the leju_robot_rl repository
git clone https://gitee.com/leju-robot/leju_robot_rl.git-
Before training, the following file needs to be modified.
- Disable joint acceleration updates (under IsaacLab)
-
File path:
/{isaaclab_path}/source/extensions/omni.isaac.lab/omni/isaac/lab/assets/articulation/articulation_data.py -
Modification: Comment out the
self.joint_accline.# around line 82 in articulation_data.py def update(self, dt: float): # update the simulation timestamp self._sim_timestamp += dt # Trigger an update of the joint acceleration buffer at a higher frequency # since we do finite differencing. # self.joint_acc # <- 注释掉此行
-
- Disable joint acceleration updates (under IsaacLab)
-
After completing the above modifications, you can run the
train.pyscript to start training.# conda activate your_env # cd leju_robot_rl python scripts/rsl_rl/train.py \ --task Legged-Isaac-Velocity-Flat-Kuavo-S42-v0 \ --num_envs 4096 \ --headless
4. Convert .pt to .onnx
After training is complete, convert the PyTorch model file (.pt) to the ONNX format (.onnx) required for robot deployment.
- Run the
play.pyscript.
# cd leju_robot_rl
python scripts/rsl_rl/play.py \
--task Legged-Isaac-Velocity-Flat-Kuavo-S42-Play-v0 \
--num_envs 32- The script automatically loads the trained
.ptmodel and generates the corresponding.onnxfile. - The newly generated
.onnxmodel file is located atleju_robot_rl/logs/rsl_rl/Kuavo/s42/flat/{time_train}/exported/policy_s42.onnx. Copy it to the onboard controller environment or the real robot; the target location is/home/lab/kuavo-rl-opensource/kuavo-robot-deploy/src/humanoid-control/humanoid_controllers/model/networks.
5. Deploy to Sim/Real
Deploy the trained model to a simulation environment or a real robot.
- Download the kuavo_rl_opensource repository
git clone -b beta https://gitee.com/leju-robot/kuavo-rl-opensource.git- Modify the
launchfile, located at/home/lab/kuavo-rl-opensource/kuavo-robot-deploy/src/humanoid-control/humanoid_controllers/launch.
- If the model is deployed to a simulation environment, modify
load_kuavo_mujoco_sim.launch; if the model is deployed to a real robot, modifyload_kuavo_real.launch:
# 原有代码为:
<arg name="rl_param" default="$(find humanoid_controllers)/config/kuavo_v$(arg robot_version)/rl/skw_rl_param.info"/>
# 应修改为:
# 确保程序使用的是flat_csp.info
<arg name="rl_param" default="$(find humanoid_controllers)/config/kuavo_v$(arg robot_version)/rl/flat_csp.info"/>- Modify the
flat_csp.infofile, located at/home/lab/kuavo-rl-opensource/kuavo-robot-deploy/src/humanoid-control/humanoid_controllers/config/kuavo_v46/rl:
- Change the original
.onnxmodel referenced in it to the newly generated model.
# 原有代码为:
networkModelFile /policy_s46_demo.onnx;
# 将其修改为:
# 确保程序使用的模型是您训练生成的:
networkModelFile /your_new_model.onnx;- Our code repository provides a model trained based on this case,
policy_s46_demo.onnx, which can be used directly.
- Build
cd kuavo-rl-opensource/kuavo-robot-deploy/
sudo su
export ROBOT_VERSION=46
source installed/setup.bash
catkin build humanoid_controllers- Launch:
- H12 remote controller instructions
-
Real robot startup
- Before starting, make sure button
Eis at the far left and buttonFis at the far right. - After the robot retracts its legs, flick the
Fbutton to the far left to make it stand up. - After the robot is standing, press the buttons for entering reinforcement learning mode and for unlocking in sequence. The robot can then be controlled with the joystick.
- Flicking the
Ebutton to the far right stops the program (note that the robot will not squat down automatically at this time).
- Before starting, make sure button
-
Reinforcement learning H12 remote controller button positions: Go to
-
⚠️ Note: If your onboard controller has the autostart service for the H12 remote controller deployed, you need to run sudo systemctl stop ocs2_h12pro_monitor.service and sudo pkill -f ros in sequence before running this case, and then continue with the following steps.
# 新开终端
cd kuavo-rl-opensource/kuavo-robot-deploy
sudo su
export ROBOT_VERSION=46
source devel/setup.bash
# 仿真环境下
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=sim # 启动rl控制器、wbc、仿真器(默认 sim_input_mode:=keyboard)。
# 如需 GUI 虚拟手柄输入,请显式指定:
# roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=sim sim_input_mode:=gui
# 实物环境下
roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=h12 # 可以选择cali:=true和cali_arm:=true进行校准启动,但校准启动不会自动缩腿,需要把F键拨到最左边两次,第一次是执行缩腿,第二次是执行站立 。Note: Start only one of the simulation and real robot.
joystick_type:=simuses keyboard input by default (sim_input_mode:=keyboard); GUI mode requires explicitly passingsim_input_mode:=gui.