LLM + RoboticsModule 21 · The maths behind robots

The maths behind robots, learned by playing: ten interactive explainers, each one used to make Robo-Helper better

Linear algebra, Bayes, Markov chains, Kalman filters, A*, Fourier, momentum, reinforcement learning, Transformers and diffusion. Play with each idea in your browser, then use it on your own robot and measure the difference.

Source: Martin (@0x_meden), “Learn the math behind robots by playing with it”, 8 Nov 2026 · X post · quoting his guide “How π0, GR00T and Optimus actually think” (5 Nov 2026). All ten links checked and working on 9 Nov 2026.

Start here (no maths needed)

Robots run on maths, but you don't have to learn it from a textbook. These ten websites let you play with the maths: drag things, press buttons, watch what happens.

Think of it like this

You learned to ride a bike by riding, not by reading about balance. These websites are like training wheels for maths: you wobble the numbers around and feel how they work before anyone writes an equation.

How to use this page

  1. Pick one of the ten ideas below. Each has a "Play" link.
  2. Play for 10–15 minutes. Each section says what to try.
  3. Read the short "idea in plain words".
  4. Then use it on Robo-Helper: run python3 bonus_robot_math.py and see the robot get better, with numbers.

Why robots care

Every robot has to answer the same questions: Where am I? What did my sensors really see? Which way should I go? What should I do next? Each of these ten ideas answers one of them.

Try it

Open the A* page, drag the walls around, and watch the search change. You already built A* in Robo-Helper week 4, so you'll recognise it.

Words to know

Explainer
A web page that teaches an idea with pictures you can move.
Noise
Random wobble in a sensor reading.
Belief
What the robot thinks is true, with how sure it is.

Going deeper: each section links an explainer to the exact Robo-Helper lesson that uses the idea, with a tested experiment and a challenge. At the end there's a summary of the quoted guide on how π0 and GR00T are built.

In this module
  1. Summary
  2. How to use it with Robo-Helper
  3. Linear algebra
  4. Probability and Bayes
  5. Markov chains
  6. Kalman filters (with an interactive demo)
  7. Path planning: A*
  8. Signals: Fourier
  9. Optimisation: momentum
  10. Reinforcement learning
  11. Transformers
  12. Diffusion, and how π0 and GR00T move
  13. Playbook
  14. Self-check
  15. Glossary & further reading

1. Summary

TL;DR

The post lists ten free interactive pages that cover the maths a robot brain uses, from rotating a vector to turning noise into arm motion. The last two (Transformers and diffusion) are, in the author's words, the maths inside π0 and GR00T: a Transformer that understands the scene and a diffusion-style head that produces motion. Here, every explainer is paired with the Robo-Helper lesson that uses it, and one tested experiment (bonus_robot_math.py, standard library only) that makes the robot measurably better.

IdeaRobo-Helper lessonExperiment: before → after (real output)
Linear algebraWeek 1Turns "2 squares ahead, facing down" into room square (4, 5)
BayesWeek 2, week 5Finding the cat: 50% right after 1 reading → 92% after 4 → 100% after 16
Markov chainsWeek 5Run-ins with a wandering cat: 0.83 per trip → 0.06, for 2 extra steps
Kalman filterWeek 2Distance error while driving: 0.56 m raw, 0.54 m averaged → 0.22 m
A*Week 4Squares searched: 40 (no guess) → 35 (A*) → 13 (weighted A*), same 11-step path
FourierWeek 2Wheel wobble removed: error 0.44 m → 0.11 m
MomentumWeek 2Braking fit: 73 steps → 35 with momentum 0.5 (but 0.9 overshoots)
Reinforcement learningBonusA surprise: in this tiny maze, exploring more only slows learning down
TransformersWeek 6 stretchAttention: new commands 89% → 92% (average of 3 seeds)
DiffusionWeek 6 (action chunks)No experiment: explained, with what it would take

2. How to use it with Robo-Helper

Track: LLM + Robotics. Eight of the ten ideas are classic robotics (estimation, planning, control). The last two are the machine-learning half that modern robot brains add on top. Robo-Helper's week-by-week lessons already use most of them; this module gives you the interactive version of each idea and one more way to apply it.

3. Linear algebra

Play: Immersive Math: “Immersive Linear Algebra”, a whole book with interactive figures. Try the vectors chapter and the matrices chapter: drag a vector and watch a matrix move it.

