MODULE 1 · LESSON 1 OF 6 · 25 MIN

The loop, 50 times a second

How Asimov 1 senses, decides and acts in steps of 20 milliseconds, and what a trajectory is.

Asimov 1 is a humanoid robot by Menlo Research: 23 motors, two legs, two arms and a waist. In this course you train the program that moves those motors. That program is called a policy, and this module builds one that keeps Asimov standing.

Before any learning, look at what a policy has to do. The simulator below starts when you press Start the simulator, or by itself if your browser already has its files. A trained walking policy runs Asimov in MuJoCo, a physics engine, inside your browser.

SIMULATOR

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

Upright · 0.00 s · step 0

The policy that moves the robot works with very little. It gets no camera images: Asimov has a camera in its head, but this policy does not use it. It has no map of the room and no planned path. The 3D view on this page is for you; the policy never sees it. Everything it knows comes from the robot’s own sensors, an IMU (a motion sensor in the pelvis) and an encoder in every joint motor, plus the command saying how fast to walk.

Every 20 milliseconds the same four things happen:

  1. Sense. Read 78 numbers from those sensors: how the robot is tilted, how fast it turns, where each joint is and how fast it moves.
  2. Decide. Run the policy once. It turns the 78 numbers into 23 numbers.
  3. Act. Turn each of the 23 numbers into a target angle for one joint, and send the targets to the joint motors.
  4. Let physics run. The simulator advances 4 steps of 5 ms while each motor turns its joint towards its target. Then the loop starts again.

The 23 targets are one per joint the policy drives. Asimov has 25 motors; the policy drives all of them except the two in the neck:

Body part Joints Count
Each leg hip pitch, hip roll, hip yaw, knee, ankle pitch, ankle roll 2 × 6 = 12
Waist waist yaw 1
Each arm shoulder pitch, shoulder roll, shoulder yaw, elbow, wrist yaw 2 × 5 = 10

A target is an angle in radians: “left knee, move to 0.40 rad”. The policy never sets a force or a speed directly; each motor’s controller decides how hard to push to reach its target. Lesson 3 follows a target from the policy to the joint.

That is all a locomotion policy is: a function from 78 numbers to 23 target angles, called 50 times a second. Walking, standing and recovering from a push all come out of this one loop.

Why steps of 20 ms?

The physics engine needs small steps to stay accurate. cyclotron, the training code you use in this course, simulates in steps of 5 ms and calls the policy every fourth step. So the policy decides 50 times a second. The robot runs its policies at the same rate, which is why training, this browser simulator and the robot all keep it.

Pause the simulator with the pause button in the corner of the 3D view, then press the button that appears beside it, Advance one step. Each press moves time forward by exactly 0.02 s: one decision, four physics steps. The badge in the opposite corner counts the time and the steps.

Running a policy, and training one

The same loop runs in two very different situations.

  • Running a policy, also called inference: a trained policy drives the robot, on Asimov or on this page. The loop simply keeps going until someone stops it. Nothing is scored, and the policy never changes.
  • Training a policy: cyclotron runs the loop on thousands of simulated robots to make the policy better. Here the loop is cut into attempts, every step is scored, and the policy is changed between rounds of attempts.

The rest of this section is about training.

One run of the loop is a step. In training, steps are grouped into episodes: one attempt, from a starting pose until the robot falls or time runs out. cyclotron’s tasks end every episode after at most 20 s, then start the robot again. A running policy has no episodes; lesson 6 shows how training’s limits look in this simulator.

As the loop runs in training, it keeps a record of every step: what the robot sensed, what the policy chose, and how well that went. Reinforcement learning calls this record a trajectory:

o0,a0,r1,o1,a1,r2,…
SymbolMeaningUnitAsimov standing still (measured)
tthe step number: 0, 1, 2, …stepsone every 20 ms
otthe observation at step t: what the robot sensed78 numbersgravity direction z: −0.998
atthe action the policy chose from it23 numbersleft knee: −0.166
rt+1the reward: how good the step was. It is numbered t+1 because it arrives with the next observation1 number0.170
ot=(…, −0.060, −0.003, −0.998, … )
at=(0.070, 0.176, … )
rt+1=0.170

One step of a trajectory of Asimov standing still. In ot, values 4 to 6 are the gravity direction; at starts with the left hip’s actions.

The next three lessons take these three letters one at a time, on Asimov: what the robot senses, what it does, and how a step is scored.

Exercise 1.1 · On paper

Count the steps

A training episode in cyclotron lasts at most 20 s. How many policy steps is that, and how many physics steps?

Hint 1
One policy step is 0.02 s.
Hint 2
Each policy step contains 4 physics steps of 0.005 s.
Checkpoint: answers only
1,000 policy steps and 4,000 physics steps.
Solution

20 s ÷ 0.02 s = 1,000 policy steps. Each holds 4 physics steps, so 4,000 physics steps, which is also 20 s ÷ 0.005 s.

So a full episode is a trajectory with 1,000 observations, 1,000 actions and 1,000 rewards.

Exercise 1.2 · In the simulator

Ten steps by hand

Pause the simulator, then press Advance one step ten times. How much simulated time passes, and how many times did the policy run?

Hint 1
Watch the time and the step count in the badge at the bottom of the 3D view.
Checkpoint: answers only
0.20 s of simulated time and 10 policy runs.
Solution

Each press runs the loop exactly once: one observation, one policy call, one set of targets, then 4 physics steps. Ten presses are ten decisions and 0.2 s.

The robot barely moves in 0.2 s. That is the point: a policy never makes one big decision. It makes many small ones, and good behaviour is what those small decisions add up to.

Where the policy comes from

The policy in the simulator was trained. Nobody wrote rules like “if the robot leans forward, bend the ankles”. Instead, a training program ran the same loop on many simulated robots, scored every step with a reward, and changed the policy a little at a time so that steps scored better. That process is reinforcement learning, and by the end of this module you will have run it yourself.

Recap

  • A policy turns 78 sensor numbers into 23 joint target angles, 50 times a second. It sees no camera images and has no map.
  • One step is 20 ms: sense, decide, act, then 4 physics steps of 5 ms.
  • Running a policy is just the loop. Training cuts it into episodes of up to 20 s, or 1,000 steps, and scores every step.
  • A trajectory is the record o0,a0,r1,o1,… that training keeps of the loop.

Sources

  1. cyclotron, velocity task: physics step 0.005 s, decimation 4, episodes of 20 ssource/cyclotron/cyclotron/tasks/locomotion/velocity_env_cfg.py, lines 555–557 (commit d71390f)
  2. cyclotron, designing your own task: the robot and the viewer run policies at 50 Hzdocs/designing-your-own-task.md, “Constraints that keep the pipeline working”, item 1
  3. Asimov 1 by Menlo Research
  4. Asimov 1's 25 motors (legs 6 × 2, arms 5 × 2, waist 1, neck 2), its IMU and its head cameraAsimov 1 repository README, Specifications table (robots/asimov-1/README.md)
  5. The 23 joints the policy drives, in the policy's ordersite/learn-sim/policy-recipe.json, policy_joint_names, in the denebots repository
  6. R. S. Sutton and A. G. Barto, Reinforcement Learning: An Introduction, 2nd edition, MIT Press, 2018Chapter 3: the agent–environment interface and trajectories