Skip to content
Merged
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
30 changes: 20 additions & 10 deletions artifacts/go2-walk-flat.deploy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
]
},
"payload_path": "policy/model.onnx",
"sha256": "b3d3aa61f2077502264163e16772d7883e115d949247a7a0ebe8f7fbcb7cdb19"
"sha256": "e7212d9500aa89a51c93031894901dee7a5b708017bdc167a9024a13b821efb7"
},
"robot": {
"base_link_name": "base",
Expand All @@ -39,10 +39,10 @@
0.800000011920929,
-1.5,
0.0,
1.0,
0.800000011920929,
-1.5,
0.0,
1.0,
0.800000011920929,
-1.5
],
"joint_names": [
Expand Down Expand Up @@ -106,7 +106,7 @@
"source": {
"checkpoint": "checkpoints/latest.pt",
"framework": "rslrl.ppo/torch",
"run_id": "26-10-10_11-48-41-971323"
"run_id": "26-11-26_12-57-18-755832"
},
"task": {
"config": {
Expand All @@ -118,10 +118,10 @@
-8.800000190734863,
-4.490799903869629,
-3.788800001144409,
-9.600000381469727,
-8.800000190734863,
-4.490799903869629,
-3.788800001144409,
-9.600000381469727,
-8.800000190734863,
-4.490799903869629
],
"action_scale": [
Expand All @@ -146,16 +146,16 @@
6.800000190734863,
2.608959913253784,
3.788800001144409,
6.0,
6.800000190734863,
2.608959913253784,
3.788800001144409,
6.0,
6.800000190734863,
2.608959913253784
],
"command_lower": [
-1.0,
-0.5,
-0.5
-1.0
],
"command_scale": [
1.0,
Expand All @@ -165,7 +165,7 @@
"command_upper": [
1.0,
0.5,
0.5
1.0
],
"feet_phase_offsets": [
0.0,
Expand All @@ -174,6 +174,16 @@
0.0
],
"gait_frequency_hz": 2.0,
"gait_schedule_enabled": true,
"gait_schedule_frequency_high": 2.14,
"gait_schedule_frequency_low": 1.05,
"gait_schedule_lateral_weight": 1.0,
"gait_schedule_smoothing_time_s": 0.6,
"gait_schedule_speed_high": 0.8,
"gait_schedule_speed_low": 0.2,
"gait_schedule_swing_fraction_high": 0.5,
"gait_schedule_swing_fraction_low": 0.368,
"gait_schedule_yaw_weight": 0.8,
"kd": [
0.5,
0.5,
Expand Down
Binary file modified artifacts/go2-walk-flat.deploy/policy/model.onnx
Binary file not shown.
2 changes: 1 addition & 1 deletion configs/task/go2-walk-flat/rslrl.ppo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ seed: 1
checkpoint:
interval: 100
algo:
max_iterations: 1000
max_iterations: 2000
obs_groups:
actor:
- policy
Expand Down
64 changes: 60 additions & 4 deletions motrix_deploy_tasks/src/motrix_deploy_tasks/tasks/go2_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ class Go2WalkTaskSpec(TaskSpec):
command_scale: CommandScale
feet_phase_offsets: FeetPhaseOffsets
gait_frequency_hz: PositiveFloat
# Older hand-built specs remain fixed-frequency unless the compiled
# environment profile explicitly opts into the measured schedule.
gait_schedule_enabled: bool = False
gait_schedule_speed_low: NonNegativeFloat = 0.2
gait_schedule_speed_high: PositiveFloat = 0.8
gait_schedule_frequency_low: PositiveFloat = 1.05
gait_schedule_frequency_high: PositiveFloat = 2.14
gait_schedule_swing_fraction_low: Annotated[FiniteFloat, Field(gt=0, lt=1)] = 0.368
gait_schedule_swing_fraction_high: Annotated[FiniteFloat, Field(gt=0, lt=1)] = 0.536
gait_schedule_smoothing_time_s: PositiveFloat = 0.35
# Legacy artifacts did not serialize this field and were trained with 0.5.
gait_schedule_yaw_weight: NonNegativeFloat = 0.5
# Legacy artifacts did not serialize this field and omit lateral speed
# from the schedule, matching their original fixed behavior.
gait_schedule_lateral_weight: NonNegativeFloat = 0.0
standing_threshold: NonNegativeFloat
termination_min_up_z: Annotated[FiniteFloat, Field(ge=-1, le=1)]

Expand Down Expand Up @@ -112,10 +127,21 @@ def __init__(self, spec: Go2WalkTaskSpec, robot: RobotSpec) -> None:
self._command_scale = np.asarray(spec.command_scale, dtype=np.float32)
self._feet_phase_offsets = np.asarray(spec.feet_phase_offsets, dtype=np.float32)
self._gait_frequency_hz = spec.gait_frequency_hz
self._gait_schedule_enabled = spec.gait_schedule_enabled
self._gait_schedule_speed_low = spec.gait_schedule_speed_low
self._gait_schedule_speed_high = spec.gait_schedule_speed_high
self._gait_schedule_frequency_low = spec.gait_schedule_frequency_low
self._gait_schedule_frequency_high = spec.gait_schedule_frequency_high
self._gait_schedule_swing_fraction_low = spec.gait_schedule_swing_fraction_low
self._gait_schedule_swing_fraction_high = spec.gait_schedule_swing_fraction_high
self._gait_schedule_smoothing_time_s = spec.gait_schedule_smoothing_time_s
self._gait_schedule_yaw_weight = spec.gait_schedule_yaw_weight
self._gait_schedule_lateral_weight = spec.gait_schedule_lateral_weight
self._standing_threshold = spec.standing_threshold
self._termination_min_up_z = spec.termination_min_up_z
self._previous_action: FloatArray = np.zeros(self.robot.joint_count, dtype=np.float32)
self._phase = np.float32(0.0)
self._gait_schedule_alpha = np.float32(0.0)

@property
def command_lower(self) -> FloatArray:
Expand All @@ -136,16 +162,46 @@ def reset(self, state: RobotState, context: ControlContext[PlanarVelocityCommand
"""Reset action and gait history; callers provide validated state and command."""
self._previous_action.fill(0)
self._phase = np.float32(0.0)
self._gait_schedule_alpha = np.float32(0.0)

def build_observation(self, state: RobotState, context: ControlContext[PlanarVelocityCommand]) -> FloatArray:
"""Consume runtime-validated state and PolicyController-validated input commands."""
velocity = context.command.values[0, :].numpy()
phase = np.zeros(4, dtype=np.float32)
if np.linalg.norm(velocity) < self._standing_threshold:
self._phase = np.float32(0.0)
elif context.step > 0:
self._phase = np.float32((self._phase + context.dt_s * self._gait_frequency_hz) % 1.0)
if context.step > 0:
if self._gait_schedule_enabled:
# Match training: forward speed anchors the measured gait;
# lateral and yaw use artifact-specified equivalent speeds.
speed = max(
abs(float(velocity[0])),
self._gait_schedule_lateral_weight * abs(float(velocity[1])),
self._gait_schedule_yaw_weight * abs(float(velocity[2])),
)
target_alpha = float(
np.clip(
(speed - self._gait_schedule_speed_low)
/ (self._gait_schedule_speed_high - self._gait_schedule_speed_low),
0.0,
1.0,
)
)
alpha_rate = context.dt_s / self._gait_schedule_smoothing_time_s
delta = target_alpha - self._gait_schedule_alpha
self._gait_schedule_alpha = np.float32(
self._gait_schedule_alpha + np.sign(delta) * min(abs(delta), alpha_rate)
)
frequency = self._gait_schedule_frequency_low + self._gait_schedule_alpha * (
self._gait_schedule_frequency_high - self._gait_schedule_frequency_low
)
else:
frequency = self._gait_frequency_hz
if np.linalg.norm(velocity) < self._standing_threshold:
self._phase = np.float32(0.0)
else:
self._phase = np.float32((self._phase + context.dt_s * frequency) % 1.0)
phase = np.mod(self._phase + self._feet_phase_offsets, 1.0).astype(np.float32)
if np.linalg.norm(velocity) < self._standing_threshold:
phase[:] = 0.0
observation = np.concatenate(
(
state.base_angular_velocity,
Expand Down
23 changes: 12 additions & 11 deletions motrix_deploy_tasks/tests/test_go2_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,26 +599,27 @@ def test_previous_action_and_trot_phase_advance_after_first_tick() -> None:
np.testing.assert_allclose(observation[45:49], [0.04, 0.54, 0.54, 0.04])


def test_gait_phase_restarts_after_standing_and_reset() -> None:
def test_gait_phase_starts_from_full_support_after_standing_and_reset() -> None:
robot = _robot()
state = _state(robot)
task = Go2WalkPolicyProcessor(_task_spec(), robot)
moving = [0.5, 0.0, 0.0]
standing = [0.0, 0.0, 0.0]
task.reset(state, _context(0, 0.0, moving))

phases = [
task.build_observation(state, _context(step, step * 0.02, command))[45:49]
for step, command in enumerate((moving, moving, standing, standing, moving, moving))
]
np.testing.assert_allclose(phases[0], 0.0)
np.testing.assert_allclose(phases[1], [0.04, 0.54, 0.54, 0.04])
np.testing.assert_allclose(phases[2:4], 0.0)
np.testing.assert_allclose(phases[4], phases[1])
np.testing.assert_allclose(phases[5], [0.08, 0.58, 0.58, 0.08])
first = task.build_observation(state, _context(0, 0.0, moving))[45:49]
second = task.build_observation(state, _context(1, 0.02, moving))[45:49]
stand = task.build_observation(state, _context(2, 0.04, standing))[45:49]
resumed = task.build_observation(state, _context(3, 0.06, moving))[45:49]

np.testing.assert_allclose(first, 0.0)
np.testing.assert_allclose(second, [0.04, 0.54, 0.54, 0.04])
np.testing.assert_allclose(stand, 0.0)
# Stand and walk share phase zero so startup begins from full support.
np.testing.assert_allclose(resumed, [0.04, 0.54, 0.54, 0.04])

task.reset(state, _context(0, 0.0, moving))
np.testing.assert_allclose(task.build_observation(state, _context(1, 0.02, moving))[45:49], phases[1])
np.testing.assert_allclose(task.build_observation(state, _context(1, 0.02, moving))[45:49], second)


def test_standing_command_freezes_deployment_gait_phase() -> None:
Expand Down
13 changes: 7 additions & 6 deletions motrix_deploy_tasks/tests/test_training_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
import pytest
import torch

import motrix_deploy_tasks
from motrix_deploy.contracts import RobotState
Expand Down Expand Up @@ -79,8 +80,8 @@ def test_go2_gait_phase_matches_training_across_standing_and_restart(env_name: s
env.initialize()
probe = _make_env_probe(env)
task = Go2WalkPolicyProcessor(profile.task, profile.robot)
moving = np.array([[0.2, 0.0, 0.0]], dtype=np.float32)
standing = np.zeros((1, 3), dtype=np.float32)
moving = torch.tensor([[0.2, 0.0, 0.0]], dtype=torch.float32)
standing = torch.zeros((1, 3), dtype=torch.float32)
env._commands[:] = moving
task.reset(
_robot_state_from_env(env, env.state, probe),
Expand Down Expand Up @@ -150,9 +151,9 @@ def _robot_state_from_env(env, state, probe) -> RobotState:
return RobotState(
sample_time_ns=int(state.episode_steps[0]) * 20_000_000,
receive_time_ns=0,
joint_position=env.get_dof_pos()[0],
joint_velocity=env.get_dof_vel()[0],
base_orientation_xyzw=imu_quat,
base_angular_velocity=env.get_gyro()[0],
joint_position=env.get_dof_pos()[0].numpy(),
joint_velocity=env.get_dof_vel()[0].numpy(),
base_orientation_xyzw=imu_quat.numpy(),
base_angular_velocity=env.get_gyro()[0].numpy(),
base_linear_acceleration=np.zeros(3, dtype=np.float32),
)
10 changes: 10 additions & 0 deletions motrix_envs/src/motrix_envs/deploy/go2_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ def build_go2_walk_profile(env_name: str) -> DeploymentProfile:
command_scale=GO2_COMMAND_SCALES[env_name].tolist(),
feet_phase_offsets=feet_offsets.tolist(),
gait_frequency_hz=env_cfg.gait_frequency,
gait_schedule_enabled=env_cfg.gait_schedule_enabled,
gait_schedule_speed_low=env_cfg.gait_schedule_speed_low,
gait_schedule_speed_high=env_cfg.gait_schedule_speed_high,
gait_schedule_frequency_low=env_cfg.gait_schedule_frequency_low,
gait_schedule_frequency_high=env_cfg.gait_schedule_frequency_high,
gait_schedule_swing_fraction_low=env_cfg.gait_schedule_swing_fraction_low,
gait_schedule_swing_fraction_high=env_cfg.gait_schedule_swing_fraction_high,
gait_schedule_smoothing_time_s=env_cfg.gait_schedule_smoothing_time_s,
gait_schedule_yaw_weight=env_cfg.gait_schedule_yaw_weight,
gait_schedule_lateral_weight=env_cfg.gait_schedule_lateral_weight,
standing_threshold=env_cfg.commands.velocity.standing_threshold,
# Match training's orientation-only fall termination.
termination_min_up_z=env_cfg.termination_min_up_z,
Expand Down
Loading