MODULE 1 · LESSON 6 OF 6 · 30 MIN

Beyond the basic loop

Why episodes end, why every robot starts from a different pose, and the extra reward terms that make training work.

The loop from lesson 1, a reward from lesson 4 and a learner from lesson 5 are, on paper, all reinforcement learning needs. In practice a training run built from only those pieces goes nowhere. This lesson covers the three additions that make it work: episodes that end, starts that vary, and reward terms that shape how the robot reaches its goal.

SIMULATOR

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

Upright · 0.00 s

Episode
Tilt from upright
–
Episode time
–
Episode
1
Last episode ended
not yet

In training an episode ends when the robot tilts past 70° or after 20 s; the robot then restarts from a new starting pose.

Why does an episode end?

Imagine Asimov falls in the first second of training. If the episode kept going, the robot would lie on the floor for the remaining 19 s, collecting 950 steps of experience about lying on the floor. None of it teaches standing.

So cyclotron ends an episode early when the robot falls: when the pelvis tilts more than 70° from upright. It also ends every episode after 20 s, so no robot spends the whole run in one long attempt. Either way the robot is put back and a new episode starts.

Turn on End episodes like training does in the Episode panel and push the robot hard. When the tilt passes 70°, the episode counter goes up and Asimov restarts.

Ending an episode on a fall does more than save time. The steps after a fall never come, so they never add reward. A policy that falls early gives up all the reward it would have collected by standing. That is why even a reward with no explicit “do not fall” term teaches the robot not to fall.

Exercise 6.1 · On paper

Steps lost to a fall

A robot falls 3 s into an episode. How many policy steps did that episode last, and how many of the possible 1,000 steps did it lose?

Hint 1
One step is 0.02 s.
Checkpoint: answers only
150 steps lasted; 850 were lost.
Solution

3 s ÷ 0.02 s = 150 steps. A full episode is 1,000 steps, so 850 steps, and all the reward they could have brought, never happened. If standing earns a small positive reward each step, falling early is expensive.

Why start from different poses?

If every episode started from the same perfect pose, the policy would only ever learn that one pose. On a real robot nothing starts perfectly.

In cyclotron’s velocity task each new episode starts with:

  • the pelvis placed anywhere within ±0.5 m and facing any direction,
  • the pelvis tilted by up to ±0.15 rad forward or back and ±0.1 rad to the side, and already rotating a little,
  • every joint offset from the default pose by up to ±0.5 rad, and moving at up to ±0.5 rad/s.

For standing this matters even more than for walking. Lesson 3 showed that holding the default pose already stands. A policy that only ever starts there can score well by doing almost nothing. Starting from poses that need balancing forces it to learn to recover.

Why extra reward terms?

A reward for standing still could be just two terms: one for matching the commanded speed, which is zero, and one for matching the commanded turning rate, also zero. But a policy optimises exactly what it is scored on and nothing else. With only those two, every way of keeping still scores the same, however odd it looks. So cyclotron’s walking reward adds terms about how the robot moves. Three of them:

Term What it scores Without it
pose How close each joint stays to the default crouch Any still posture scores the same: a deep squat, arms out, a locked knee
action_rate_l2 How much the 23 actions change from one step to the next Targets can flip between extremes every 20 ms: fine in simulation, but on the robot it heats the motors and shakes the joints
dof_pos_limits How far joints go past 90% of their range of motion Nothing keeps the policy from pressing joints against their mechanical stops

These terms change how the robot stands, not whether it stands. Choosing them, and their weights, is most of the work of designing a task.

A penalty is a price, not a rule. Standing still, the built-in walking policy aims its two shoulder rolls at 11.5 and −16.0 (an action of 1 aims a joint 0.25 rad from the default pose): targets far beyond what the joints can reach, so its arms rest pressed against their stops. Nothing caps a raw action, in training or here. dof_pos_limits charges it 0.0033 per step for that, about 2% of what the two tracking terms pay it for standing still. The policy pays the price. It does not do what we meant; it does what scores well.

To see what a piece is worth, train the same task without it and compare. The Build page’s standing task was trained three more times that way, with the same seed and for the same 1,500 iterations: once without pose, once without action_rate_l2, and once without episodes ending on a fall. Load them with the Ablation switcher and watch each one stand, then push it.

