[train] 更新新MJCF与第一版完整训练框架
This commit is contained in:
@@ -25,7 +25,7 @@ class MuJoCoIO:
|
||||
print("[MuJoCoIO] Loading MuJoCo model...")
|
||||
spec = mujoco.MjSpec.from_file(str(temp_xml))
|
||||
|
||||
# Override actuators to match mjlab exactly
|
||||
# Override actuators to match training/runtime actuator semantics.
|
||||
self._rebuild_actuators(spec)
|
||||
|
||||
self.m = spec.compile()
|
||||
@@ -91,8 +91,10 @@ class MuJoCoIO:
|
||||
for act in actuators_to_delete:
|
||||
spec.delete(act)
|
||||
|
||||
KP_LEG, KD_LEG = 40.0, 1.0
|
||||
KD_WHEEL = 0.5
|
||||
# Keep sim2sim aligned with the training robot config and sim2real runtime:
|
||||
# leg position PD = (50.0, 1.5), wheel velocity damping = 1.0.
|
||||
KP_LEG, KD_LEG = 50.0, 1.5
|
||||
KD_WHEEL = 1.0
|
||||
EFFORT_LIMIT = 17.0
|
||||
|
||||
leg_jnames = [
|
||||
|
||||
@@ -77,6 +77,7 @@ class PolicyRunner:
|
||||
|
||||
# Load both policy networks
|
||||
self.policies = {}
|
||||
self.policy_obs_dims = {}
|
||||
for name, path in self.policy_paths.items():
|
||||
print(f"[PolicyRunner] Loading {name} policy from: {path}")
|
||||
if Path(path).exists():
|
||||
@@ -84,6 +85,7 @@ class PolicyRunner:
|
||||
else:
|
||||
print(f"[PolicyRunner] WARNING: {name} policy file not found! Falling back to rough.")
|
||||
self.policies[name] = load_policy(self.policy_paths["rough"], device)
|
||||
self.policy_obs_dims[name] = int(self.policies[name].obs_mean.numel())
|
||||
|
||||
# Default DOF positions for each policy
|
||||
self.default_dof_poses = {
|
||||
@@ -226,11 +228,23 @@ class PolicyRunner:
|
||||
|
||||
raw_actions_out = {}
|
||||
for name in active_policies:
|
||||
# Flatten observation history
|
||||
obs_history_array = np.array(self.obs_histories[name])
|
||||
term_dims = [3, 3, 3, 12, 12, 4, 16]
|
||||
term_histories = np.split(obs_history_array, np.cumsum(term_dims)[:-1], axis=1)
|
||||
flat_obs = np.concatenate([h.flatten() for h in term_histories])
|
||||
expected_obs_dim = self.policy_obs_dims[name]
|
||||
|
||||
if expected_obs_dim == current_obs_53d.shape[0]:
|
||||
# Newer policies consume the current 53D observation directly.
|
||||
flat_obs = self.obs_histories[name][-1]
|
||||
elif expected_obs_dim == current_obs_53d.shape[0] * self.history_length:
|
||||
# Legacy policies expect 6-step history stacking grouped by term.
|
||||
obs_history_array = np.array(self.obs_histories[name])
|
||||
term_dims = [3, 3, 3, 12, 12, 4, 16]
|
||||
term_histories = np.split(obs_history_array, np.cumsum(term_dims)[:-1], axis=1)
|
||||
flat_obs = np.concatenate([h.flatten() for h in term_histories])
|
||||
else:
|
||||
raise RuntimeError(
|
||||
f"Policy '{name}' expects obs dim {expected_obs_dim}, "
|
||||
f"but sim2sim can only provide {current_obs_53d.shape[0]} or "
|
||||
f"{current_obs_53d.shape[0] * self.history_length}."
|
||||
)
|
||||
|
||||
obs_tensor = torch.tensor(flat_obs, device=self.device, dtype=torch.float32).unsqueeze(0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user