MODULE 1 · LESSON 4 OF 6 · 35 MIN

Reward and return

A score for every step, how cyclotron builds it from 20 terms, and how far ahead a policy looks.

The policy has no idea what “standing” or “walking” means. The only thing that tells it what we want is the reward: after every step, one number that says how good that step was. Training changes the policy so that, over time, it collects more of it. Everything you want the robot to do, or not do, has to show up in that number.

SIMULATOR

Asimov 1 simulated with MuJoCo and driven by a trained policy, on your own computer.

Upright · 0.00 s · step 0

Reward

Computed in the browser from the running policy’s own env.yaml, term by term: value × weight × 0.02 s, as training adds it up.

TermWeightValueReward this step
Waiting for the first step…

Reward this step (computed terms)
–
Sum this episode
–
Discounted return from the episode start
–
0.990
Discounted return since the episode began

One number, built from many terms

cyclotron’s walking task scores each step with 20 terms. Each term measures one thing about the step and has a weight: positive weights reward, negative weights penalise.

Term Weight What it scores
track_linear_velocity +5.0 Moving at the commanded forward and sideways speed
track_angular_velocity +3.0 Turning at the commanded rate
upright +1.0 Keeping the torso level
pose +1.0 Staying close to the default pose, more tightly when standing
air_time +0.5 Feet in the air between 0.05 and 0.5 s per step, when walking
heading_drift −0.5 Drifting off the commanded heading
foot_clearance −2.0 Swinging feet that are not about 10 cm high
foot_swing_height −0.25 The highest point of a step not being about 10 cm
foot_slip −0.1 Feet sliding while on the ground
feet_orientation −1.0 Soles not flat
action_rate_l2 −0.5 Actions changing from one step to the next
body_ang_vel −0.08 The torso rocking
angular_momentum −0.03 The whole body spinning
dof_pos_limits −1.0 Joints near their limits
ankle_roll_overuse −0.5 Ankle roll beyond 0.06 rad
joint_deviation_l1 −1.0 Any joint away from the default pose, when standing
feet_stumble −1.25 Feet hitting something sideways
feet_contact_force_limit −0.0005 Stamping: foot forces above 350 N
soft_landing −0.00001 Hard landings
self_collisions −1.0 Body parts hitting each other

Only the first two say what the task is. The other 18 shape how the robot goes about it; lesson 6 explains why they are needed.

The reward for one step is the sum of every term’s value times its weight, times the step’s length in seconds:

rt+1=∑iwi×fi×Δt
SymbolMeaningUnitAsimov standing still (measured)
rt+1the reward for step t: one number–0.170
iwhich term: 1 to 20 in cyclotron’s walking task–8 computed on this page
witerm i’s weight from the table: positive to reward, negative to penalise–+5 for track_linear_velocity
fiwhat term i measured on that step, for example how close the speed was to the commanddepends on the term1.000 for track_linear_velocity
Δtthe length of a step. Multiplying by it keeps rewards comparable if the control rate ever changess0.02
rt+1=5×1.000×0.02
+ 3×1.000×0.02+…
=0.170

The eight terms this page computes, for the built-in policy standing still. The two largest are track_linear_velocity and track_angular_velocity; the other six add the rest.

The reward, live

The Reward panel recomputes the reward of the policy that is running, term by term, from that policy’s own training file. The built-in policy’s file has 18 of the 20 terms above. The panel computes 8 of them, the ones that need only the robot’s joints, its pelvis and the actions: track_linear_velocity, track_angular_velocity, upright, action_rate_l2, joint_deviation_l1, dof_pos_limits, body_ang_vel and angular_momentum.

It lists the other 10 below its table, without values, because this page cannot reproduce them faithfully:

  • Nine are about the feet touching things: air_time, foot_clearance, foot_swing_height, foot_slip, feet_orientation, soft_landing, feet_stumble, feet_contact_force_limit and self_collisions. In training they read Isaac Sim’s contact sensor: which foot is on the ground, since when, and how hard it presses. MuJoCo computes contacts too, but differently, so a copy here would give different numbers from the ones the policy was trained with.
  • pose allows each joint a different amount of deviation depending on whether the robot is standing, walking or running, from three tables this page does not read yet.

So the panel’s total is the sum of 8 terms, not the policy’s full training reward.

Standing still under the built-in policy, the eight terms added up to 0.170 per step. After a 300 N push forward, the step reward was lowest 13 steps later, at −0.112, and the term that had dropped most was track_linear_velocity.

Exercise 4.1 · In the simulator

Which term reacts to a push

Let the robot stand, then push it forward at 300 N while watching the Reward this step column. Which term drops furthest, and which barely moves?

Hint 1
A push makes the robot move although the command says to stand still.
Hint 2
The push lasts 0.15 s, too short to follow live. Pause with the button in the corner of the 3D view, push, then press Advance one step repeatedly and watch each step’s reward.
Checkpoint: answers only
In the measured run the step reward was lowest 13 steps after the push. At that step the largest drop was in track_linear_velocity, by 0.0994 per step.
Solution

A push changes several things at once: the torso rocks, the robot moves without being asked to, the joints leave the default pose and the policy’s actions change quickly to recover. Each of those shows up in its own term. The heavily weighted tracking terms usually move most, because the command is “stand still” and the push makes the base move. Terms that measure smoothness move too: recovering takes fast action changes, and the reward charges for them. The policy was trained to trade these off.