The idea: a robot sees the world from its own point of view ("2 squares ahead of me"). To use that on a map, it rotates the reading by the way it's facing, then adds where it is. Rotation is a 2×2 matrix of cosines and sines. Arms are the same idea stacked joint by joint (forward kinematics, Module 02).

In Robo-Helper: week 1 moves on a grid with fixed directions, so it never needed rotation. A real robot can face any way.

1) LINEAR ALGEBRA: the robot at (4, 3) facing 90 degrees (down the screen) sees something 2 squares ahead.
   rotate((2, 0), 90) = (0.0, 2.0)  ->  it is at room square (4, 5)

Challenge: the robot faces 180° and reads 3. Where is the thing? Predict, then check with sensor_to_room((4, 3), 180, 3). (Remember y grows downwards in our room.)

4. Probability and Bayes

Play: Seeing Theory (Brown University). Do "Basic Probability" then "Bayesian Inference": flip coins, and watch a belief update as evidence arrives.

The idea: start with a belief (every square equally likely). Each sensor reading makes some squares more likely and some less: multiply by how well each square explains the reading, then rescale so it adds up to 1. That's Bayes' rule, and it's how real robots work out where they are (localisation).

In Robo-Helper: week 2 averages noisy readings; week 5's word counter is Bayes too (the "prior" is how common each intent is).

2) BAYES: where is the cat? The robot at (1, 1) takes noisy 'distance east' readings (noise 1.0).
    1 readings: most likely square is the right one 50% of the time
    4 readings: most likely square is the right one 92% of the time
   16 readings: most likely square is the right one 100% of the time

500 trials each. Our sensor's noise is flat (anywhere within ±1), but the belief update assumes a bell curve. It still works, which is common: the model doesn't have to be exactly right to be useful.

Challenge: double the noise to 2.0. How many readings do you need now to be right 90% of the time?

5. Markov chains

Play: Setosa: Markov chains, explained visually. Change the arrows' probabilities and watch where the dot spends its time.

The idea: a Markov chain is "what happens next depends only on where you are now", with a probability for each next step. Run it for a long time and you get where it spends its time (the stationary distribution). Your week 5 next-word model is a Markov chain over words.

In Robo-Helper: the cat. Give it a favourite bed at (4, 1) and let it wander. Then let A* charge extra for squares the cat likes.

3) MARKOV CHAIN: a wandering cat with a favourite bed at (4, 1). Route to the blue block avoiding where it usually is.
   cat's favourite squares (long-run share): (4, 1) 32.9%, (5, 1) 23.1%, (3, 1) 19.8%
   shortest  route:  7 steps, expected run-ins with the cat per trip 0.828
   cat-aware route:  9 steps, expected run-ins with the cat per trip 0.060

Two extra steps cut run-ins by more than 90%. An honest note: our first try had a cat that wandered with no favourite spot. It spent its time almost evenly everywhere, so the "cat-aware" route was identical and no better. The model only helps if the cat has habits.

Challenge: try pull=0.3 (a lazier preference for the bed) and a cost of 1 + 5 * pi[s]. When does avoiding the cat stop being worth the extra steps?

6. Kalman filters

Play: Tim Babb: How a Kalman filter works, in pictures. The best-known plain explanation, built from blobs of uncertainty.

The idea: two sources of information, both imperfect: what you expect (I'm driving at 0.5 m/s, so the wall should be 5 cm closer) and what you measure (the noisy sensor). The Kalman filter blends them, trusting each in proportion to how sure it is. Every self-driving car and drone runs one (or a cousin of it).

In Robo-Helper: week 2 averaged 16 readings while standing still. That fails when the robot moves, because the old readings are out of date.

4) KALMAN FILTER: driving towards a wall at 0.5 m/s, sensor noise 1.0 m, 10 readings a second.
   raw readings         typical error 0.56 m
   average of last 16   typical error 0.54 m
   Kalman filter        typical error 0.22 m

Interactive: raw, averaged, Kalman

The robot drives towards a wall. ■ noisy readings   ■ Kalman estimate   grey: average of the last 16   dark: the truth. This demo uses its own random numbers, so its errors differ a little from the Python output above.

Raw error
–
Average of 16
–
Kalman
–

Set the speed to 0: now the robot stands still and the average works well. Speed it up and watch the grey line lag behind.

Challenge: the filter has one knob, q (how much the robot doubts its own speed). Try 0.0001 and 1.0. Which way does it go wrong?

7. Path planning: A*

Play: Red Blob Games: Introduction to A*. Drag walls and goals and compare breadth-first search, Dijkstra and A*.

