Whole-Body Control deployment system for humanoid robots using reinforcement learning and motion tracking.
English | 中文
- State Machine Control: Multiple FSM states including Passive, Loco (locomotion), and WBC (whole-body control)
- Motion Tracking: Real-time tracking of LAFAN1 motion dataset retargeted for Unitree G1 humanoid robots
- ONNX Runtime: Fast inference with ONNX models
- Configurable: JSON-based configuration for easy parameter tuning
- CMake >= 3.14
- C++17 compiler
- CUDA
- Required libraries:
- unitree_sdk2
- ONNX Runtime 1.22.0 (see installation below)
- Eigen3
- nlohmann_json >= 3.7.3
- Boost
Download and extract ONNX Runtime 1.22.0 to the controller/ directory:
For x64 (Simulation):
cd controller/
wget https://github.com/microsoft/onnxruntime/releases/download/v1.22.0/onnxruntime-linux-x64-1.22.0.tgz
tar -xzf onnxruntime-linux-x64-1.22.0.tgzFor aarch64 (Real Robot):
cd controller/
wget https://github.com/microsoft/onnxruntime/releases/download/v1.22.0/onnxruntime-linux-aarch64-1.22.0.tgz
tar -xzf onnxruntime-linux-aarch64-1.22.0.tgzmkdir -p build
cd build
cmake ..
make -j4Configuration files are located in config/:
wbc.json: WBC state configurationloco.json: Locomotion state configurationfixedpose.json: FixedStand state configurationpassive.json: Passive state configuration
Example configuration (wbc.json):
{
"model_path": "model/wbc/lafan1_0128_1.onnx",
"folder_path": "motion_data/lafan1/dance12_binary",
"enter_idx": 0,
"pause_idx": 350,
"safe_projgravity_threshold": 0.5
}-
Install Unitree Mujoco following the instructions at https://github.com/unitreerobotics/unitree_mujoco
-
Set the ONNX Runtime path in
CMakeLists.txt:set(ONNXRUNTIME_ROOT ${PROJECT_SOURCE_DIR}/onnxruntime-linux-x64-1.22.0)
-
Configure the network interface in
controller/src/interface/IOSDK.cpp:ChannelFactory::Instance()->Init(1, "lo"); // lo for simulation
-
Build the project:
cd build cmake .. make -j4 -
Edit unitree_mujoco/config.yaml and Start the simulation:
robot: "g1" # Robot name, "go2", "b2", "b2w", "h1", "go2w", "g1" robot_scene: "scene_29dof.xml" # Robot scene, /unitree_robots/[robot]/scene.xml domain_id: 1 # Domain id interface: "lo" # Interface use_joystick: 1 # Simulate Unitree WirelessController using a gamepad joystick_type: "xbox" # support "xbox" and "switch" gamepad layout joystick_device: "/dev/input/js0" # Device path joystick_bits: 16 # Some game controllers may only have 8-bit accuracy print_scene_information: 1 # Print link, joint and sensors information of robot enable_elastic_band: 1 # Virtual spring band, used for lifting h1
cd simulate/build ./unitree_mujoco -
Run the controller (in a new terminal):
cd controller/build ./wbc_fsm
-
Copy this project to
/home/unitreeon the Unitree G1 robot's PC2 computer -
Set the ONNX Runtime path in
CMakeLists.txt:set(ONNXRUNTIME_ROOT ${PROJECT_SOURCE_DIR}/onnxruntime-linux-aarch64-1.22.0)
-
Configure the network interface in
controller/src/interface/IOSDK.cpp:ChannelFactory::Instance()->Init(0, "eth0"); // eth0 for real robot
-
Build the project:
cd build cmake .. make -j4 -
Run the controller:
./wbc_fsm
- R1: Resume WBC state (when paused)
- R2: Pause WBC state (at specified frame)
- L2: Pause WBC state (at current frame)
- R2+A: Switch to Loco mode
- L2+B: Switch to Passive mode
- SELECT: Exit program
- After starting the program, the robot enters Damping Protection Mode
- Press START to enter position control mode
- Suspend the robot (In simulation,
enable_elastic_bandis enabled by default. Press keyboard 9 to release the band, press again to re-suspend. Press 8 to lower, 7 to raise) - Press R2+A on the controller to enter Loco(AMP) Mode, then release the suspension band
- Press R2+up to enter high speed mode(running)
- Press R2+down to enter low speed mode(walking)
- Press R2+B on the controller to enter Loco(RL) Mode
- Press R1+Up on the controller to enter WBC (Whole-Body Control) Mode
- Press R2 to pause the motion
- Press R1 to resume the motion
controller/
├── config/ # Configuration files
├── include/ # Header files
│ ├── common/ # Common utilities
│ ├── control/ # Control components
│ ├── FSM/ # State machine states
│ ├── interface/ # Hardware interfaces
│ └── message/ # Message definitions
├── src/ # Source files
│ ├── main.cpp
│ ├── control/
│ ├── FSM/
│ └── interface/
├── model/ # ONNX models
├── motion_data/ # Motion reference data
└── CMakeLists.txt
This project is based on Unitree Robotics SDK2 framework.
Original framework: Copyright (c) 2020-2023, Unitree Robotics.Co.Ltd. All rights reserved.
Modified and extended by [ccrpRepo / ZSTU Robotics] © 2026
- Based on Unitree Robotics SDK2
- Motion data from LAFAN1 dataset
- ONNX Runtime for model inference