From 6b22fc9f37c2f8806518bb3e27551a28dabf4bab Mon Sep 17 00:00:00 2001 From: Kristof Houben Date: Mon, 1 Dec 2025 20:34:14 +0100 Subject: [PATCH] Simplified phase period loading --- runtime/scripts/v2_rl_walk_mujoco.py | 20 ++++++++++--------- .../open_duck_mini_v2/mujoco_infer.py | 15 +++++++------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/runtime/scripts/v2_rl_walk_mujoco.py b/runtime/scripts/v2_rl_walk_mujoco.py index ad47522..37bf92d 100644 --- a/runtime/scripts/v2_rl_walk_mujoco.py +++ b/runtime/scripts/v2_rl_walk_mujoco.py @@ -7,7 +7,6 @@ from mini_bdx_runtime.onnx_infer import OnnxInfer from mini_bdx_runtime.raw_imu import Imu -from mini_bdx_runtime.poly_reference_motion import PolyReferenceMotion from mini_bdx_runtime.xbox_controller import XBoxController from mini_bdx_runtime.feet_contacts import FeetContacts from mini_bdx_runtime.eyes import Eyes @@ -103,9 +102,12 @@ def __init__( if self.commands: self._try_connect_controller() - # Reference motion, but we only really need the length of one phase - # TODO - self.PRM = PolyReferenceMotion("./polynomial_coefficients.pkl") + # Load only the phase period from reference motion data + with open("./polynomial_coefficients.pkl", "rb") as f: + ref_data = pickle.load(f) + first_key = next(iter(ref_data)) + self.nb_steps_in_period = int(ref_data[first_key]["period"] * ref_data[first_key]["fps"]) + self.imitation_i = 0 self.imitation_phase = np.array([0, 0]) self.phase_frequency_factor = 1.0 @@ -316,14 +318,14 @@ def run(self): self.imitation_i += 1 * ( self.phase_frequency_factor + self.phase_frequency_factor_offset ) - self.imitation_i = self.imitation_i % self.PRM.nb_steps_in_period + self.imitation_i = self.imitation_i % self.nb_steps_in_period self.imitation_phase = np.array( [ - np.cos( - self.imitation_i / self.PRM.nb_steps_in_period * 2 * np.pi - ), np.sin( - self.imitation_i / self.PRM.nb_steps_in_period * 2 * np.pi + self.imitation_i / self.nb_steps_in_period * 2 * np.pi + ), + np.cos( + self.imitation_i / self.nb_steps_in_period * 2 * np.pi ), ] ) diff --git a/training/playground/open_duck_mini_v2/mujoco_infer.py b/training/playground/open_duck_mini_v2/mujoco_infer.py index c78d68d..d0ddcc2 100644 --- a/training/playground/open_duck_mini_v2/mujoco_infer.py +++ b/training/playground/open_duck_mini_v2/mujoco_infer.py @@ -6,7 +6,6 @@ import time import argparse from playground.common.onnx_infer import OnnxInfer -from playground.common.poly_reference_motion_numpy import PolyReferenceMotion from playground.common.utils import LowPassActionFilter from playground.open_duck_mini_v2.mujoco_infer_base import MJInferBase @@ -33,7 +32,11 @@ def __init__( self.action_filter = LowPassActionFilter(50, cutoff_frequency=37.5) if not self.standing: - self.PRM = PolyReferenceMotion(reference_data) + # Load only the phase period from reference motion data + with open(reference_data, "rb") as f: + ref_data = pickle.load(f) + first_key = next(iter(ref_data)) + self.nb_steps_in_period = int(ref_data[first_key]["period"] * ref_data[first_key]["fps"]) self.policy = OnnxInfer(onnx_model_path, awd=True) @@ -174,21 +177,19 @@ def run(self): if not self.standing: self.imitation_i += 1.0 * self.phase_frequency_factor self.imitation_i = ( - self.imitation_i % self.PRM.nb_steps_in_period + self.imitation_i % self.nb_steps_in_period ) - # print(self.PRM.nb_steps_in_period) - # exit() self.imitation_phase = np.array( [ np.cos( self.imitation_i - / self.PRM.nb_steps_in_period + / self.nb_steps_in_period * 2 * np.pi ), np.sin( self.imitation_i - / self.PRM.nb_steps_in_period + / self.nb_steps_in_period * 2 * np.pi ),