diff --git a/UPDATE.md b/UPDATE.md index 192fa6e..334903a 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -1,6 +1,11 @@ +# 20260403 +## v1.0.3 +1. 修复last_last_action重置问题,修复resample_command在计算奖励前的问题 +2. 将所有配置中加入自碰撞 # 20260325 ## v1.0.2-rc2 1. 修复robogauge评估中返回None导致的训练中断问题 +2. 将自碰撞打开,真机表现更好 # 20260126 ## v1.0.2-rc1 1. 修改高速移动的训练文件到最终版,删除配置中无用注释 diff --git a/legged_gym/envs/base/legged_robot.py b/legged_gym/envs/base/legged_robot.py index 5ffed46..db0830c 100644 --- a/legged_gym/envs/base/legged_robot.py +++ b/legged_gym/envs/base/legged_robot.py @@ -129,6 +129,9 @@ class LeggedRobot(BaseTask): # compute observations, rewards, resets, ... self.check_termination() self.compute_reward() + # resample commands must after reward computing + resampling_env_ids = ((self.commands_resampling_step <= 0.0) * (self.episode_length_buf < self.max_episode_length - 1)).nonzero(as_tuple=False).flatten() + self._resample_commands(resampling_env_ids) env_ids = self.reset_buf.nonzero(as_tuple=False).flatten() self.reset_idx(env_ids) @@ -137,6 +140,7 @@ class LeggedRobot(BaseTask): self.compute_observations() # in some cases a simulation step might be required to refresh some obs (for example body positions) + self.last_last_actions[:] = self.last_actions[:] self.last_actions[:] = self.actions[:] self.last_dof_vel[:] = self.dof_vel[:] self.last_root_vel[:] = self.root_states[:, 7:13] @@ -216,6 +220,7 @@ class LeggedRobot(BaseTask): # reset buffers self.actions[env_ids] = 0. self.last_actions[env_ids] = 0. + self.last_last_actions[env_ids] = 0. self.last_dof_vel[env_ids] = 0. self.feet_air_time[env_ids] = 0. self.episode_length_buf[env_ids] = 0 @@ -403,20 +408,8 @@ class LeggedRobot(BaseTask): def _post_physics_step_callback(self): """ Callback called before computing terminations, rewards, and observations - Default behaviour: Compute ang vel command based on target and heading, compute measured terrain heights and randomly push robots + Default behaviour: Compute measured terrain heights and randomly push robots """ - # env_ids = (self.episode_length_buf % int(self.cfg.commands.resampling_time / self.dt)==0).nonzero(as_tuple=False).flatten() - resampling_env_ids = ((self.commands_resampling_step <= 0.0) * (self.episode_length_buf < self.max_episode_length - 1)).nonzero(as_tuple=False).flatten() - self._resample_commands(resampling_env_ids) - if self.cfg.commands.heading_command: - mask = (self.stop_heading == 0.0) - forward = quat_apply(self.base_quat[mask], self.forward_vec[mask]) - heading = torch.atan2(forward[:, 1], forward[:, 0]) - self.commands[mask, 2] = torch.clip( - 0.5*wrap_to_pi(self.commands[mask, 3] - heading), - self.env_command_ranges["ang_vel_yaw"][:, 0], - self.env_command_ranges["ang_vel_yaw"][:, 1] - ) if self.cfg.terrain.measure_heights: self.measured_heights = self._get_heights() @@ -591,6 +584,17 @@ class LeggedRobot(BaseTask): self.commands_xy_accumulation[env_ids] += self.commands[env_ids, :2] + if self.cfg.commands.heading_command: + heading_env_ids = env_ids[self.stop_heading[env_ids] == 0.0] + if len(heading_env_ids) > 0: + forward = quat_apply(self.base_quat[heading_env_ids], self.forward_vec[heading_env_ids]) + heading = torch.atan2(forward[:, 1], forward[:, 0]) + self.commands[heading_env_ids, 2] = torch.clip( + 0.5 * wrap_to_pi(self.commands[heading_env_ids, 3] - heading), + self.env_command_ranges["ang_vel_yaw"][heading_env_ids, 0], + self.env_command_ranges["ang_vel_yaw"][heading_env_ids, 1] + ) + def _compute_torques(self, actions): """ Compute torques from actions. Actions can be interpreted as position or velocity targets given to a PD controller, or directly as scaled torques. @@ -807,6 +811,7 @@ class LeggedRobot(BaseTask): self.d_gains = torch.zeros(self.num_actions, dtype=torch.float, device=self.device, requires_grad=False) self.actions = torch.zeros(self.num_envs, self.num_actions, dtype=torch.float, device=self.device, requires_grad=False) self.last_actions = torch.zeros(self.num_envs, self.num_actions, dtype=torch.float, device=self.device, requires_grad=False) + self.last_last_actions = torch.zeros(self.num_envs, self.num_actions, dtype=torch.float, device=self.device, requires_grad=False) self.last_dof_vel = torch.zeros_like(self.dof_vel) self.last_root_vel = torch.zeros_like(self.root_states[:, 7:13]) self.commands = torch.zeros(self.num_envs, self.cfg.commands.num_commands, dtype=torch.float, device=self.device, requires_grad=False) # x vel, y vel, yaw vel, heading @@ -1372,10 +1377,7 @@ class LeggedRobot(BaseTask): def _reward_action_smoothness(self): # a_t - 2a_{t-1} + a_{t-2} - if not hasattr(self, 'last_last_actions'): - self.last_last_actions = torch.zeros_like(self.last_actions) rew = torch.sum((self.actions - 2 * self.last_actions + self.last_last_actions).pow(2), dim=1) - self.last_last_actions[:] = self.last_actions[:] return rew def _reward_dof_power(self): diff --git a/legged_gym/envs/go2/go2_config.py b/legged_gym/envs/go2/go2_config.py index 778d40b..3c3f326 100644 --- a/legged_gym/envs/go2/go2_config.py +++ b/legged_gym/envs/go2/go2_config.py @@ -151,7 +151,7 @@ class GO2Cfg(LeggedRobotCfg): foot_name = "foot" penalize_contacts_on = ["thigh", "calf"] terminate_after_contacts_on = ["base"] - self_collisions = 1 # 1 to disable, 0 to enable...bitwise filter + self_collisions = 0 # 1 to disable, 0 to enable...bitwise filter class rewards(LeggedRobotCfg.rewards): soft_dof_pos_limit = 0.9 diff --git a/legged_gym/envs/go2/go2_config_fast_flat_move.py b/legged_gym/envs/go2/go2_config_fast_flat_move.py index 23d9ddc..7dc873d 100644 --- a/legged_gym/envs/go2/go2_config_fast_flat_move.py +++ b/legged_gym/envs/go2/go2_config_fast_flat_move.py @@ -146,7 +146,7 @@ class GO2Cfg(LeggedRobotCfg): 'heading': [-1.57, 1.57], # min max [rad] }, { # list for command range curriculums at specific training iterations 'iter': 40000, # training iteration at which the command ranges are updated - 'lin_vel_x': [-2.0, 4.2], # min max [m/s] + 'lin_vel_x': [-2.0, 4.5], # min max [m/s] 'lin_vel_y': [-0.5, 0.5], # min max [m/s] 'ang_vel_yaw': [-1.0, 1.0], # min max [rad/s] 'heading': [-1.57, 1.57], # min max [rad] @@ -181,7 +181,7 @@ class GO2Cfg(LeggedRobotCfg): foot_name = "foot" penalize_contacts_on = ["thigh", "calf"] terminate_after_contacts_on = ["base"] - self_collisions = 1 # 1 to disable, 0 to enable...bitwise filter + self_collisions = 0 # 1 to disable, 0 to enable...bitwise filter class rewards(LeggedRobotCfg.rewards): soft_dof_pos_limit = 0.9 diff --git a/legged_gym/envs/go2/go2_config_vanilla.py b/legged_gym/envs/go2/go2_config_vanilla.py index a7bd616..8d8ed6d 100644 --- a/legged_gym/envs/go2/go2_config_vanilla.py +++ b/legged_gym/envs/go2/go2_config_vanilla.py @@ -165,7 +165,7 @@ class GO2Cfg(LeggedRobotCfg): foot_name = "foot" penalize_contacts_on = ["thigh", "calf"] terminate_after_contacts_on = ["base"] - self_collisions = 1 # 1 to disable, 0 to enable...bitwise filter + self_collisions = 0 # 1 to disable, 0 to enable...bitwise filter class rewards(LeggedRobotCfg.rewards): soft_dof_pos_limit = 0.9 diff --git a/legged_gym/envs/go2/go2_config_vanilla_with_dynamic_cmd.py b/legged_gym/envs/go2/go2_config_vanilla_with_dynamic_cmd.py index 4473a69..ae0a3c6 100644 --- a/legged_gym/envs/go2/go2_config_vanilla_with_dynamic_cmd.py +++ b/legged_gym/envs/go2/go2_config_vanilla_with_dynamic_cmd.py @@ -165,7 +165,7 @@ class GO2Cfg(LeggedRobotCfg): foot_name = "foot" penalize_contacts_on = ["thigh", "calf"] terminate_after_contacts_on = ["base"] - self_collisions = 1 # 1 to disable, 0 to enable...bitwise filter + self_collisions = 0 # 1 to disable, 0 to enable...bitwise filter class rewards(LeggedRobotCfg.rewards): soft_dof_pos_limit = 0.9 diff --git a/setup.py b/setup.py index 6545e11..5854aeb 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='1.0.2', + version='1.0.3', author='Wu Tianyang', license="MIT", packages=find_packages(),