The idea: search outwards from the start, but always look next at the square that seems closest to the goal ("steps so far + a guess of steps left"). A good guess means far fewer squares looked at. Trust the guess more (weighted A*) and it searches even less, but may no longer find the shortest path.

In Robo-Helper: week 4.

5) A*: the room, start to bin. Plain search vs A* vs weighted A* (trusting the guess more).
   no heuristic (Dijkstra)  path 11 steps, squares looked at 40
   A* weight 1              path 11 steps, squares looked at 35
   A* weight 2              path 11 steps, squares looked at 13
   A* weight 5              path 11 steps, squares looked at 13

In our small room, weighted A* still finds the shortest path. That isn't guaranteed: weighted A* only promises a path at most w times the shortest. On a big map, that trade (a slightly longer path, found much faster) is what a robot with a deadline wants.

Challenge: add walls to ROOM in a copy until weighted A* with w = 5 returns a longer path than plain A*.

8. Signals: Fourier

Play: Jez Swanson: An Interactive Introduction to Fourier Transforms. Draw a shape and watch circles spinning at different speeds trace it out.

The idea: any wiggly signal is a sum of simple waves at different speeds (frequencies). The Fourier transform tells you how much of each. If a wobble comes from the wheels at a steady rhythm, it shows up as one spike, and you can remove just that spike.

In Robo-Helper: week 2's sensor. Averaging can't remove a steady rhythm well; Fourier can.

6) FOURIER: a 64-reading sensor log with a wheel wobble (8 cycles) and noise.
   strongest rhythm found at 8 cycles per log (we put it at 8)
   typical error vs the true distance: 0.44 m before, 0.11 m after removing it

This works on a log you've already recorded. A robot cleaning its readings live would use a filter that only looks backwards; the idea is the same.

Challenge: make the wobble 2 cycles instead of 8. Does the method still find it? (The slow downward drift of the true distance also lives at low frequencies.)

9. Optimisation: gradient descent with momentum

Play: Gabriel Goh: Why Momentum Really Works (Distill). Slide the step size and momentum and watch the path to the bottom of the valley.

The idea: plain gradient descent takes a step downhill each time. Momentum remembers the last steps and keeps rolling, like a heavy ball, so it speeds up along long gentle slopes. Too much momentum and it overshoots and swings.

In Robo-Helper: week 2 fits the braking distance with plain gradient descent.

7) MOMENTUM: Lesson 3's braking-distance fit. Steps until the error is below 0.001.
   learning rate 0.1, momentum 0.0: 73 steps
   learning rate 0.1, momentum 0.5: 35 steps
   learning rate 0.1, momentum 0.9: 37 steps
   learning rate 0.3, momentum 0.0: 24 steps

Momentum halves the steps at the same learning rate, but 0.9 swings and does no better than 0.5. On this easy problem, a bigger learning rate on its own does best. Momentum matters most on long, narrow valleys, which is exactly what the Distill page shows. Big networks have lots of those.

Challenge: try learning rate 0.6 without momentum. What happens, and why does the Distill page say so?

10. Reinforcement learning

Play: Andrej Karpathy: REINFORCEjs. Run the GridWorld demos and watch values spread from the goal; try the "Waterworld" deep Q-learning agent.

The idea: no teacher, only rewards. The robot tries things, remembers how good each move was in each square (its Q table), and slowly prefers the moves that led to reward. It has to explore (try new moves) and exploit (use what it knows).

In Robo-Helper: the Q-learning bonus, and DQN against A* in Module 20.

8) REINFORCEMENT LEARNING: Lesson 7's maze. How much exploring is best? (5 seeds each)
   epsilon  0.0: learned route found by 5/5 seeds (length 7), first 9-step-or-better episode: [7, 7, 7, 7, 7]
   epsilon 0.05: learned route found by 5/5 seeds (length 7), first 9-step-or-better episode: [11, 3, 9, 7, 5]
   epsilon  0.2: learned route found by 5/5 seeds (length 7), first 9-step-or-better episode: [9, 8, 7, 9, 7]
   epsilon  0.5: learned route found by 5/5 seeds (length 7), first 9-step-or-better episode: [18, 14, 23, 21, 7]

A surprise: with no random exploring at all (epsilon 0) it learns fastest. Why? Every step costs −1, and untried moves start at 0, so an untried move always looks better than one that's already cost something. The robot explores on its own ("optimism"). In a big world with distant rewards that trick isn't enough, and exploring matters.

Challenge: change the step reward from −1 to 0 in a copy of q_learn. Does epsilon 0 still work?

