Fix action smoothing history and viewer timing control

This commit is contained in:
8x54zj-m
2026-07-22 13:25:17 +08:00
parent 1a84cf69ab
commit 1072565d97
4 changed files with 49 additions and 3 deletions

View File

@@ -172,8 +172,10 @@ class Go1WalkTask(NpEnv):
def apply_action(self, actions, state):
state.info["last_dof_vel"] = self.get_dof_vel(state.data)
state.info["last_actions"] = state.info["current_actions"]
state.info["current_actions"] = actions
if "last_last_actions" in state.info:
state.info["last_last_actions"] = state.info["last_actions"].copy()
state.info["last_actions"] = state.info["current_actions"].copy()
state.info["current_actions"] = np.array(actions, copy=True)
state.data.actuator_ctrls = self._compute_torques(actions, state.data)
return state

View File

@@ -1,6 +1,9 @@
from types import SimpleNamespace
import numpy as np
from motrix_envs.locomotion.go1.dreamwaq import _sanitize_dof_pos
from motrix_envs.locomotion.go1.walk_np import Go1WalkTask
def test_sanitize_dof_pos_handles_zero_quaternion_with_nonfinite_joints():
@@ -17,3 +20,25 @@ def test_sanitize_dof_pos_handles_zero_quaternion_with_nonfinite_joints():
np.testing.assert_allclose(np.linalg.norm(clean[:, 3:7], axis=1), 1.0)
assert clean[0, 7] == 0.0
assert clean[1, 8] == 0.0
def test_apply_action_advances_three_frame_action_history():
task = Go1WalkTask.__new__(Go1WalkTask)
task.get_dof_vel = lambda data: np.ones((1, 12), dtype=np.float32)
task._compute_torques = lambda actions, data: actions
state = SimpleNamespace(
data=SimpleNamespace(actuator_ctrls=None),
info={
"current_actions": np.full((1, 12), 2.0, dtype=np.float32),
"last_actions": np.full((1, 12), 1.0, dtype=np.float32),
"last_last_actions": np.zeros((1, 12), dtype=np.float32),
},
)
actions = np.full((1, 12), 3.0, dtype=np.float32)
task.apply_action(actions, state)
actions.fill(9.0)
np.testing.assert_array_equal(state.info["last_last_actions"], 1.0)
np.testing.assert_array_equal(state.info["last_actions"], 2.0)
np.testing.assert_array_equal(state.info["current_actions"], 3.0)