Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ mujoco_model_file: "assets/scene_mjx.xml"

# ONNX 模型庫 (ONNX Model Library)
onnx_models:
stable_walk:
stable_walk:
path: "models/pupper_ppo_policy_30965760_tf_converted_穩定步態版.onnx"
output_mode: "offset" # 模型輸出為偏移量
# 【新】為每個模型指定觀察配方
observation_recipe:
- 'linear_velocity'
Expand All @@ -25,9 +26,10 @@ onnx_models:
- 'last_action'
- 'commands'

agile_model:
agile_model:
path: "models/pupper_ppo_policy_200540160_tf_converted.onnx"
# 假設 agile_model 使用與 stable_walk 相同的配方
output_mode: "offset"
observation_recipe:
- 'linear_velocity'
- 'angular_velocity'
Expand All @@ -37,9 +39,10 @@ onnx_models:
- 'last_action'
- 'commands'

new_high_level:
new_high_level:
path: "models/pupper_ppo_policy_203161600_tf_v2.3_converted.onnx"
# 【新】使用新的觀察配方
output_mode: "offset"
observation_recipe:
- 'angular_velocity'
- 'gravity_vector'
Expand All @@ -49,8 +52,9 @@ onnx_models:
- 'last_action'
- 'commands'

new_e2e:
new_e2e:
path: "models/pupper_ppo_policy_e2e_203161600.onnx"
output_mode: "absolute" # 此模型直接輸出絕對角度
# e2e 模型也使用新的觀察配方
observation_recipe:
- 'angular_velocity'
Expand Down
10 changes: 8 additions & 2 deletions hardware_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,14 @@ def _control_loop(self):
# 【保留】更新 last_action
self.hw_state.last_action[:] = action_raw

# 【保留】生成發送給Teensy的文字指令
final_command = default_pose_hardware + action_raw * self.global_state.tuning_params.action_scale
# 【修改】根據模型設定決定最終控制模式
model_cfg = self.policy.get_active_model_config() # 取得當前策略的設定
if model_cfg.get('output_mode') == 'absolute':
# 若模型直接輸出絕對角度,則不加上 default pose
final_command = action_raw * self.global_state.tuning_params.action_scale
else:
# 預設為偏移量模式,需要加上 default pose
final_command = default_pose_hardware + action_raw * self.global_state.tuning_params.action_scale
action_str = ' '.join(f"{a:.4f}" for a in final_command)
command_to_send = f"move all {action_str}\n"

Expand Down
6 changes: 5 additions & 1 deletion policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import time
from collections import deque
from typing import TYPE_CHECKING, List, Dict
from typing import TYPE_CHECKING, List, Dict, Any

# 為了型別提示,避免循環匯入
if TYPE_CHECKING:
Expand Down Expand Up @@ -118,6 +118,10 @@ def get_active_recipe(self) -> List[str]:
"""一個輔助函式,返回當前主要策略所使用的觀察配方,主要供 HardwareController 使用。"""
return self.model_recipes.get(self.primary_policy_name, [])

def get_active_model_config(self) -> Dict[str, Any]:
"""取得目前主策略的完整設定字典 (包含自訂 output_mode 等資訊)。"""
return self.config.onnx_models.get(self.primary_policy_name, {})

def select_target_policy(self, target_name: str):
"""(由鍵盤觸發) 選擇一個目標策略並開始平滑轉換。"""
# 檢查目標模型是否存在
Expand Down
9 changes: 8 additions & 1 deletion simulation_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,14 @@ def _simulation_step(self) -> None:
with self.state.lock:
final_ctrl = self.sim.default_pose + self.state.joint_test_offsets
else:
final_ctrl = self.sim.default_pose + action_final * tuning_params.action_scale
# 【修改】根據模型的輸出模式決定是否加上 default pose
model_cfg = self.policy_manager.get_active_model_config()
if model_cfg.get('output_mode') == 'absolute':
# 模型輸出為絕對角度
final_ctrl = action_final * tuning_params.action_scale
else:
# 預設:模型輸出為偏移量
final_ctrl = self.sim.default_pose + action_final * tuning_params.action_scale

self.sim.apply_position_control(final_ctrl, tuning_params)

Expand Down