feat: implement _update_terrain_curriculum and fix _get_env_origins for heightfield/trimesh#84
Open
dcol91863 wants to merge 1 commit intounitreerobotics:mainfrom
Open
Conversation
…or heightfield/trimesh Closes unitreerobotics#81 The `_update_terrain_curriculum(env_ids)` method was referenced in the docstring of `reset_idx` but was never implemented, making terrain curriculum training a no-op even when `cfg.terrain.curriculum = True`. Changes ------- legged_gym/envs/base/legged_robot.py: 1. _get_env_origins() — heightfield / trimesh branch (new) Previously the method only created a flat grid regardless of terrain type, so `custom_origins` was always False and robots were never placed on the actual heightfield platforms. Now: - Sets `custom_origins = True` for heightfield and trimesh terrains. - Converts `terrain.env_origins` (numpy, rows=levels, cols=types) to a GPU tensor `self.terrain_origins` for fast index lookups. - Assigns each environment a random terrain type (column). - Initialises each environment to a random level in [0, max_init_terrain_level]. - Sets `self.env_origins` from the lookup table. 2. _update_terrain_curriculum(env_ids) — new method Promotes robots that traversed more than half a platform length (env_length / 2) during the episode to the next harder level, and demotes robots that fell short by one level. Levels are clamped to [0, num_rows - 1]. env_origins is refreshed for the reset envs. The method is a no-op on the very first call (before init_done) so the initial level assignment from _get_env_origins is preserved. 3. reset_idx() — wired up Added call to `_update_terrain_curriculum(env_ids)` when `cfg.terrain.curriculum` is True (placed before robot repositioning so the updated origin is used immediately). Also logs the mean terrain level to `extras["episode"]["terrain_level"]` for monitoring.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #81
The
_update_terrain_curriculum(env_ids)method was referenced in the docstring ofreset_idxbut was never implemented. Withcfg.terrain.curriculum = Trueand a heightfield/trimesh terrain, the curriculum was silently a no-op — all robots stayed on the same terrain level forever.This PR implements the full terrain curriculum loop in a single file (
legged_gym/envs/base/legged_robot.py).Changes
_get_env_origins()— heightfield/trimesh branchPreviously the method always created a flat grid and left
custom_origins = False, so robots were never actually placed on the heightfield platforms. Now:custom_origins = Trueforheightfieldandtrimeshmesh types.terrain.env_origins(numpy array, shape[num_rows, num_cols, 3]) to a GPU tensorself.terrain_originsfor fast indexed lookups.[0, max_init_terrain_level].self.env_originsfrom the lookup table immediately._update_terrain_curriculum(env_ids)— new methodCalled at the start of each
reset_idxwhencfg.terrain.curriculumisTrue:env_length / 2) to the next harder level.[0, num_rows - 1].self.env_origins[env_ids]from theterrain_originslookup table so that_reset_root_statesplaces the robot on the correct platform.The method is a no-op until
self.init_doneis set, preserving the initial level assignment from_get_env_origins.reset_idx()— wired up_update_terrain_curriculum(env_ids)before robot repositioning whencfg.terrain.curriculumisTrue.extras["episode"]["terrain_level"](mean across all envs) for training curve monitoring.Test plan
cfg.terrain.mesh_type = 'heightfield'andcfg.terrain.curriculum = True, train a G1/H1 policy — confirm robots spawn on terrain platforms andterrain_levelin tensorboard increases over training.cfg.terrain.mesh_type = 'plane'— confirm flat-grid path is unchanged.cfg.terrain.curriculum = Falsewith heightfield — confirm_update_terrain_curriculumis never called and robots still spawn correctly.