Trained20 s from the default poseJoints from the default poseAction change per stepPush that topples it, back / forward
With everythingstands0.010 rad0.0035150 N / 50 N
Without posestands0.025 rad0.0010150 N / 75 N
Without action_rate_l2falls after 11.5 s0.013 rad1.5387–
Without the fall ending the episodestands0.013 rad0.0019125 N / 50 N

The middle columns are averages over the 23 joints, measured from 0.5 s to 2 s after a start. Pushes act on the pelvis, from 50 N up in steps of 25 N.

  • Without pose, Asimov still stands, and takes pushes about as well. But nothing says what a good stance looks like any more, so it stands 2.4 times further from the default crouch. Not a failure, just a different posture nobody asked for.
  • Without action_rate_l2, the actions change by 1.54 from one step to the next, against 0.0035 with it: the targets jump between extremes every 20 ms. In training that still kept robots up, but in this simulator it falls after 11.5 s. Its exploration noise also stayed high, 0.64 at the end of training against 0.16, so it never settled on one way of standing.
  • Without the fall ending the episode, it still learned to stand. A robot on the floor kept losing reward here, because the reward also penalises a tilted body (flat_orientation), so falling stayed costly even without the episode ending. Its training curves tell you less, though: every episode lasts the full 20 s, so the episode length no longer shows whether robots fall.

The ablations change how the robot stands much more than whether it stands. That is the job of the extra terms: a reward is a description of the behaviour you want, and whatever it leaves out, the policy is free to do.

Exercise 6.2 · On paper

What a fall costs

Two robots earn +0.1 reward on every step they stay up. Robot A stands for the whole 20 s episode. Robot B falls after 3 s, which ends its episode.

  1. What is each robot’s total reward, without discounting?
  2. What is each robot’s discounted return from the start, G0, with γ=0.99?
Hint 1
A full episode is 1,000 steps; 3 s is 150 steps.
Hint 2
A constant reward r for n steps, discounted, adds up to r (1−γn)/(1−γ).
Checkpoint: answers only
1. A: 100, B: 15. 2. A: 10.00, B: 7.79.
Solution
  1. A collects 1,000 × 0.1 = 100. B collects 150 × 0.1 = 15.
  2. A: 0.1×(1−0.991000)/0.01, which is 10×(1−0.00004)=10.00. B: 0.1×(1−0.99150)/0.01, which is 10×(1−0.221)=7.79.

Without discounting, falling costs B 85% of its reward. With discounting the gap is smaller, 22%, because rewards seconds away count for less. But it is still a gap, and it comes from the fall alone: nothing in the reward said “do not fall”. Ending the episode on a fall is what turns falling into lost reward.

Recap

  • Episodes end when the robot tilts past 70° or after 20 s; a fall costs all the reward the robot would have collected.
  • New episodes start from varied, imperfect poses, so the policy learns to recover, not to hold one pose.
  • Extra reward terms decide how the robot stands: posture, smoothness, effort. A policy optimises exactly what it is scored on.

Sources

  1. cyclotron, velocity task: terminations (time_out, fell_over at 70°)source/cyclotron/cyclotron/tasks/locomotion/velocity_env_cfg.py, lines 533–537 (commit d71390f)
  2. cyclotron, velocity task: reset events (starting pose and joint offsets)source/cyclotron/cyclotron/tasks/locomotion/velocity_env_cfg.py, lines 319–344
  3. cyclotron, velocity task: reward terms and weights (pose at line 401, action_rate_l2 at 477, dof_pos_limits at 484)source/cyclotron/cyclotron/tasks/locomotion/velocity_env_cfg.py, lines 377–526
  4. cyclotron, Asimov 1: joint-limit penalties start at 90% of each joint's range (soft_joint_pos_limit_factor)source/cyclotron/cyclotron/assets/robots/asimov_1.py, line 219
  5. Measurement: the built-in policy's shoulder-roll actions at restmeasurements.json, results.restObservation.previousActions (scripts/measure-module-1.mjs)
  6. Measurement: the built-in policy's reward terms at rest, including the joint-limit termmeasurements.json, results.reward.atRest (scripts/measure-module-1.mjs)
  7. The browser simulator's fall rule (about 80° of tilt)site/src/sim/core/main.js, fall detection in main_loop (from humanoid-policy-viewer)