ceca51b0d8
Default humanoid intake to command-following gait and support bounded Cartesian target dragging for arms. Carry model and actuator semantics through calibration, native verification and packaging. Document reusable intake decisions and cover them with regression tests.
57 lines
2.8 KiB
Python
57 lines
2.8 KiB
Python
"""A zero residual scale retains position control while removing policy authority."""
|
|
from dataclasses import replace
|
|
|
|
import pytest
|
|
import torch
|
|
|
|
|
|
def test_zero_scale_holds_home_without_disabling_the_actuator(neutral_robot):
|
|
from mjlab.envs import ManagerBasedRlEnv
|
|
from mjlab.sim import get_simulation_cls, set_simulation_cls
|
|
from mjrl.backend import native_sim
|
|
from mjrl.backend.resolve import resolve
|
|
from mjrl.backend.select import use_backend
|
|
from tasks.templates.Biped_Template.env_cfg import env_cfg
|
|
|
|
held = replace(neutral_robot.position_joints[0], action_scale=0.0)
|
|
robot = replace(neutral_robot, position_joints=(held, *neutral_robot.position_joints[1:]))
|
|
previous, threads = get_simulation_cls(), native_sim._DEFAULT_NTHREAD
|
|
env = None
|
|
try:
|
|
use_backend(resolve(backend='native', device='cpu', num_envs=1))
|
|
env = ManagerBasedRlEnv(env_cfg(robot, play=True), device='cpu')
|
|
action = env.action_manager.get_term('joint_pos')
|
|
action.process_actions(torch.tensor([[100.0, 1.0]]))
|
|
assert action._processed_actions[0, 0].item() == pytest.approx(held.home)
|
|
moving = robot.position_joints[1]
|
|
assert action._processed_actions[0, 1].item() == pytest.approx(moving.home + moving.action_scale)
|
|
# A held action is still a powered PD joint, not an omitted/passive DOF.
|
|
actuator = env.scene['robot'].actuators[0]
|
|
assert actuator.stiffness[0, 0].item() == pytest.approx(held.kp)
|
|
assert actuator.force_limit[0, 0].item() == pytest.approx(held.effort_limit)
|
|
action.process_actions(torch.tensor([[-100.0, -1.0]]))
|
|
assert action._processed_actions[0, 0].item() == pytest.approx(held.home)
|
|
assert action._processed_actions[0, 1].item() == pytest.approx(moving.home - moving.action_scale)
|
|
finally:
|
|
if env is not None:
|
|
env.close()
|
|
set_simulation_cls(previous)
|
|
native_sim._DEFAULT_NTHREAD = threads
|
|
|
|
|
|
def test_negative_and_entirely_held_locomotion_actions_are_rejected(neutral_robot):
|
|
with pytest.raises(ValueError, match='action_scale'):
|
|
replace(neutral_robot.position_joints[0], action_scale=-.1)
|
|
with pytest.raises(ValueError, match='at least one joint'):
|
|
replace(neutral_robot, position_joints=tuple(
|
|
replace(joint, action_scale=0.0) for joint in neutral_robot.position_joints))
|
|
|
|
|
|
def test_velocity_actuator_still_requires_nonzero_scale():
|
|
from pathlib import Path
|
|
from tasks.robot_spec import read_robot_spec
|
|
|
|
robot = read_robot_spec(Path(__file__).resolve().parents[1] / 'tasks/wheeled_biped_example/robot_spec.py')
|
|
with pytest.raises(ValueError, match='action_scale>0'):
|
|
replace(robot, velocity_joints=tuple(replace(joint, action_scale=0.0) for joint in robot.velocity_joints))
|