# Repository Briefing: leggedrobotics/terrain-grounded-imagination
> Source: https://repoforai.com/repo/leggedrobotics/terrain-grounded-imagination (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/leggedrobotics/terrain-grounded-imagination
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: MIT
- **Engineering Health**: A (76/100 · Maintenance 35/35 · Adoption 10/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-01
- **Deployment / Stack Signals**: GPU, CLI
- **Momentum**: 258 ★ total (+9 24h / +110 7d) · 14 forks
- **When to Use**: Best for: Robotics teams with an Isaac Lab GPU setup that want to reproduce terrain-aware locomotion experiments or compare model-based policy gradients against PPO on G1 or ANYmal-D. Skip if: You need a ready-to-deploy robot controller, cannot run the Isaac Lab stack locally, or lack terrain queries and contact definitions for the robot you plan to port.

## Overview
```text
### Architecture & Core Mechanics
Terrain-Grounded Imagination (TGI) is a locomotion trainer, not an LLM inference engine. Simulator transitions train an action- and terrain-conditioned world model to predict the robot’s next state and contact forces. Policy updates start from simulator states and backpropagate returns through 32 imagined steps (0.64 s), bootstrapping with a critic. At a poorly supported imagined touchdown, the gradient path is cut and the critic takes over earlier. A success-guided curriculum samples terrain types and difficulty levels.

The key design choice is to learn dynamics, not terrain. Differentiable queries of simulator geometry supply terrain information to the world model, rewards, terminations, critic, and perception, so gaps and edges do not depend on a learned reconstruction. This is the integration boundary: perception can vary provided it reads terrain through those lookups. The Python workspace separates G1 environments and foothold prediction (`fpm/`) from 2.5D G1 training (`tgi/`), 3D G1 training (`tgi_g1_3d/`), and 3D ANYmal-D training (`tgi_anymal/`).

### Key Capabilities & Differentiators
The 2.5D G1 task tracks velocity commands over stairs, gaps, pits, and stepping stones, using pelvis and sole heightmaps and foothold-gated perception. The 3D G1 task uses goal commands and adds overhangs. Its policy sees a 32 × 32 × 40 voxel grid at 5 cm resolution from two torso LiDARs. The dynamics and task logic query a separate layered distance field at 15 support points per sole and 53 body collision spheres, allowing them to distinguish footing from overhead clearance.

In its 2,048-episode evaluation with no pushes, the 3D G1 policy recorded 99.7% success and a 0.15% fall rate; success required surviving 20 seconds and reaching the first goal in time. ANYmal-D predicts foot and body contact forces, including knee contact during climbs. It recorded 92.4% success in one 10,270-episode evaluation and 91.0 ± 2.1% over five seeds, with success defined as finishing within 0.5 m of the goal at 8 seconds. In the single-run breakdown, climb-up success was 78.1% and stepping-stone success was 82.1%. The two robots’ headline rates are not directly comparable.

### Trade-offs & Limitations
Compared with direct simulator PPO, TGI adds a learned dynamics model and differentiable terrain queries in exchange for a path to optimize the policy by backpropagating through imagined dynamics. It still requires simulator transitions. Reading terrain directly avoids having to learn the geometry of gaps and overhangs, but it does not fix errors in predicted motion or forces. The short horizon and touchdown gradient cut limit reliance on those predictions; they also leave the critic responsible for more of the return when the gradient is cut early.

The 2.5D heightmap path suits terrain describable by a single height per location; overhangs require the richer 3D representation used here, with separate distance-field and LiDAR processing. Adoption is easiest when the existing robot, simulator, and task definitions match. A port needs compatible geometry queries and task logic as well as fitted dynamics, not just a new robot asset. For a decision against PPO, compare end-to-end training cost and matched evaluation protocols, and treat cross-simulator tests or hardware demonstrations as distinct from the reported simulation success rates.

### Hardware & Deployment Guide
The tested stack is Linux with Isaac Lab 3.0.0, Isaac Sim 6.1, Newton 1.6.1, and PyTorch 2.11. In the Isaac Lab Python environment, install `fpm` with `pip install -e fpm --no-deps`, then install the task packages in editable mode. Run `scripts/convert_g1_usd.py` once from the chosen G1 task directory, then `scripts/train.py --log_dir logs/<run_name>`. ANYmal-D starts with its own `scripts/train.py`. These are local GPU jobs. The documented 2.5D G1 and ANYmal-D runs took about 7.5 and 5.6 hours respectively on an RTX PRO 6000; the 3D G1 run took 12.1 hours on a 16 GB RTX 5080. These are reference runs, not minimum requirements.

For 2.5D G1, `scripts/export.py --ckpt` produces an `fpm`-format artifact, which can be played through `fpm/scripts/play.py` or tested with `scripts/sim2sim.py --export_dir` in MuJoCo. `scripts/isaac_eval.sh` is a 1,100-step check with startup randomization enabled, not the full 3,300-step protocol with startup randomization zeroed. For the full test, use `--save_results` and compute the fraction of episodes that both avoid falling and cover at least 70% of commanded distance; the script’s printed “success” is mean distance share instead. There is no tagged release to pin, so record the commit and simulator versions used for each run.
```

## Key Capabilities
```text
- Dynamics and geometry: Learned next-state and force predictions are coupled to differentiable queries of simulator terrain.
- Policy update: Backpropagation spans up to 32 steps (0.64 s); the critic takes over at the horizon or at a poorly supported imagined touchdown.
- 2.5D perception: G1 uses pelvis and sole heightmaps and foothold-gated observations; the impact penalty activates above 450 N.
- 3D perception: G1 uses a 32 × 32 × 40 LiDAR voxel grid at 5 cm resolution, while support and collision checks use a layered distance field.
- Body contacts: The ANYmal-D model predicts foot and body contact forces, including knee contact during climbs; foot forces above 600 N are penalized.
- Evaluation: The G1 export uses the `fpm` format; MuJoCo transfer and Isaac locomotion validation are separate CLI paths.
```

## Quick Start / Clone
```bash
git clone https://github.com/leggedrobotics/terrain-grounded-imagination
cd terrain-grounded-imagination
pip install -e fpm --no-deps
pip install -e tgi
pip install -e tgi_g1_3d
pip install -e tgi_anymal
```
