[MicroDuck RL 05] Inside the Velocity Locomotion Task: Observations, Rewards, Domain Randomization, and Curriculum Learning

MicroDuck RL: From Simulation to the Real Robot — Part 05 of 14

This is the most technical part of the series. The task is defined in src/mjlab_microduck/tasks/microduck_velocity_env_cfg.py, a heavily commented file of roughly 950 lines and the best place to study the implementation. Keep the source open as you read.

Action Space: 14 Dimensions

Every 0.02 seconds, the policy outputs 14 target joint positions in radians. Those targets are passed to the servos’ PD controllers.

Actor Observation Space: 61 Dimensions

Observation Dimensions Description
base_ang_vel 3 Base angular velocity from the IMU
projected_gravity 3 Gravity projected into the body frame, which provides orientation information
joint_pos 14 Joint positions
joint_vel 14 Joint velocities
actions 14 Previous action
command (twist) 3 Velocity command [vx, vy, ω]
head_pose 4 Head-pose command: offsets from HOME for the four neck and head joints
body_pose 6 Body-pose command [x, y, z, roll, pitch, yaw]

The critic, or value network, receives an additional 76 dimensions of privileged information during training, including true linear velocity, foot height, contact time, and contact forces. At deployment time, only the actor’s 61-dimensional observation is required.

Important design choice: Every task uses the same 61-dimensional observation layout. Command slots that a task does not use are filled with zeros rather than removed. This shared contract makes it possible to hot-switch between walking, standing, rolling, and other policies on the physical robot.

Reward Design: The Heart of the Task

Positive terms that encourage the desired behavior:

Term Weight Purpose
track_linear_velocity 2.0 Tracks the commanded linear velocity using a Gaussian kernel with std = √0.1
track_angular_velocity 2.0 Tracks the commanded turning rate using a Gaussian kernel with std = √0.5
pose 1.0 Keeps the leg joints near the default standing or gait pose; only the legs are included, because the head and neck follow commands
upright 2.0 Keeps the body upright; this term was strengthened to prevent forward lean while walking
air_time 3.0 Rewards foot air times between 0.125 and 0.3 seconds, encouraging alternating steps instead of shuffling
head_pose_tracking Primary objective Tracks the commanded head pose with std = 0.5

Negative terms that discourage undesirable behavior. Pay attention to the sign convention; Part 10 explains why it matters.

Term Weight Purpose
foot_slip −0.1 Penalizes sliding of the stance foot. This term is intentionally weak because a stronger penalty interferes with turning in place.
action_rate_l2 −0.1 Penalizes jerky actions and is introduced gradually through the curriculum
self_collisions Negative Penalizes the legs striking the body’s battery compartment
foot_clearance / foot_swing_height Negative Penalizes insufficient foot clearance
head_pose_bias Negative Penalizes only avoidable, persistent head droop. An EMA prevents normal head motion during walking from being penalized.

Episodes terminate on fell_over, nan_state, or the 20-second time limit.

Two details of command sampling are especially instructive:

  • Turning commands span ±1.0 rad/s, and 15% of environments are deliberately assigned in-place turns with zero linear velocity. With independent uniform sampling, in-place turns would make up only about 2% of the experience, which is not enough for the policy to learn them reliably.
  • Head- and body-pose commands are resampled every two to five seconds.

Domain Randomization: The Core Sim2Real Tool

Randomized property Range When applied
Body center-of-mass offset Starts at ±3 mm and increases to ±8 mm through the curriculum Every episode
Head-assembly center of mass Starts at ±3 mm Every episode
Mass and inertia ±5% At startup
Joint friction (BAM friction_scale) ±10% Every episode
Rotor inertia (armature) ±10% Every episode
Foot-ground friction coefficient Randomized At startup
Encoder zero offset Fixed, per-environment bias At startup
IMU mounting-orientation error Zero-mean distribution Observation layer
External pushes Up to ±0.3 m/s every three to six seconds During the episode
Battery voltage from 6.5 to 8.2 V, load-dependent voltage drop, and command delay of three to six steps — Inside the actuator model

The project deliberately leaves proportional- and derivative-gain randomization and initial-pose tilt disabled. The ENABLE_* switches at the top of the configuration make it easy to see which options are active and which were tried and rejected.

Curriculum Learning

Training difficulty increases over time. The ranges for center-of-mass perturbations and head commands, the share of standing environments, and the action_rate penalty are all increased in stages. Curriculum schedules use environment steps as their unit: iteration × 24.

The best way to read this 950-line configuration is to begin with the reward-weight table, then inspect the ENABLE_* switches to understand the design trade-offs, and finally use the log-reading methods in Part 10 to test your interpretation. Part 06 examines the robot itself and the BAM actuator model that makes the entire pipeline work.