From reward to return

The reward scores one step, but no single step matters on its own. A policy that leans into a push loses a little reward now and keeps the robot standing for the next thousand steps. What training optimises is the reward over time, the return:

Gt=rt+1+γrt+2+γ2rt+3+ …
Gt=∑k=0∞γk rt+k+1
SymbolMeaningUnitAsimov standing still (measured)
Gtthe return from step t: all the reward still to come, each reward discounted–16.55 after 10 s (17.0 if it stood forever)
rt+k+1the reward k+1 steps after step t–0.170 per step
γthe discount (gamma), a number between 0 and 1–0.99 (cyclotron)
khow many steps ahead a reward is: 0 for the very next onesteps50 per second
G0=0.170+0.99×0.170+…
=0.170/(1−0.99)=17.0

If every step were worth the same 0.170, the return would add up to 100 steps’ worth. Measured, after 10 s it was already 16.55.

A reward k steps ahead counts γk as much as a reward now. How fast that weight falls sets how far the policy looks ahead: how far into the future rewards still count for much. A common measure is 1/(1−γ) steps; a reward that far ahead counts about a third as much as one now, and rewards further away count less and less.

γ = 0.9looks about 0.2 s ahead0101234 sγ = 0.99looks about 2 s ahead0101234 sγ = 0.999looks about 20 s ahead01→ 20 s01234 s
How much a reward counts (from 1 down to 0) by how many seconds ahead it is, for three discounts. The orange dot is the look-ahead, 1/(1 − γ) steps: there a reward counts about 0.37 as much as one now. With γ = 0.999 it is 20 s away, off the chart.

cyclotron uses γ=0.99, so its policies look about 100 steps, or 2 s, ahead: long enough to see a fall coming, short enough that what happens ten seconds later barely counts.

The Reward panel also shows the discounted return from the start of the episode, G0, as it adds up. Watch how it grows quickly at first, then flattens: rewards far into the episode are multiplied by tiny weights. In the measured run, standing still, G0 was 6.39 after 1 s, 10.44 after 2 s, 15.29 after 5 s and 16.55 after 10 s.

Exercise 4.2 · On paper

How far ahead does a policy look?

  1. With γ=0.99, how much does a reward 1 s ahead count, and one 5 s ahead?
  2. With γ=0.9, roughly how far ahead does the policy look, in steps and in seconds?
Hint 1
1 s is 50 steps; the weight is γ50.
Hint 2
Use the rule of thumb 1/(1−γ).
Checkpoint: answers only
1. 0.605 and 0.081. 2. About 10 steps, 0.2 s.
Solution
  1. 0.9950=0.605 and 0.99250=0.081.
  2. 1/(1−0.9)=10 steps, which is 0.2 s at 50 steps a second. A policy that looks 0.2 s ahead would hardly see the consequence of a fall that takes half a second to happen. That is one reason locomotion uses discounts close to 1.

Exercise 4.3 · On paper

The return of standing still

Suppose standing still earned the same reward r on every step, forever. What would G0 be with γ=0.99? Use the measured per-step reward at rest, 0.170, and compare with the 10 s value above.

Hint 1
G0=r+γr+γ2r+… is a geometric series.
Checkpoint: answers only
G0=r/(1−γ)=100 r, which is 17.0.
Solution

The series r(1+γ+γ2+… ) adds up to r/(1−γ), here 100 r = 17.0. After 10 s (500 steps) the remaining weight is 0.99500=0.0066, so G0 is already within 1% of that limit if the reward really stays constant. The measured value, 16.55, differs a little because the reward of a standing robot is not exactly constant: the policy keeps making small corrections.

Recap

  • The reward is one number per step: the sum of weighted terms, times 0.02 s.
  • cyclotron’s walking reward has 20 terms; two define the task and the rest shape how it is done.
  • The return adds up future rewards, each discounted by γk.
  • With γ=0.99, a policy looks about 100 steps, or 2 s, ahead.

Sources

  1. cyclotron, velocity task: the 20 reward terms and their weightssource/cyclotron/cyclotron/tasks/locomotion/velocity_env_cfg.py, lines 377–526 (commit d71390f)
  2. cyclotron, reward functions (tracking, upright, smoothness, posture)source/cyclotron/cyclotron/tasks/locomotion/mdp/rewards.py
  3. cyclotron, PPO settings: discount γ = 0.99source/cyclotron/cyclotron/tasks/locomotion/agents/rsl_rl_ppo_cfg.py, line 91
  4. Isaac Lab's reward manager adds value × weight × step duration for every termsource/isaaclab/isaaclab/managers/reward_manager.py, line 150 (Isaac Lab commit b0542fe, as pinned by cyclotron)
  5. The browser reward gauge: ports of eight termssite/src/sim/reward.ts in the denebots repository
  6. cyclotron, which reward terms read the foot contact sensor, and pose's separate tolerances for standing, walking and runningsource/cyclotron/cyclotron/tasks/locomotion/mdp/rewards.py (feet_* terms, soft_landing, self_collision_cost, variable_posture)
  7. Measurement: reward terms at rest, after a 300 N push, and the discounted return over 10 smeasurements.json, results.reward (scripts/measure-module-1.mjs)
  8. R. S. Sutton and A. G. Barto, Reinforcement Learning: An Introduction, 2nd edition, MIT Press, 2018Sections 3.2 and 3.3: goals, rewards, returns and discounting