最近换自己的机器人去跑宇树的算法,结果遇到了这样的提示。然后及进行解决,

最开始是说学习率太高,然后我就将学习率降低——没有用

有一个朋友说检查状态空间,看是哪个数据没有,那就将数据打印出来

在envs文件中,找到状态空间的相关代码,添加打印

    def compute_observations(self):
        """ Computes observations
        """
        print(f"Base angular velocity: {self.base_ang_vel}")
        print(f"Projected gravity: {self.projected_gravity}")
        print(f"Commands: {self.commands[:, :3]}")
        print(f"DOF positions: {self.dof_pos}")
        print(f"DOF velocities: {self.dof_vel}")
        print(f"Actions: {self.actions}")

        sin_phase = torch.sin(2 * np.pi * self.phase).unsqueeze(1)
        cos_phase = torch.cos(2 * np.pi * self.phase).unsqueeze(1)
        self.obs_buf = torch.cat((self.base_ang_vel * self.obs_scales.ang_vel,
                                  self.projected_gravity,
                                  self.commands[:, :3] * self.commands_scale,
                                  (self.dof_pos - self.default_dof_pos) * self.obs_scales.dof_pos,
                                  self.dof_vel * self.obs_scales.dof_vel,
                                  self.actions,
                                  sin_phase,
                                  cos_phase
                                  ), dim=-1)
        assert not torch.any(torch.isnan(self.obs_buf)), "NaN detected in observations!"
        assert not torch.any(torch.isinf(self.obs_buf)), "Inf detected in observations!"
        self.privileged_obs_buf = torch.cat((self.base_lin_vel * self.obs_scales.lin_vel,
                                             self.base_ang_vel * self.obs_scales.ang_vel,
                                             self.projected_gravity,
                                             self.commands[:, :3] * self.commands_scale,
                                             (self.dof_pos - self.default_dof_pos) * self.obs_scales.dof_pos,
                                             self.dof_vel * self.obs_scales.dof_vel,
                                             self.actions,
                                             sin_phase,
                                             cos_phase
                                             ), dim=-1)

然后就可以打印各个数据,很好的查看办法。我从第一类开始,打印的是0,后面几乎都是nan。

再次向前溯源,我的第一个数据是self.base_ang_vel,那就再向前

 def _init_foot(self):
        self.feet_num = len(self.feet_indices)

        rigid_body_state = self.gym.acquire_rigid_body_state_tensor(self.sim)

        print(f"Rigid body state: {rigid_body_state}")

        self.rigid_body_states = gymtorch.wrap_tensor(rigid_body_state)

        print(f"Wrapped rigid body states: {self.rigid_body_states}")

        self.rigid_body_states_view = self.rigid_body_states.view(self.num_envs, -1, 13)


        self.feet_state = self.rigid_body_states_view[:, self.feet_indices, :]
        self.feet_pos = self.feet_state[:, :, :3]
        self.feet_vel = self.feet_state[:, :, 7:10]
 def update_feet_state(self):
        self.gym.refresh_rigid_body_state_tensor(self.sim)
        print(f"Updated rigid body state: {self.rigid_body_states}")

        self.feet_state = self.rigid_body_states_view[:, self.feet_indices, :]
        self.feet_pos = self.feet_state[:, :, :3]
        self.feet_vel = self.feet_state[:, :, 7:10]

继续打印数据,发现这里还是nan,就说明仿真平台就没有采到数据

我询问了万能的AI,他说看看URDF文件有没有问题,我就去寻找。对比之前的URDF文件,我发现,我把角速度设置成了0...

之后就是修改URDF文件

 lower="-0.5"
      upper="0.5"
      effort="20"
       velocity="12"

再次尝试就好啦!

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