Humanoid motion control and reinforcement learning for Unitree G1.
This project requires a high-performance Ubuntu workstation. You MUST ensure the base holosoma framework is fully configured before proceeding.
- NVIDIA GPU (RTX 3090/4090 recommended)
- NVIDIA Drivers & CUDA Toolkit (12.x recommended)
- Python 3.10+ (Conda environment highly recommended)
- Holosoma Environment: Verify that you can run basic Holosoma examples first.
git clone <repo-url>
cd g1-motion-control
./scripts/bootstrap.sh # Install control dependenciesHolosoma is now integrated into this repository as a local library. Navigate to the directory and complete the environment initialization:
cd third_party/holosoma/scripts
# Option A: Full IsaacSim Installation (Required for training)
./setup_isaacsim.sh
# Option B: Full MuJoCo Installation (For fast simulation inference)
./setup_mujoco.sh
# Option C: Inference Environment (For run_multi_policy_sim2sim.py)
./setup_inference.shNote: If you encounter permission or path issues, please refer to third_party/holosoma/README.md.
# Activate IsaacSim environment and start training
cd third_party/holosoma
source scripts/source_isaacsim_setup.sh
python src/holosoma/holosoma/train_agent.py \
exp:g1-29dof-robust \
reward:g1-29dof-loco-robust-refined \
--training.num-envs 8192cd third_party/holosoma && source scripts/source_mujoco_setup.sh
python src/holosoma/holosoma/run_sim.py robot:g1-29dof terrain:terrain_locomotion_planecd third_party/holosoma && source scripts/source_inference_setup.sh
python3 "../my work space/run_multi_policy_sim2sim.py" <path_to_onnx>- MuJoCo Window: Press
8to lower gantry,9to remove gantry. - Controller Terminal: Press
]to activate policy. - Mode Switch: Number keys
1(Stand),2(Walk). - Real-time Movement:
โ โ โ โ: Move (Forward/Back/Left/Right)Q / E: Rotate (Left/Right)Z: Zero velocity
model_22200.onnx: Latest refined locomotion (Stable gait & Upright posture).model_39999.onnx: WBT policy for crawling and motion tracking.
configs/: G1 configurationsmy work space/: Inference scripts & training logs (Contains selected ONNX models)scripts/: Utility scriptsthird_party/:holosoma/: Core framework (Locally customized, not synced to upstream)beyond_mimic/: [Future] Motion imitation frameworkgr00t/: [Future] NVIDIA GR00T foundation model integrationtwist2/: [Future] Locomotion controlgmr/: [Future] Gaussian Mixture Regression/Roboticscommon_assets/: Shared robot URDFs and meshes
Since holosoma is now a local library, you should place your custom logic within its package structure to ensure the dynamic loading system works correctly.
| Component | Target Path |
|---|---|
| Reward Functions (Logic) | third_party/holosoma/src/holosoma/holosoma/managers/reward/terms/ |
| Reward Configs (Weights) | third_party/holosoma/src/holosoma/holosoma/config_values/loco/g1/reward.py |
| Experiment Presets | third_party/holosoma/src/holosoma/holosoma/config_values/loco/g1/experiment.py |
| Environment/Obs/Action DIY | third_party/holosoma/src/holosoma/holosoma/config_values/loco/g1/ |
- Define your reward functions in
managers/reward/terms/. - Reference them in
config_values/loco/g1/reward.pyby creating a newRewardManagerCfg. - Create a new
ExperimentConfiginexperiment.py(e.g.,g1_29dof_diy). - Start training:
python src/holosoma/holosoma/train_agent.py exp:g1-29dof-diy
To maintain a clean and manageable workspace while integrating multiple complex repositories, we follow these principles:
All third_party projects are "vendored" into this repository. This means:
- We do not use Git Submodules for active development.
- Local modifications are encouraged and committed directly to the main repository.
- Version history of the original repo is removed to keep the workspace lightweight.
Each major framework (gr00t, holosoma, beyond_mimic) may require conflicting dependency versions (Isaac Sim 2023 vs 4.0, different PyTorch versions, etc.).
- Rule: Use separate Conda environments or Docker containers for each major integration.
- Environment-specific setup scripts should be placed in
scripts/envs/.
Avoid duplicating large STL/Meshes across different third_party folders.
- Store the "Source of Truth" for G1 URDF/Meshes in
third_party/common_assets/. - Use soft links (
ln -s) or config path overrides to point external frameworks to these shared assets.
- Git LFS: Large
.ptand.onnxfiles should be tracked via Git LFS or kept outside the main git history if they are intermediate training results. - Redundancy Cleanup: Intermediate models are periodically pruned (keeping only start and final milestones) to save space.
Convert BVH files to .npy format for retargeting:
cd third_party/holosoma/src/holosoma_retargeting
source ../../scripts/source_retargeting_setup.sh
cd data_utils
python extract_global_positions.py \
--input_dir <bvh_directory> \
--output_dir <output_directory>Convert human motion to robot motion:
cd third_party/holosoma/src/holosoma_retargeting
source ../../scripts/source_retargeting_setup.sh
python examples/robot_retarget.py \
--data_path <npy_directory> \
--task-type robot_only \
--task-name <sequence_name> \
--data_format lafan \
--task-config.ground-range -10 10 \
--save_dir demo_results/g1/robot_only/<output_dir> \
--retargeter.foot-sticking-tolerance 0.02Convert retargeted .npz to training format:
cd third_party/holosoma/src/holosoma_retargeting
source ../../scripts/source_retargeting_setup.sh
python data_conversion/convert_data_format_mj.py \
--input_file <retargeted_file>.npz \
--output_fps 50 \
--output_name <output_file>.npz \
--data_format lafan \
--object_name "ground" \
--onceExtract specific frame range from motion file. Note: Edit the script to set input/output paths and frame range:
cd third_party/holosoma/src/holosoma_retargeting
source ../../scripts/source_retargeting_setup.sh
# Edit trim_npz.py to set input_file, output_file, start_frame, end_frame
python trim_npz.pyExample script configuration:
input_file = "converted_res/robot_only/motion.npz"
output_file = "converted_res/robot_only/motion_trimmed.npz"
start_frame = 10700
end_frame = 11700Convert .pkl motion files to training .npz format:
cd third_party/holosoma/src/holosoma_retargeting
source ../../scripts/source_retargeting_setup.sh
python convert_pkl_to_npz.py \
--pkl_path <input_file>.pkl \
--output_path <output_file>.npz \
--xml_path models/g1/g1_29dof.xml \
--fps <fps> # Optional: override fps if not in pklThis script:
- Loads
.pklfile withroot_pos,root_rot,dof_posfields - Uses MuJoCo forward kinematics to compute body positions
- Converts to standard
.npzformat with all required fields - Computes velocities via numerical differentiation
Add interpolated frames from reference initial pose to motion start. Note: Edit the script to set file paths and interpolation duration:
python prepend_interpolation.pyScript configuration:
reference_file = "converted_res/robot_only/original_motion.npz" # Extract frame 0 as reference
input_file = "converted_res/robot_only/motion_trimmed.npz" # Motion to prepend
output_file = "converted_res/robot_only/motion_with_interp.npz"
num_interp_frames = 13 # 0.25s at 50fps
reference_frame_idx = 0 # Use frame 0 from reference fileThis script:
- Extracts initial pose from reference motion file (frame 0)
- Interpolates from reference pose to motion start
- Preserves target frame x,y position to avoid horizontal drift
- Only interpolates z position, orientation, and joint angles
Add interpolated frames at both start and end of motion. Note: Edit the script to set file paths:
python add_interpolation_both_ends.pyScript configuration:
default_pose_file = "converted_res/robot_only/default_pose.npz" # Default pose (single frame)
input_file = "converted_res/robot_only/motion_trimmed.npz"
output_file = "converted_res/robot_only/motion_with_interp.npz"
num_interp_frames = 13 # 0.25s at 50fps (auto-calculated from fps)This script:
- Adds interpolation from default pose to motion start
- Adds interpolation from motion end to default pose
- Preserves x,y position to avoid horizontal drift
- Only interpolates z position, orientation, and joint angles
View motion sequence in browser:
cd third_party/holosoma/src/holosoma_retargeting
source ../../scripts/source_retargeting_setup.sh
python data_conversion/viser_body_vel_player.py \
--npz_path <motion_file>.npz \
--robot_urdf models/g1/g1_29dof.urdfOpen the displayed URL (usually http://localhost:8080) to:
- Playback motion sequence
- Control playback with slider
- View body positions and velocity vectors
- Toggle mesh and velocity arrow display
cd third_party/holosoma
source scripts/source_isaacsim_setup.sh
python src/holosoma/holosoma/train_agent.py \
exp:g1-29dof-wbt \
logger:wandb \
--command.setup_terms.motion_command.params.motion_config.motion_file=<absolute_or_relative_path_to_motion_file>.npzNote:
- Use absolute path or path relative to project root for
motion_file - Training uses
enable_default_pose_prepend=Trueby default, which adds 2s interpolation from config default pose to motion start - If motion file already has initial pose interpolation, this provides smooth double transition