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
20 changes: 11 additions & 9 deletions runtime/scripts/v2_rl_walk_mujoco.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
),
]
)
Expand Down
15 changes: 8 additions & 7 deletions training/playground/open_duck_mini_v2/mujoco_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
),
Expand Down