From ef3ccb2e1a390ffc37cbed1e0bebbceda5bb5b89 Mon Sep 17 00:00:00 2001 From: 8x54zj-m <8x54zj-m@motrixlab.local> Date: Wed, 1 Jul 2026 10:51:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20NaN=20protection=20=E2=80=94=20dof=20nan?= =?UTF-8?q?=5Fto=5Fnum,=20physics=20reset=20on=20crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- motrix_envs/src/motrix_envs/locomotion/go1/dreamwaq.py | 7 +++++++ motrix_envs/src/motrix_envs/np/env.py | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/motrix_envs/src/motrix_envs/locomotion/go1/dreamwaq.py b/motrix_envs/src/motrix_envs/locomotion/go1/dreamwaq.py index ce09d4a..1917c52 100644 --- a/motrix_envs/src/motrix_envs/locomotion/go1/dreamwaq.py +++ b/motrix_envs/src/motrix_envs/locomotion/go1/dreamwaq.py @@ -326,6 +326,13 @@ class DreamWaQTask(Go1WalkTask): def update_observation(self, state): data = state.data + # 清理物理崩溃残留的 NaN/Inf(仅在检测到时才修改,避免无谓开销) + dv = data.dof_vel + if np.any(~np.isfinite(dv)): + data.set_dof_vel(np.nan_to_num(np.array(dv), nan=0.0, posinf=0.0, neginf=0.0)) + dp = data.dof_pos + if np.any(~np.isfinite(dp)): + data.set_dof_pos(np.nan_to_num(np.array(dp), nan=0.0, posinf=0.0, neginf=0.0), self._model) obs = self._get_obs(data, state.info) # 更新历史缓冲区 diff --git a/motrix_envs/src/motrix_envs/np/env.py b/motrix_envs/src/motrix_envs/np/env.py index ea18335..8f2743c 100644 --- a/motrix_envs/src/motrix_envs/np/env.py +++ b/motrix_envs/src/motrix_envs/np/env.py @@ -187,10 +187,12 @@ class NpEnv(ABEnv): for _ in range(self._cfg.sim_substeps): self._model.step(self._state.data) except Exception as e: - # Rust panic / MotrixSim 物理崩溃 → 标记所有 env 为终止 + # Rust panic / 物理崩溃 → 标记终止 + 清除腐蚀数据 n = self._state.data.shape[0] self._state.terminated[:] = True self._state.reward[:] = 0.0 + # 强制重置物理状态,防止 NaN 传播到 observations/rewards + self._state.data.reset(self._model) if not hasattr(self, '_physics_crash_count'): self._physics_crash_count = 0 self._physics_crash_count += 1