Roban2 Fall-and-Rise Training and Deployment Framework
Overview
This document provides step-by-step guidance on the main workflow for Roban2 fall-and-rise.
Prerequisites
Before you begin, make sure the following software and hardware requirements are met:
- Operating System: Linux (Ubuntu 20.04/22.04 recommended, x86_64)
- Hardware: NVIDIA GPU
Part 1: Reinforcement Learning Training Workflow
Core environment: NVIDIA Isaac Sim + Isaac Lab
1. Install Isaac Sim 4.5.0
You need to manually download NVIDIA Isaac Sim 4.5.0.
mkdir ~/roban_rl_rise && mkdir ~/roban_rl_rise/isaacsim # 也可以不创建roban_rl_rise而其他文件夹存放工程,后续将roban_rl_rise替换为您自己的工程文件夹名称即可
cd ~/Downloads
unzip "isaac-sim-standalone-4.5.0-linux-x86_64.zip" -d ~/roban_rl_rise/isaacsim
cd ~/roban_rl_rise/isaacsim
export ISAACSIM_PATH="${HOME}/roban_rl_rise/isaacsim"
export ISAACSIM_PYTHON_EXE="${ISAACSIM_PATH}/python.sh"
${ISAACSIM_PATH}/isaac-sim.shOnce the window pops up, this step is complete
, and you can terminate the process.
2. Configure Isaac Lab 2.1.0
Clone the Isaac Lab repository, create a symbolic link to Isaac Sim, and use Conda to create a virtual environment named roban_rise for installation.
cd ~/roban_rl_rise
git clone https://github.com/isaac-sim/IsaacLab.git
cd IsaacLab
git checkout v2.1.0
ln -s ../isaacsim _isaac_sim # 建立软链接 ln -s path_to_isaac_sim _isaac_sim
./isaaclab.sh --conda roban_rise
conda activate roban_rise
./isaaclab.sh --installSubsequent scripts must be executed in a Conda environment where IsaacLab is correctly installed and activated.
3. Get the training code repository
cd ~/roban_rl_rise
git clone https://gitee.com/leju-robot/roban_whole_body_tracking.git
cd roban_whole_body_tracking
python -m pip install -e source/whole_body_tracking
pip install "numpy==1.26.4"4. Data preprocessing (CSV to NPZ)
After the motion capture data is processed by GMR, you get CSV-format data containing the robot baselink global pose and joint angle data. This project provides a script that converts the CSV-format data into the richer NPZ format via Isaac Sim. If the device performance is not high enough, it is not recommended to remove the --headless parameter; otherwise there will be severe lag. When running on a low-spec GPU or CPU, --headless must be used.
- Parameter description: Replace
{motion_name}with the actual file name.
python scripts/csv_to_npz.py \
--input_file {motion_name}.csv \
--input_fps 30 \
--output_name {motion_name} \
--save_to assets/motions/{motion_name}.npz \
--no_wandb \
--headless5. Verify motion replay
Before starting training, first test whether the converted motion data can be replayed correctly.
replay_npz only verifies that the data format and joint mapping are correct; it does not mean the motion is dynamically executable.
python scripts/replay_npz.py \
--motion_file assets/motions/{motion_name}.npz6. Start training (Train)
Launch the reinforcement learning training task.
- Task name:
Tracking-Flat-RobanS2-v0
python scripts/rsl_rl/train.py \
--task=Tracking-Flat-RobanS2-v0 \
--motion_file assets/motions/{motion_name}.npz \
--headlessUse tensorboard to visualize the training process
tensorboard --logdir=${HOME}/roban_rl_rise/roban_whole_body_tracking/logs/rsl_rl/robanS2_flat7. Model conversion (Play)
Load the trained model checkpoint for demonstration. After running, a .onnx file that can be used for deployment will be generated.
python scripts/rsl_rl/play.py \
--task=Tracking-Flat-RobanS2-v0 \
--motion_file assets/motions/{motion_name}.npz \
--model_path logs/rsl_rl/{task_name}/{timestamp}/model_{checkpoint}.pt \
--num_envs 2 \
--headlessPart 2: Deployment and Real-Robot Verification Workflow
Core environment: Docker + ROS + Mujoco
1. Get the deployment code repository
Pull the kuavo-ros-opensource repository and switch to the specified test branch.
cd ~/roban_rl_rise
git clone -b opensource/roban_factory https://gitee.com/leju-robot/kuavo-ros-opensource.git
cd kuavo-ros-opensource2. Environment compilation
For non-real-robot use, compile with Docker:
./docker/run_with_gpu.sh
export ROBOT_VERSION=14 # 设置机器人版本号,Roban2在底层控制框架中对应的版本代号为v14。
source installed/setup.zsh
catkin config -DCMAKE_ASM_COMPILER=/usr/bin/as -DCMAKE_BUILD_TYPE=Release
catkin build humanoid_controllers
# 若编译失败,则执行 rm -rf devel build ,然后重新开始Compile on the real robot:
sudo su
export ROBOT_VERSION=14 # 设置机器人版本号
source installed/setup.bash
catkin config -DCMAKE_ASM_COMPILER=/usr/bin/as -DCMAKE_BUILD_TYPE=Release
catkin build humanoid_controllers
# 若编译失败,则执行 rm -rf devel build ,然后重新开始3. Modifying the parameter file
The parameter file is stored at: src/humanoid-control/humanoid_controllers/config/kuavo_v${机器人版本}/rl/skw_rl_param.info. You can modify the parameters in skw_rl_param.info, including the ONNX file path of the neural network, the input/output dimensions, etc. For details, refer to the comments in that file. This case takes modifying the ONNX file path and the CSV file as an example.
- Parameter description: To change file names, copy the previously trained .onnx file to
src/humanoid-control/humanoid_controllers/model/networks/; copy the previous .csv file tosrc/humanoid-control/humanoid_controllers/config/kuavo_v14/rl/.residualActionindicates whether residual network training is used. The trained model is a non-residual network by default, so this parameter should befalseby default; here the model was trained with a residual network, so the parameter istrue.
networkModelFile /2025-10-20_23-00-51.onnx;
trajectoryFile prone_1_robans221_1011.csv;
residualAction true4. Sim2Sim (Mujoco simulation verification)
Start Mujoco inside Docker for simulation testing.
source devel/setup.zsh
# 使用手柄北通2/北通2pro控制mpc行走
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=bt2
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=bt2pro
# 使用手柄北通2/北通2pro从起身开始进行运动,点按两次中间圆形键从倒地起身开始进行运动
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=bt2 init_fall_down_state:=true
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=bt2pro init_fall_down_state:=true
# 使用键盘控制mpc行走
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=sim
# 使用键盘从起身开始进行运动,在键盘控制界面依次按下g->c->g
roslaunch humanoid_controllers load_kuavo_mujoco_sim.launch joystick_type:=sim init_fall_down_state:=trueRunning result:
5. Sim2Real (running on the real robot)
# 在root权限下
source devel/setup.bash
# 使用手柄北通2/北通2pro控制mpc行走
roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=bt2
roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=bt2pro
# 使用手柄北通2/北通2pro从起身开始进行运动,点按两次中间圆形键从倒地起身开始进行运动
roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=bt2 init_fall_down_state:=true
roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=bt2pro init_fall_down_state:=true
# 使用键盘控制mpc行走
roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=sim
# 使用键盘从起身开始进行运动,键盘控制界面依次按下g->c->g
roslaunch humanoid_controllers load_kuavo_real.launch joystick_type:=sim init_fall_down_state:=trueReal-robot result:
Part 3 Core Code Walkthrough
command.py
(1) Joint data reordering (To Isaac)
- Function:
reorder_joint_data_for_isaac - Description: Reorder the joint data in the original NPZ file into the joint order expected by the IsaacLab simulation engine (usually depth-first traversal order).
(2) Joint data reordering (To NPZ)
- Function:
reorder_isaac_data_for_npz - Description: Reorder the joint data in IsaacLab (such as joint limit information) back into the NPZ file order, so that the loaded motion data can be constrained correctly.
(3) Motion data loader
- Class name:
MotionLoader - Function: Load the motion data from the npz file into memory and provide access to the required body part data, including joint velocity, joint position,
pos&quatandlin_vel&ang_velof specific body parts. - Dimension transformation: Map the data dimensions from
[T(Total Frames), AB(All Bodies), N]to[T, RB(Referred Bodies), N], i.e., keep only the data of the body parts that need to be tracked.
(4) Motion command manager
- Class name:
MotionCommand - Function: Provide preset, time-series motions for the agent to track.
-
Data indexing: Index by
time_stepsto map the data from[T, RB, N]to[RT(Current Time Step), RB, N]required by the current environment step. -
Error calculation (
_update_metrics):- Compute the error between the robot's current state (Robot State) and the reference motion (Motion Command);
- Include the position/velocity/orientation errors of the anchor (root node), as well as the relative position/orientation errors of each body part.
-
Command update and target retargeting (
_update_command):- Step-by-step update:
time_steps += 1, advancing the motion playback progress. - Redefine the blended coordinate frame: Compute
body_pos_relative_wandbody_quat_relative_w. - This will be used to compute: the Actor's observation input (i.e., the basis for the $\xi_{banchor}$-related computation in
observation.py) as well as the Relative Body Reward. The goal is to make the robot track where the limbs should be "if the reference motion happened at the current robot position", rather than tracking absolute coordinates several meters away. - Specific implementation:
- Align the Yaw angle: Compute the Yaw-axis rotation difference
delta_ori_wbetween the robot's current anchor and the reference motion anchor. - Build a virtual anchor: Create a position
delta_pos_wthat has the robot's X, Y coordinates but keeps the Z coordinate (height) of the reference motion. - Apply the transformation: Take the local offsets of each body part relative to its anchor in the reference motion (
body_pos_w - anchor_pos_w), rotate them bydelta_ori_w, and add them to the virtual anchordelta_pos_w. - Result: A virtual full-body target pose "based on the current robot position and heading" is obtained.
- Align the Yaw angle: Compute the Yaw-axis rotation difference
- Step-by-step update:
-
rewards.py
This module defines the reward functions of the training framework. The core design philosophy is "Gaussian kernel mapping": mapping the tracking error through an exponential function into the interval $(0, 1]$.
- When the error is 0, the reward is 1.
- When the error is infinite, the reward approaches 0.
1. Task tracking rewards (Tracking Rewards)
(1) Velocity tracking reward
Anchor (root node) absolute position reward
Guide the robot's root to move to the specified coordinates in the world coordinate system to prevent position drift.
- Corresponding function:
motion_global_anchor_position_error_exp- Code implementation:
- Compute the difference:
diff = command.anchor_pos_w - command.robot_anchor_pos_w. - Compute the squared norm:
error = torch.sum(torch.square(diff), dim=-1). - Gaussian mapping:
torch.exp(-error / std**2).
- Compute the difference:
- Mathematical meaning: Full-dimensional absolute position matching.
- $r_{pos} = \exp(-| \mathbf{p}{global}^{ref} - \mathbf{p}{global}^{robot} |^2 / \sigma^2)$
- This is a hard constraint, requiring the robot to keep up with the target in absolute space.
- Input data sources:
- Command:
anchor_pos_w(from the original NPZ trajectory + environment origin offset). - Robot:
robot_anchor_pos_w(from the simulator's physics state).
- Command:
- Code implementation:
Relative Body Position Reward
- Corresponding function:
motion_relative_body_position_error_exp- Code implementation:
- Index filtering: Use
_get_body_indexesto extract the key bodies. - Relative error:
diff = command.body_pos_relative_w - command.robot_body_pos_w. - Averaging:
error = torch.sum(torch.square(diff), dim=-1).mean(-1).
- Index filtering: Use
- Mathematical meaning: Morphological similarity in a mixed coordinate frame.
- The "relative" here embodies a subtle mixed logic:
- Horizontal direction (X, Y) — relative: The virtual target's X/Y follows the robot's current X/Y. This allows the robot to walk at any position.
- Vertical direction (Z) — absolute: The virtual target's Z is forced to adopt the Z of the reference motion.
- Yaw — relative: The virtual target has been rotated to align with the Yaw axis.
- Conclusion: What it rewards is "assuming the correct ego-centric pose at the correct height".
- Input data sources:
- Command:
body_pos_relative_w. Comes from the_update_commandfunction incommand.py, after Yaw-axis alignment and Z-axis locking. - Robot:
robot_body_pos_w.
- Command:
- Code implementation:
(2) Orientation Tracking Reward
This type of reward focuses on differences in rotation space ($SO(3)$), using quaternion geodesic distance to compute the error.
Anchor (Root Node) Absolute Orientation Reward
Forces the robot's overall heading (Yaw) and balance state (Pitch/Roll) to match the reference motion.
- Corresponding function:
motion_global_anchor_orientation_error_exp- Code implementation:
- Compute the quaternion difference:
error = quat_error_magnitude(command.anchor_quat_w, command.robot_anchor_quat_w) ** 2. - Gaussian mapping:
torch.exp(-error / std**2).
- Compute the quaternion difference:
- Mathematical meaning: Full-dimensional rotation consistency.
- $r_{ori} = \exp(- \text{dist}{SO3}(\mathbf{q}{global}^{ref}, \mathbf{q}_{global}^{robot})^2 / \sigma^2)$
- Includes Yaw: If the reference motion walks north while the robot walks east, this reward will be very low even if the robot has not fallen (Pitch/Roll are normal), forcing the robot to turn.
- Input data sources:
- Command:
anchor_quat_w(reference quaternion in the world frame). - Robot:
robot_anchor_quat_w(actual quaternion in the world frame).
- Command:
- Code implementation:
Relative Body Orientation Reward
Forces the robot's hands and feet to assume the correct rotation angles relative to the torso (e.g., palm rotation, ankle angle).
- Corresponding function:
motion_relative_body_orientation_error_exp- Code implementation:
- Relative error:
error = quat_error_magnitude(command.body_quat_relative_w, command.robot_body_quat_w) ** 2. - Averaging:
error.mean(-1)averages over all limbs.
- Relative error:
- Mathematical meaning: Local rotation consistency.
- $r = \exp \left( - \frac{1}{N} \sum_{i} \text{dist}{SO3}(\mathbf{q}{local}^{ref, i}, \mathbf{q}_{local}^{robot, i})^2 / \sigma^2 \right)$
- It has Yaw invariance: it only cares about the angle of the limb relative to the torso.
- Input data sources:
- Command (heavily processed):
body_quat_relative_w. Comes fromcommand.py, after rotation compensation viaquat_mul(delta_ori_w, ...). - Robot:
robot_body_quat_w.
- Command (heavily processed):
- Code implementation:
2. Physics and Contact Rewards
These rewards do not depend on the reference motion; instead, they are designed based on physical laws to regulate the robot's gait and contact behavior.
(1) Foot Lift-off/Contact Time Reward
Used to shape gait frequency, encouraging quick foot lifting or a specific contact rhythm.
- Corresponding function:
feet_contact_time- Code implementation:
first_air: Detects the moment of "just lifting off" (logic: contact wasTruein the previous frame andFalsein the current frame).last_contact_time: The continuous contact time recorded by the contact sensor.- Logic:
reward = sum((last_contact_time < threshold) * first_air).
- Mathematical meaning: Short Contact Reward.
- A reward is given only when the foot has completed a lift-off event ($0 \to 1$) and the preceding ground contact time was very short ($< T_{thresh}$).
- Purpose: Encourage the robot to take quick steps and avoid sticking to the ground (Sticking); typically used for highly dynamic motions (e.g., running, jumping).
- Input data sources:
- Contact sensor (Sim): Historical contact force and time data provided by IsaacLab's
ContactSensor.
- Contact sensor (Sim): Historical contact force and time data provided by IsaacLab's
- Code implementation:
(2) Feet Slide Penalty
Used to eliminate skating, which is one of the main causes of Sim-to-Real transfer failure.
- Corresponding function:
feet_slide- Code implementation:
contacts: Determines whether the foot is under force (in contact with the ground), with a threshold of 1.0 N (net_forces_w_history.norm > 1.0).body_vel: Gets the foot's horizontal linear velocity ([:, :2]).- Computation:
reward_vel = sum(body_vel.norm() * contacts).
- Mathematical meaning: Sliding velocity penalty.
- $Cost = \sum_{feet} | \mathbf{v}{xy} | \cdot \mathbb{I}{contact}$
- The logic is: if a foot is in contact with the ground ($\mathbb{I}{contact}=1$), its horizontal velocity ($\mathbf{v}{xy}$) should be 0. Any non-zero velocity means slipping.
- Note: The function returns a positive "slide amount"; in the RL configuration file this term is usually given a negative weight to turn it into a penalty.
- Input data sources:
- Physics engine: Rigid body linear velocity.
- Sensor: Contact force sensor.
- System role:
- Sim-to-Real: Slipping in simulation usually does not cause falls, but in the real world it leads to severe odometry drift and control failure. This penalty term forces the policy to learn the "static friction" physical constraint of the real world.
- Code implementation:
Acknowledgements and References
This project is developed based on the following open-source framework: