v1.0.3; fix last_last_action reset, resample_command befor compute reward bugs; add self collisions
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
|
# 20260403
|
||||||
|
## v1.0.3
|
||||||
|
1. 修复last_last_action重置问题,修复resample_command在计算奖励前的问题
|
||||||
|
2. 将所有配置中加入自碰撞
|
||||||
# 20260325
|
# 20260325
|
||||||
## v1.0.2-rc2
|
## v1.0.2-rc2
|
||||||
1. 修复robogauge评估中返回None导致的训练中断问题
|
1. 修复robogauge评估中返回None导致的训练中断问题
|
||||||
|
2. 将自碰撞打开,真机表现更好
|
||||||
# 20260126
|
# 20260126
|
||||||
## v1.0.2-rc1
|
## v1.0.2-rc1
|
||||||
1. 修改高速移动的训练文件到最终版,删除配置中无用注释
|
1. 修改高速移动的训练文件到最终版,删除配置中无用注释
|
||||||
|
|||||||
@@ -129,6 +129,9 @@ class LeggedRobot(BaseTask):
|
|||||||
# compute observations, rewards, resets, ...
|
# compute observations, rewards, resets, ...
|
||||||
self.check_termination()
|
self.check_termination()
|
||||||
self.compute_reward()
|
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()
|
env_ids = self.reset_buf.nonzero(as_tuple=False).flatten()
|
||||||
self.reset_idx(env_ids)
|
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.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_actions[:] = self.actions[:]
|
||||||
self.last_dof_vel[:] = self.dof_vel[:]
|
self.last_dof_vel[:] = self.dof_vel[:]
|
||||||
self.last_root_vel[:] = self.root_states[:, 7:13]
|
self.last_root_vel[:] = self.root_states[:, 7:13]
|
||||||
@@ -216,6 +220,7 @@ class LeggedRobot(BaseTask):
|
|||||||
# reset buffers
|
# reset buffers
|
||||||
self.actions[env_ids] = 0.
|
self.actions[env_ids] = 0.
|
||||||
self.last_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.last_dof_vel[env_ids] = 0.
|
||||||
self.feet_air_time[env_ids] = 0.
|
self.feet_air_time[env_ids] = 0.
|
||||||
self.episode_length_buf[env_ids] = 0
|
self.episode_length_buf[env_ids] = 0
|
||||||
@@ -403,20 +408,8 @@ class LeggedRobot(BaseTask):
|
|||||||
|
|
||||||
def _post_physics_step_callback(self):
|
def _post_physics_step_callback(self):
|
||||||
""" Callback called before computing terminations, rewards, and observations
|
""" 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:
|
if self.cfg.terrain.measure_heights:
|
||||||
self.measured_heights = self._get_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]
|
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):
|
def _compute_torques(self, actions):
|
||||||
""" Compute torques from actions.
|
""" Compute torques from actions.
|
||||||
Actions can be interpreted as position or velocity targets given to a PD controller, or directly as scaled torques.
|
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.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.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_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_dof_vel = torch.zeros_like(self.dof_vel)
|
||||||
self.last_root_vel = torch.zeros_like(self.root_states[:, 7:13])
|
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
|
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):
|
def _reward_action_smoothness(self):
|
||||||
# a_t - 2a_{t-1} + a_{t-2}
|
# 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)
|
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
|
return rew
|
||||||
|
|
||||||
def _reward_dof_power(self):
|
def _reward_dof_power(self):
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class GO2Cfg(LeggedRobotCfg):
|
|||||||
foot_name = "foot"
|
foot_name = "foot"
|
||||||
penalize_contacts_on = ["thigh", "calf"]
|
penalize_contacts_on = ["thigh", "calf"]
|
||||||
terminate_after_contacts_on = ["base"]
|
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):
|
class rewards(LeggedRobotCfg.rewards):
|
||||||
soft_dof_pos_limit = 0.9
|
soft_dof_pos_limit = 0.9
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ class GO2Cfg(LeggedRobotCfg):
|
|||||||
'heading': [-1.57, 1.57], # min max [rad]
|
'heading': [-1.57, 1.57], # min max [rad]
|
||||||
}, { # list for command range curriculums at specific training iterations
|
}, { # list for command range curriculums at specific training iterations
|
||||||
'iter': 40000, # training iteration at which the command ranges are updated
|
'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]
|
'lin_vel_y': [-0.5, 0.5], # min max [m/s]
|
||||||
'ang_vel_yaw': [-1.0, 1.0], # min max [rad/s]
|
'ang_vel_yaw': [-1.0, 1.0], # min max [rad/s]
|
||||||
'heading': [-1.57, 1.57], # min max [rad]
|
'heading': [-1.57, 1.57], # min max [rad]
|
||||||
@@ -181,7 +181,7 @@ class GO2Cfg(LeggedRobotCfg):
|
|||||||
foot_name = "foot"
|
foot_name = "foot"
|
||||||
penalize_contacts_on = ["thigh", "calf"]
|
penalize_contacts_on = ["thigh", "calf"]
|
||||||
terminate_after_contacts_on = ["base"]
|
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):
|
class rewards(LeggedRobotCfg.rewards):
|
||||||
soft_dof_pos_limit = 0.9
|
soft_dof_pos_limit = 0.9
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ class GO2Cfg(LeggedRobotCfg):
|
|||||||
foot_name = "foot"
|
foot_name = "foot"
|
||||||
penalize_contacts_on = ["thigh", "calf"]
|
penalize_contacts_on = ["thigh", "calf"]
|
||||||
terminate_after_contacts_on = ["base"]
|
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):
|
class rewards(LeggedRobotCfg.rewards):
|
||||||
soft_dof_pos_limit = 0.9
|
soft_dof_pos_limit = 0.9
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ class GO2Cfg(LeggedRobotCfg):
|
|||||||
foot_name = "foot"
|
foot_name = "foot"
|
||||||
penalize_contacts_on = ["thigh", "calf"]
|
penalize_contacts_on = ["thigh", "calf"]
|
||||||
terminate_after_contacts_on = ["base"]
|
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):
|
class rewards(LeggedRobotCfg.rewards):
|
||||||
soft_dof_pos_limit = 0.9
|
soft_dof_pos_limit = 0.9
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import find_packages
|
|||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
setup(name='go2_rl_gym',
|
setup(name='go2_rl_gym',
|
||||||
version='1.0.2',
|
version='1.0.3',
|
||||||
author='Wu Tianyang',
|
author='Wu Tianyang',
|
||||||
license="MIT",
|
license="MIT",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
|
|||||||
Reference in New Issue
Block a user