11. Transformers

Play: Polo Club (Georgia Tech): Transformer Explainer. A real GPT-2 running in your browser. Type a sentence, then click into the attention heads and move the temperature slider.

The idea: every word asks every other word "how relevant are you to me?" (queries times keys), turns the scores into weights with softmax, and takes a weighted mix of their information (values). Stack that many times and you have the "understanding" half of π0 and GR00T.

In Robo-Helper: you built single-head attention, with backprop by hand, in the week 6 stretch. Its measured gain: new commands 89% → 92% on average over 3 seeds, the same 8/12 on the bake-off. A real nanoGPT on the same robot data is in Module 20.

Challenge: in the explainer, set the temperature to 0.2 and then 2.0 on the same prompt. Then find where Robo-Helper's tiny LM uses softmax, and say what a temperature would do to its plans.

12. Diffusion, and how π0 and GR00T move

Play: Polo Club: Diffusion Explainer. Watch Stable Diffusion turn pure noise into a picture, step by step, and change the prompt and the guidance.

The idea: train a network to remove a little noise at a time. Then start from pure noise and run it again and again until a clean picture appears. Robots use the same trick for motion: start from a random wobble of joint positions and refine it into a smooth arm movement.

What the quoted guide says about π0 and GR00T (summary)

These figures are as reported in the guide, which cites the π0 paper, NVIDIA's repo and the talks it links. We haven't run either model.

In Robo-Helper: no diffusion, and we're honest about why: the robot moves on a grid with A*, so there's no smooth arm motion to generate. But one idea is already there. Since the week-6 rebuild, the tiny LM writes a whole plan at once ("put red blue") instead of one action, which is an action chunk in words. It's what took the bake-off from 5/12 to 8/12.

Challenge (after the course): pick one lecture from the guide's watching order (start with Stanford AA203 lecture 15 on flow matching and action chunks), then read the openpi README and write down what you'd need to run π0 in the LIBERO simulator.

13. Playbook

  1. Play first, for 10–15 minutes, before reading anything. Make a prediction, then test it on the page.
  2. Find the matching Robo-Helper lesson and reread the part that uses the idea.
  3. Run bonus_robot_math.py. Read the before and after numbers, and say in one sentence why they changed.
  4. Do the challenge: change one number, predict what will happen, then run it.
  5. Keep the honest surprises. When an idea didn't help (momentum 0.9, epsilon 0.5, a cat with no habits), write down why. That's real understanding.

14. Self-check

Why did averaging 16 readings work in week 2 but barely help while driving?

Standing still, every reading measures the same distance, so averaging cancels the noise. Driving, the old readings measure distances the robot has already passed, so the average lags behind. The Kalman filter fixes that by moving its estimate forward with the robot's known speed before blending in each new reading.

A* with weight 5 found the same 11-step path as plain A*. Is weighted A* always as good?

No. It only promises a path at most w times the shortest. It happened to be optimal in our small room. The trade is fewer squares searched for a possibly longer path.

The cat-aware route is 2 steps longer. When is that worth it?

When a run-in costs more than two steps, for example if the robot has to stop and replan, or might hurt the cat. With our cat, run-ins dropped from 0.83 to 0.06 per trip. With a cat that has no habits, avoiding it gains nothing.

Why did exploring less make Q-learning faster in Lesson 7's maze?

Optimistic starting values: untried moves are worth 0 while tried ones have cost −1 per step, so the greedy robot keeps trying new moves anyway. Random exploring on top only wastes steps in such a small maze.

What do π0 and GR00T have in common, and where do they differ most?

Both put a vision-language model on top and a flow-matching action head below that turns noise into a chunk of motion. They differ most in data: humans driving robots for π0, video of human hands for GR00T.

15. Glossary & further reading

TermMeaning
Rotation matrixA 2×2 (or 3×3) table of cosines and sines that turns a vector by an angle.
Prior / posteriorWhat you believe before / after seeing the evidence.
Stationary distributionWhere a Markov chain spends its time in the long run.
Kalman gainHow much the filter trusts the new reading versus its prediction.
HeuristicA guess of the remaining cost, used by A* to search less.
FrequencyHow many times per log (or per second) a wave repeats.
MomentumKeeping part of the last step's direction, like a rolling ball.
Epsilon (ε)How often a learning robot picks a random move to explore.
AttentionWeighted mixing of information, with weights from query-key scores.
Flow matching / diffusionTurning noise into data (a picture, a motion) step by step.
Action chunkSeveral future actions predicted at once.