diff --git a/UPDATE.md b/UPDATE.md index bdad085..234c878 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -1,7 +1,9 @@ # 20260107 +## v0.1.7 +Fix bug: 修复`cfg.commands.dynamic_resample_commands=False`时, 未根据环境调整指令采样范围的问题 ## v0.1.6 1. 加入`go2_rem_cts`, student使用MoE结构, teacher使用普通CTS, 使用非共享权重和全goal输入 -2. 加入`move_down_by_acuumulated_xy_command`选择是否通过累计速度来降低等级 +2. 加入`move_down_by_accumulated_xy_command`选择是否通过累计速度来降低等级 3. 加入`dynamic_resample_commands`选择是否通过累计速度来动态调整指令采样下限 # 20260106 ## v0.1.5 diff --git a/legged_gym/envs/base/legged_robot.py b/legged_gym/envs/base/legged_robot.py index cc214fe..8ed4c4a 100644 --- a/legged_gym/envs/base/legged_robot.py +++ b/legged_gym/envs/base/legged_robot.py @@ -16,7 +16,7 @@ from legged_gym import LEGGED_GYM_ROOT_DIR from legged_gym.envs.base.base_task import BaseTask from legged_gym.utils.math import wrap_to_pi, quat_apply_yaw from legged_gym.utils.isaacgym_utils import get_euler_xyz as get_euler_xyz_in_tensor -from legged_gym.utils.isaacgym_utils import sample_disjoint_intervals +from legged_gym.utils.isaacgym_utils import sample_disjoint_intervals, sample_single_interval from legged_gym.utils.helpers import class_to_dict from .legged_robot_config import LeggedRobotCfg from legged_gym.utils.terrain import Terrain @@ -474,19 +474,36 @@ class LeggedRobot(BaseTask): self.commands[env_ids, 2] = (upper - lower) * r + lower self.commands_resampling_step[env_ids] = self.cfg.commands.resampling_time / self.dt else: - self.commands[env_ids, 0] = torch_rand_float(self.command_ranges["lin_vel_x"][0], self.command_ranges["lin_vel_x"][1], (len(env_ids), 1), device=self.device).squeeze(1) - self.commands[env_ids, 1] = torch_rand_float(self.command_ranges["lin_vel_y"][0], self.command_ranges["lin_vel_y"][1], (len(env_ids), 1), device=self.device).squeeze(1) + self.commands[env_ids, 0] = sample_single_interval( + env_ids, + self.env_command_ranges["lin_vel_x"][env_ids, 0], + self.env_command_ranges["lin_vel_x"][env_ids, 1], + self.device + ) + self.commands[env_ids, 1] = sample_single_interval( + env_ids, + self.env_command_ranges["lin_vel_y"][env_ids, 0], + self.env_command_ranges["lin_vel_y"][env_ids, 1], + self.device + ) if self.cfg.commands.heading_command: - self.commands[env_ids, 3] = torch_rand_float(self.command_ranges["heading"][0], self.command_ranges["heading"][1], (len(env_ids), 1), device=self.device).squeeze(1) + self.commands[env_ids, 3] = sample_single_interval( + env_ids, + self.env_command_ranges["heading"][env_ids, 0], + self.env_command_ranges["heading"][env_ids, 1], + self.device + ) else: - self.commands[env_ids, 2] = torch_rand_float(self.command_ranges["ang_vel_yaw"][0], self.command_ranges["ang_vel_yaw"][1], (len(env_ids), 1), device=self.device).squeeze(1) + self.commands[env_ids, 2] = sample_single_interval( + env_ids, + self.env_command_ranges["ang_vel_yaw"][env_ids, 0], + self.env_command_ranges["ang_vel_yaw"][env_ids, 1], + self.device + ) # set small commands to zero self.commands[env_ids, :2] *= (torch.norm(self.commands[env_ids, :2], dim=1) > 0.2).unsqueeze(1) - # set small commands to zero - # self.commands[env_ids, :2] *= (torch.norm(self.commands[env_ids, :2], dim=1) > 0.2).unsqueeze(1) - rand_prob = torch.rand(len(env_ids), device=self.device) min_prob, max_prob = 0.0, 0.0 # set limitation lin vel @@ -1129,7 +1146,7 @@ class LeggedRobot(BaseTask): distance = self.max_move_distance[env_ids] # robots that walked far enough progress to harder terains move_up = distance > self.terrain.env_length / 2 - if self.cfg.terrain.move_down_by_acuumulated_xy_command: + if self.cfg.terrain.move_down_by_accumulated_xy_command: move_down = (distance < torch.norm(self.commands_xy_accumulation[env_ids], dim=1) * (self.cfg.commands.resampling_time * (1 - self.zero_command_proba)) * 0.5) * ~move_up else: # robots that walked less than half of their required distance go to simpler terrains diff --git a/legged_gym/envs/base/legged_robot_config.py b/legged_gym/envs/base/legged_robot_config.py index 4365f9b..eb09fc0 100644 --- a/legged_gym/envs/base/legged_robot_config.py +++ b/legged_gym/envs/base/legged_robot_config.py @@ -38,7 +38,7 @@ class LeggedRobotCfg(BaseConfig): terrain_proportions = [0.1, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.1, 0.0] # trimesh only: slope_treshold = 0.75 # slopes above this threshold will be corrected to vertical surfaces - move_down_by_acuumulated_xy_command = False # move down the terrain curriculum based on accumulated xy command distance instead of absolute distance + move_down_by_accumulated_xy_command = False # move down the terrain curriculum based on accumulated xy command distance instead of absolute distance class commands: curriculum = False diff --git a/legged_gym/envs/go2/go2_config.py b/legged_gym/envs/go2/go2_config.py index 8546c20..e695f4e 100644 --- a/legged_gym/envs/go2/go2_config.py +++ b/legged_gym/envs/go2/go2_config.py @@ -93,7 +93,7 @@ class GO2Cfg(LeggedRobotCfg): # terrain_proportions = [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0] # terrain_proportions = [0.3, 0.3, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1] # terrain_proportions = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0] - move_down_by_acuumulated_xy_command = True # move down the terrain curriculum based on accumulated xy command distance instead of absolute distance + move_down_by_accumulated_xy_command = True # move down the terrain curriculum based on accumulated xy command distance instead of absolute distance class commands(LeggedRobotCfg.commands): curriculum = False diff --git a/legged_gym/envs/go2/go2_config_vanilla.py b/legged_gym/envs/go2/go2_config_vanilla.py index ff37c27..649076a 100644 --- a/legged_gym/envs/go2/go2_config_vanilla.py +++ b/legged_gym/envs/go2/go2_config_vanilla.py @@ -94,7 +94,7 @@ class GO2Cfg(LeggedRobotCfg): # terrain_proportions = [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0] # terrain_proportions = [0.3, 0.3, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1] # terrain_proportions = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0] - move_down_by_acuumulated_xy_command = False # move down the terrain curriculum based on accumulated xy command distance instead of absolute distance + move_down_by_accumulated_xy_command = False # move down the terrain curriculum based on accumulated xy command distance instead of absolute distance class commands(LeggedRobotCfg.commands): curriculum = False diff --git a/legged_gym/utils/isaacgym_utils.py b/legged_gym/utils/isaacgym_utils.py index 5c2be06..da59bf5 100644 --- a/legged_gym/utils/isaacgym_utils.py +++ b/legged_gym/utils/isaacgym_utils.py @@ -45,3 +45,11 @@ def sample_disjoint_intervals(env_ids, limit_bound, cfg_min, cfg_max, device): cfg_max - width_pos + (u - width_neg) ) return samples + +def sample_single_interval(env_ids, cfg_min, cfg_max, device): + """ + sample uniform distribution from [cfg_min, cfg_max] + """ + r = torch.rand(len(env_ids), device=device) + samples = cfg_min + r * (cfg_max - cfg_min) + return samples \ No newline at end of file diff --git a/setup.py b/setup.py index 2e10c31..5601547 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import find_packages from distutils.core import setup setup(name='go2_rl_gym', - version='0.1.5', + version='0.1.7', author='Wu Tianyang', license="MIT", packages=find_packages(),