v1.0.3; fix last_last_action reset, resample_command befor compute reward bugs; add self collisions
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user