Reinforcement Learning for Robot Control
Reinforcement learning trains robot control policies through trial-and-error interaction, discovering dynamic behaviors like quadruped locomotion and agile parkour. Rather than commanding raw motor voltages, modern RL policies output target setpoints to high-frequency PD controllers while optimizing shaped reward functions.
Why Does This Exist?
Classical legged locomotion and dynamic robotics historically relied on analytical control models: Zero Moment Point (ZMP), inverted pendulum models, and whole-body quadratic programming. While these methods produce stable walking on flat laboratory floors, they struggle on rough gravel, slippery snow, and unstructured outdoor terrain where foot contact slippage cannot be predicted analytically.
Reinforcement Learning (RL) abandons hand-derived gait equations in favor of direct policy optimization: an agent interacts with a physics simulation across millions of simulated steps, receives scalar rewards for progressing forward without falling, and optimizes its neural network weights using policy gradient methods (such as Proximal Policy Optimization).
However, applying standard RL to physical robots fails if treated as an abstract game. If a neural network directly outputs raw motor voltages or currents at , high-frequency dynamics destabilize the actuators, causing severe joint vibration and motor burnout. Modern physical RL succeeds by embedding the learned policy inside a two-rate control hierarchy: the policy outputs target joint position offsets at , while dedicated low-level microcontrollers run proportional-derivative (PD) tracking loops at .
Basics first: the physics simulators where millions of parallel RL steps run live in robot-simulation. The mathematical derivation of policy gradients lives in proximal-policy-optimization. Designing scalar rewards that prevent undesirable agent behavior lives in reward-shaping.
Think of It Like This
A jockey riding a galloping racehorse
Think of the division of labor between a jockey and a galloping thoroughbred horse running across uneven pasture.
The jockey does not command each leg muscle individually: they do not calculate knee flexion or hoof impact timing. The jockey sits in the saddle, assesses the overall direction, sets the pace, and nudges the reins every second (a to high-level policy).
The horse's spinal reflexes and cerebellum handle the high-speed biomechanics: adjusting muscle tension as hooves hit mud, stabilizing the ankle upon impact, and managing ground reaction forces at hundreds of Hertz.
Where it stops: a horse has millions of years of biological evolution and self-preservation instincts. A quadruped robot's policy has only the rewards you program into its loss function: if you reward forward speed without penalizing joint torque or impact vibration, the policy will discover gaits that slam steel feet into concrete until the motor gears fracture.
How It Actually Works
The Markov decision process for legged locomotion
Robot RL formulates continuous physical control as a Markov Decision Process (MDP) defined by :
- Observation Space : Typically composed of:
- Base angular velocity from IMU gyroscopes.
- Projected gravity vector in the chassis frame.
- Commanded velocity target .
- Joint positions and velocities (for a 12-DoF quadruped).
- Previous action vector .
- Action Space : Target joint position offsets . The commanded joint setpoint is .
- Low-Level Motor Reflex: At each interval (), the actuator microcontroller computes torque:
Reward shaping for physical feasibility
If an agent is rewarded solely for forward speed (), it discovers unphysical, violent gaits that break real hardware. Robust robot RL employs multi-objective reward shaping that balances task accomplishment against energy consumption, smoothness, and structural survival:
- Tracking reward: , granting positive reward when linear velocity matches the target.
- Torque penalty: , discouraging excessive motor heating.
- Action smoothness penalty: , penalizing jerky control setpoints.
- Base orientation penalty: , enforcing an upright chassis.
Worked example: calculating shaped reward for quadruped locomotion
Consider a 12-DoF quadruped tracking a forward velocity command :
- Measured forward velocity: (velocity tracking error ).
- Total motor torque norm: .
- Action change norm: .
- Base angular roll and pitch rate: .
- Reward weights:
Compute each term:
-
Velocity Tracking Reward:
-
Torque Effort Penalty:
-
Action Smoothness Penalty:
-
Chassis Orientation Penalty:
Summing the components yields the net step reward:
The positive velocity progress () comfortably outweighs the combined mechanical and orientation penalties (), guiding the policy gradient to reinforce this smooth, efficient gait.
Code
This Python snippet simulates one environment step of a quadruped locomotion policy, computing motor PD torques and evaluating shaped reward terms.
import mathimport numpy as np
def compute_locomotion_reward( v_actual: float, v_target: float, torque_norm: float, action_diff_norm: float, roll_rate: float, pitch_rate: float,) -> tuple[float, float, float, float, float]: """Compute individual shaped reward components and net scalar reward.""" # Velocity tracking term r_vel: float = 1.5 * math.exp(-((v_actual - v_target) ** 2) / 0.25)
# Penalties p_torque: float = -0.001 * (torque_norm ** 2) p_action: float = -0.10 * (action_diff_norm ** 2) p_rot: float = -0.50 * (abs(roll_rate) + abs(pitch_rate))
r_net: float = r_vel + p_torque + p_action + p_rot return ( round(r_vel, 4), round(p_torque, 4), round(p_action, 4), round(p_rot, 4), round(r_net, 4), )
r_v, p_t, p_a, p_r, r_tot = compute_locomotion_reward( v_actual=0.90, v_target=1.00, torque_norm=10.0, action_diff_norm=0.20, roll_rate=0.05, pitch_rate=0.05,)
print(r_v) # -> 1.4412print(p_t) # -> -0.1print(p_a) # -> -0.004print(p_r) # -> -0.05print(r_tot) # -> 1.2872Watch Out For
Directly outputting raw motor torques from neural network layers
Allowing an RL policy to command raw motor torques directly bypasses the motor drive's low-level feedback stabilization. Because neural networks operating at cannot adjust torque between policy calls, any contact bounce during foot strike causes the foot to bounce uncontrollably.
The symptom is high-frequency joint vibrations, stripped gearbox teeth, and extreme policy instability during contact transitions. Fix it by commanding target joint positions to a high-rate () PD controller, which inherently provides mechanical stiffness and damping at impact.
Reward hacking through unconstrained contact frequencies
When designing reward terms for walking or climbing, policies frequently exploit flaws in penalty weights: if foot clearance is rewarded without penalizing ground impact force, quadrupeds learn to violently slap their front paws into the ground at high frequencies.
The symptom is the policy reporting massive training rewards while performing an unnatural, violent vibration that would shatter physical hardware. Fix it by monitoring curriculum metrics: inspect torque norms, ground reaction force spikes, and foot contact durations, tightening penalties whenever unnatural behaviors emerge.
The Quick Version
- Reinforcement learning discovers dynamic locomotion and agile manipulation through trial-and-error simulation training.
- Physical RL uses a two-rate architecture: the neural policy outputs joint position targets at , while microcontroller PD loops compute torques at .
- Multi-objective reward shaping balances task velocity tracking against penalties on torque, action rate of change, and chassis orientation drift.
- For a locomotion target, an actual speed of with torque norm yields a net step reward of .
- Commanding target joint setpoints rather than raw torques provides essential physical damping during ground impacts.