feat: sim2real domain randomization + reward fixes for rotary cartpole
Close the sim2real gap for the Furuta pendulum (swings up but can't balance on hardware). Root causes were (a) no domain randomization, so the policy overfit one deterministic sim instance, and (b) reward design flaws that produced degenerate policies. Domain randomization (runner-level, backend-agnostic): - BaseRunner: domain_rand config; per-env action-delay buffer (latency), Gaussian qpos/qvel sensor noise, per-env dynamics-scale sampling (friction/damping/torque), resampled per episode. Sensor noise per step. - privileged_obs/privileged_dim expose normalized DR factors (mu) for RMA. - step() now uses clean state for reward/termination, noisy state for the observation the policy sees. - MuJoCoRunner: applies per-env friction/damping/torque scales. - robot.py: compute_motor_force gains friction/damping scale args. - Configs: DR blocks for mujoco (full) and mjx (delay+noise); clean defaults for mujoco_single/serial; noise/delay anchored to recordings. Reward fixes (rotary_cartpole): - Shift upright reward to [0,1] (was [-1,1]) + alive_bonus, so surviving always beats ending early (kills the "suicide into the limit" policy). - Add balance_bonus * upright * stillness so reward requires upright AND near-zero pendulum velocity (kills the "spin in full loops" policy). Deploy: - eval.py load_policy reconstructs the history/adaptation encoder (auto-detects its dim from the checkpoint) so DR+embedding policies load. Fixes: - MuJoCoRunner._sim_reset referenced self._env (typo) -> self.env, which was breaking every rotary-cartpole reset. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
7
configs/env/rotary_cartpole.yaml
vendored
7
configs/env/rotary_cartpole.yaml
vendored
@@ -1,12 +1,18 @@
|
||||
max_steps: 1000
|
||||
robot_path: assets/rotary_cartpole
|
||||
reward_upright_scale: 1.0
|
||||
alive_bonus: 0.25 # per-step survival bonus (living must beat dying)
|
||||
balance_bonus: 2.0 # extra reward for upright AND still (beats spinning)
|
||||
balance_vel_scale: 0.5 # how fast the balance bonus decays with pendulum speed
|
||||
|
||||
# ── Regularisation penalties (prevent fast spinning) ─────────────────
|
||||
motor_vel_penalty: 0.01 # penalise high motor angular velocity
|
||||
motor_angle_penalty: 0.05 # penalise deviation from centre
|
||||
action_penalty: 0.05 # penalise large actions (energy cost)
|
||||
|
||||
# ── Initial state randomisation ──────────────────────────────────────
|
||||
pendulum_init_range_deg: 180.0 # pendulum starts in [-180°, +180°]
|
||||
|
||||
# ── Software safety limit (env-level, always applied) ────────────────
|
||||
motor_angle_limit_deg: 90.0 # terminate episode if motor exceeds ±90°
|
||||
|
||||
@@ -16,4 +22,5 @@ hpo:
|
||||
motor_vel_penalty: {min: 0.001, max: 0.1}
|
||||
motor_angle_penalty: {min: 0.01, max: 0.2}
|
||||
action_penalty: {min: 0.01, max: 0.2}
|
||||
pendulum_init_range_deg: {min: 30.0, max: 180.0}
|
||||
max_steps: {values: [500, 1000, 2000]}
|
||||
Reference in New Issue
Block a user