Q-learning robot arm

2D twin of the 3D arm: the same environment and learner, with a Q-value heat map of the joint space below the arm.

Switch to 3D

Presets

Playback

Learner and scene

Presets change the learning rate, discount, exploration and the scene.

Training

Drag in the picture

Layers

Model checks

The science

The arm as a decision problem. A 2-link planar arm (links 1.4 m and 1.2 m, shoulder 0.6 m above the floor) has its shoulder angle split into 15 bins from -20 to 160 degrees and its elbow into 21 bins from -160 to +160 degrees, giving 315 joint states. An action nudges one joint by one bin (4 actions). Each move costs -1, reaching a goal cell (tip within 0.2 m of the goal point) pays +20 and ends the episode, and a move into a collision (a link touching the red keep-out ball or the floor) is refused with -5.

Q-learning. The agent keeps a table Q(s,a) and updates it after every move: Q(s,a) ← Q(s,a) + α[r + γ maxa′Q(s′,a′) − Q(s,a)]. It picks a random move with probability ε and the best known move otherwise. The bracketed term is the temporal-difference (TD) error; it shrinks as the table approaches the Bellman optimality equation Q*(s,a) = r + γ max Q*(s′,·).

The exact answer is known. Because the environment is small and deterministic, the page also solves it exactly by value iteration and breadth-first search. That lets you see how far learning is from the truth: the graph of RMS(max Q − V*), the share of start poses (poses cut off from the goal by the ball are left out) from which the greedy policy reaches the goal, and the number of moves compared with the true shortest path. The 3D arm replays the current greedy policy, so you see the learning progress as behaviour.

Honest simplifications. Real robots use continuous joint angles, dynamics, sensor noise and usually function approximation or model-based control, not a 315-entry table; this is a classroom model of reinforcement learning, not a controller. Only a 2D plane and two joints are modelled, the obstacle is a ball in that plane, and the angle grid is coarse (adjacent bins are 13 and 16 degrees apart). The arm is a generic design and not a model of a particular product.

What to try
  • Start with Default: ball in the way and watch the left graphs: the share of start poses that reach the goal climbs while the Q-table error against the exact value-iteration answer falls.
  • Try No exploration (greedy) and Too much exploration: with epsilon at 0 some states are never visited, with epsilon near 1 the policy is learned slowly.
  • Drag the goal or the red keep-out ball in the picture: the environment changes, the table is forgotten and the arm learns a new detour.
Greedy policy success rate
Q-table error against the exact solution
Q-value map of the joint space
Mean temporal-difference error
Made with 🟠 Blender