Hadrien Cornier GitHub
Writing / Robotics

From joint angles to a moving arm

From encoder readings to gripper position: a visual guide to robot geometry, servos, and the commands that connect them.

1 · Configuration: a list of anglesq₁ = 30°q₂ = 60°gripperjoint spaceq₁q₂30°60°q = (30°, 60°)q + known rigid links → every link placed and turnedstate = (q, q̇): same q, faster swing → more braking2 · Reading one angleX = A cos θ, Y = A sin θ30°(0.866, 0.5)(−0.866, 0.5)sin 30° = sin 150°: Y alone is ambiguousθ = atan2(Y, X) uses both signs → 30°CORDIC: rotate until Y ≈ 0turn φᵢ = arctan 2⁻ⁱ, shift + addstepturntally1+45°45°2−26.565°18.435°3+14.036°32.471°4−7.125°25.346°…12 steps≈ 30°+ = clockwise turnmax tested error 0.028°3 · The loop inside the servou = KP e + KI ∫e dt + KD ėactionlaptopqd = 30°Σ+−e = 10°PIDumotor + gearsjoint turnsencoderq = 20°observationPproportional: pushes on the error nowIintegral: sums past error → holds a loadDderivative: ė = −q̇ → brakesthe servo repeats this between laptop messages4 · Remove one term at a timeone link · 2 N·m load · target 45.8° · schematic curvesfull PIDwithin 2% after 2.20 sno I7.16° short: 2 N·m ÷ 16 = 0.125 radno D64.3% overshoot, rings ~30 sno Pmoves away, swings grow5 · Forward kinematics: add the linksα₁α₂cos 30° = 0.866sin 30° = 0.50.8 sin 90°(0.866, 1.3)α₁ = q₁ = 30°α₂ = q₁ + q₂ = 90°x = cos α₁ + 0.8 cos α₂ = 0.866 + 0 = 0.866y = sin α₁ + 0.8 sin α₂ = 0.5 + 0.8 = 1.3p = g(q)3D: z = h + Σ Lᵢ sin αᵢx = r cos φ, y = r sin φr < 0 when folded past the pan axis6 · Small turns: the Jacobian1.56shoulder columnelbow columncolumn j = hand velocityfrom joint j aloneJ =−1.3−0.80.8660per radian, at (30°, 60°)shoulder +0.01 radΔp ≈ (−0.013, 0.0087)elbow +0.01 radΔp ≈ (−0.008, 0)shoulder column length 1.56= shoulder-to-hand distance7 · Inverse kinematics: two answersABp*target p* = (0.866, 1.3)A: q = (30°, 60°)B: q ≈ (82.6°, −60°)IK set = { q ∈ Qvalid :g(q) = p* }empty, a few, or a whole familystart from the current q→ favors a nearby solutionvalid endpoint → the pathstill needs a planner8 · Where the hand can go1.80.2ideal 2-link arm, no limits:ring from 0.2 to 1.80.2 = |L₁ − L₂|, 1.8 = L₁ + L₂Franka Panda, sampled:300,000 q inside limits263,270 collision-freegreen cell = accepted sampleblank cell = unresolveduniform in q is notuniform in hand position9 · Pose: position plus orientationxgygzg out of pageR = [ xg yg zg ]columns = gripper axes in worldRz(90°) =0−10100001axes ⟂, length 1: RᵀR = Ino mirror flip: det R = 1R ∈ SO(3), pose (p, R) ∈ SE(3)twist about the hand's own z:Rnew = Rold Rz(θ)grasp = reach + useful R + clearance10 · Who writes the target?Planner: grasp pose → IK → path + timingACT: images + q → chunk of joint targetsHand-pose model → IK or Cartesian controlVLM picks goal → VLA makes motionservo loopqd → e → upanel 3The command must match the controller:command type · units · frame · timingposition, velocity or torque
Whole board

Tell an SO-101 shoulder to go to 30°. It swings there and holds against a load. How does a number become controlled motion? And how do measured angles tell us where the gripper is and which way it points? We'll follow a toy arm with two links of length 1 and 0.8, shoulder at 30°, elbow at 60°.

The robot knows a list of angles

The SO-101 has five arm joints plus a gripper actuator, and each smart servo measures its own angle. A Franka Panda has seven rotary arm joints plus sliding fingers. Stack the angles in one list, q = (q₁, …, q₇): that is the configuration, and the space of all such lists is joint space. The links are rigid with known shapes, so q fixes where every link sits and how it is turned.

Franka Panda with its seven arm joints named and their rotation axes marked
The Panda's seven arm joints, each with the axis it turns about.

Turn only the Panda's wrist: the joint centers stay put and the gripper can keep pointing the same way, yet the hand rolls about its own axis. Joint centers or a pointing direction miss that roll.

Simulated Panda: only the wrist turns while the upstream joints stay fixed. (MP4)

q is a snapshot, though. Two arms at (30°, 60°), one still and one swinging fast, need very different braking in the next instant. So the mechanical state is the pair (q, q̇): angles plus velocities. A robot that senses its own joints is doing proprioception (Latin proprius, one's own).

How a servo reads its own angle

Take the AS5600, a chip that sits under a small magnet on the motor shaft and reads the magnet's angle. The field pushes sideways on charges moving through the chip's Hall elements, which makes a small voltage, and the electronics turn this into two signed signals a quarter turn apart. Those get digitized, and the angle comes from them:

X = A cos θ, Y = A sin θ

Magnet on the shaft above a Hall sensor chip, and the chain from analog signals to a digital angle
Magnet, sensor and the signal chain from voltages to an angle.

At our 30°, with A = 1, (X, Y) = (0.866, 0.5). Why two signals? Because one is ambiguous: sin 30° = sin 150° = 0.5. The cosines have opposite signs, and that settles it: θ = atan2(Y, X) uses both signs to pick the right quadrant.

Angles of 30 and 150 degrees on a circle with the same sine and opposite cosines
30° and 150° share a sine of 0.5; their cosines have opposite signs.

The AS5600 computes atan2 with a hardwired block called CORDIC (Coordinate Rotation Digital Computer), and the trick is lovely. Rotate the vector (X, Y) in the registers (the magnet stays put) until it lies flat on the x-axis, and keep a tally of the turns. The tally is the angle. The clever part is choosing turns whose multiplications become divisions by 1, 2, 4, 8 and so on, which are just shifts in binary. Those stored angles are φᵢ = arctan(2−i), and each step needs only shifts and adds:

xnew = x + 2−i y, ynew = y − 2−i x (clockwise; flip both signs to turn back)

Turn clockwise and add φᵢ when y is positive; turn back and subtract it when y is negative. Each step is an exact rotation plus a stretch, so error comes only from stopping after finitely many steps and from rounding the stored numbers.

Is that the fast way, though? I benchmarked three methods, and all three stayed within half a 12-bit encoder step (360°/8192 ≈ 0.0439°). CORDIC beat a basic Taylor series by about 55×. But a Taylor series with extra range reduction was about 6× faster than CORDIC, on native C++ on an Apple M1 Max laptop. A sensor chip wants something else: one small dedicated circuit that repeats shift, add, subtract and lookup. That is CORDIC.

How the encoder finds the angle: the CORDIC derivation and the benchmark

The hardware. A Seeed Grove board with the AS5600 was listed at US$6.50 for one on 2026-09-28, before tax and shipping.

Why shifts and adds rotate the vector. A clockwise rotation by φ is

xrot = x cos φ + y sin φ = cos φ (x + y tan φ)
yrot = y cos φ − x sin φ = cos φ (y − x tan φ)

For 0° ≤ φ ≤ 45° the common factor cos φ is positive, so dropping it keeps the direction and only stretches the vector. Rotating (1, 0) clockwise by 45° gives (0.707…, −0.707…); the update without cos φ gives (1, −1), the same direction with a greater length. With tan φᵢ = 2−i, the remaining factors at i = 0, 1, 2 are 1, 1/2, 1/4, which scaled integers apply as right shifts. Both coordinates update from the old values at the same time.

The recurrence for the 30° example:

x₀ = X, y₀ = Y, a₀ = 0; dᵢ = +1 if yᵢ ≥ 0, otherwise −1
xi+1 = xᵢ + dᵢ 2−i yᵢ, yi+1 = yᵢ − dᵢ 2−i xᵢ, ai+1 = aᵢ + dᵢ φᵢ

The first floating-point step gives x₁ = 1.366, y₁ = −0.366. When y gets close to zero, the tally a is close to the input angle. Inputs anywhere on the full circle need a few extra sign tests and possible negations first. In integers, (887, 512) is about 29.995°. The first update gives (1399, −375); the negative y triggers a reverse turn, and the next shift is 1399 >> 1 = 699, a division by a power of two rounded down.

Twelve integer CORDIC steps: old coordinates, shifts, updates, the angle tally and the vector direction. (MP4)

The first four turns for (X, Y) = (0.866, 0.5), with rounded values:

StepTurnAngle estimate
1+45°45°
2−26.565°18.435°
3+14.036°32.471°
4−7.125°25.346°

The Taylor competitor. The series arctan z = z − z³/3 + z⁵/5 − … converges slowly near z = 1. Signs and axis swaps reduce any input to α in [0°, 45°], so z is in [0, 1]. Above 22.5°, the identity arctan z = π/4 + arctan((z − 1)/(z + 1)) shrinks the series input to at most tan 22.5° = tan(π/8) ≈ 0.4142. At z = 0.8 the new input is −1/9 ≈ −0.111, and the three terms w − w³/3 + w⁵/5 plus 45° give 38.6598066°, against a reference of 38.6598083°. Three terms on z directly give 39.81308°.

The benchmark results over 1,114,197 coordinate pairs, as the largest error over the tested inputs and the time on the tested laptop:

MethodWorkLargest tested errorTime per angle
Basic Taylor326 terms0.04394°590.6 ns
CORDIC12 steps0.02798°10.78 ns
Range-reduced Taylor3 terms0.01512°1.79 ns

The core operation counts at source level:

MethodAdditions and subtractionsMultiplicationsRight shiftsTable entries
12-step CORDIC36 integer02412
326-term basic Taylor325 floating-point3270326
3-term reduced Taylor2 floating-point403

CORDIC also does 12 sign checks, full-circle handling with extra sign tests and possible negations, and one conversion and one multiplication to output floating-point radians. Taylor needs one coordinate-ratio division plus signs and axis swaps; the reduced method sometimes adds a second division and the π/4 restoration, and on the timing inputs it averaged 4 multiplications, 4.50 additions or subtractions and 1.50 divisions. Compiler instruction selection differs from these counts, loop bookkeeping and checksums are excluded, and a division costs more than a shift.

Protocol: every method got identical coordinate pairs rounded to 30 fractional bits (Taylor got the exact floating-point values of those rounded numbers), input preparation stayed outside the timing, and the system double-precision atan2 was the reference. Timing used 65,536 fixed-seed inputs, 64 passes per trial, a rotating method order, Apple Clang 21 with -O3 and floating-point contraction disabled, and media rendering stopped. Each time is the median of 11 trials. Implementations, raw timings, operation counts and accuracy checks are in encoder-benchmark.

The feedback loop inside the servo

Now we can measure q, so back to the command. The SO-101 servo packs a motor, the encoder, a driver, gears and a controller into one case. The laptop's message reaches it through a USB adapter and the servo bus, and the servo keeps running its own feedback loop between messages. The commanded angle is the action; the encoder reading is an observation of the current state.

Laptop connected through a USB adapter to the servo bus, with a feedback loop inside each servo
The laptop talks to the bus; the feedback runs inside each servo.

Say the target is qd = 30° and the encoder reads q = 20°, so the error is e = qd − q = 10°. The standard controller model here is PID (I have not checked the servo's exact firmware):

u(t) = KP e(t) + KI ∫0t e(s) ds + KD ė(t)

u is the motor drive the controller asks for, and the K gains set how strong each correction is. P (proportional) pushes on the error right now. I (integral) pushes on the error summed over time, so it keeps pushing after the error reaches zero. D (derivative) reacts to how fast the error changes; with a fixed target ė = −q̇, so D brakes harder the faster the joint moves.

Error curve showing the present error, the accumulated area and the slope used by the three PID terms
What each term reads: the error now, the area under it so far, and its slope.

Why bother with I? Hang a constant load on the joint. P only pushes when there is error, so the joint settles short of the target, where KP e balances the load. The integral grows while that gap lasts and keeps its value once the gap closes, so it ends up holding the load at the target.

Schematic simulation: the integral accumulates until it supports a 2 N·m load at the target. (MP4)

Remove one term at a time

I checked these roles in a simulation of one link turning in a horizontal plane. It starts at rest at 0°, and we ask for 45.8° while a constant 2 N·m torque pushes against it. Each run removes one controller term and keeps everything else the same. The board compares the outcomes. Without D, the link's own friction eventually calms the ringing; the growing swings without P belong to these particular gains.

Full PID, no I, no D and no P side by side: 24 simulated seconds at 2× playback. (MP4)

The simulation drives torque directly with no limit. Under another load or pose the same gains can behave differently, so some controllers change gains with the joint, pose or load.

Simulation setup, checks and damping

M q̈ = u − b q̇ − 2, u = 16 e + 4 ∫0t e(s) ds − 7 q̇

M = 1 kg·m² and b = 0.5 N·m·s/rad. The angle, velocity and integrated error start at zero, and each ablation sets one gain to zero. Without I, the resting derivative term is zero, so P must supply 2 N·m: with KP = 16 that takes 2/16 = 0.125 rad ≈ 7.16° of error. The controller applies continuous torque directly with no torque limit, and the derivative term uses measured velocity so a target change does not cause a kick. The integration step was 2 ms, repeated at 1 ms, and the angles matched the exact linear-system solution within 10−7 rad. Settling means staying within 2% of the target for the rest of an 80 s run. The system poles confirm the no-P instability. Code, parameters and complete traces are in pid-ablation.

Damping. For one joint with a fixed target under PD control:

M ë + (b + KD) ė + KP e = 0, ζ = (b + KD) / (2√(M KP))

ζ is dimensionless. For 0 < ζ < 1 the joint is underdamped and overshoots with oscillation; ζ = 1 is the critical boundary; for ζ > 1 it is overdamped and approaches more slowly without oscillating. This ideal second-order model assumes positive M and KP and leaves out integral action, gravity, delay and contact. With the simulation's numbers and the integral ignored, ζ = (0.5 + 7)/(2·4) ≈ 0.94; with KD removed, ζ = 0.5/8 ≈ 0.06, deep in the ringing regime.

Underdamped, critically damped and overdamped joints moving to the same target. (MP4)

From angles to the gripper

Now the second question: given q, where is the gripper? That is forward kinematics (kinematics: motion without its forces; dynamics adds the forces and torques). Each joint angle is measured from the link before, so the link directions add up: α₁ = 30° and α₂ = 30° + 60° = 90°. Each link then adds its length times the cosine and sine of its direction:

x = cos q₁ + 0.8 cos(q₁ + q₂) = 0.866 + 0 = 0.866
y = sin q₁ + 0.8 sin(q₁ + q₂) = 0.5 + 0.8 = 1.3

One, two and three planar links with cumulative angles and summed link projections
One, two and three links: relative angles add into directions, and the projections add into the gripper position.

The SO-101's bending joints work in a vertical plane, so the same sum gives a signed reach r and a height z. The pan angle φ then swings that plane around the vertical: x = r cos φ, y = r sin φ. Call the whole map p = g(q). It takes a point in joint space to a point in task space, where the hand lives. Try it below.

Simplified SO-101 side view with reach and height, and top view with the pan angle
Simplified SO-101: reach r and height z = h + Σ Lᵢ sin αᵢ above a shoulder at height h (side), and the pan angle φ that turns r into x and y (top). r goes negative when the arm folds back past the pan axis, so the horizontal distance is |r|.

q = (30°, 60°), hand at (0.866, 1.300). Dashed: the other elbow branch.

Our toy arm, L₁ = 1 and L₂ = 0.8. The shaded ring is every hand position it can reach with no joint limits.

Small turns: the Jacobian

Nudge the shoulder a little. Which way does the hand go, and how far? Differentiate g and you get the Jacobian: ṗ = J(q) q̇. Column j is the hand velocity from turning joint j alone at unit speed, and for small changes Δp ≈ J(q) Δq. At (30°, 60°):

J(q) =
−sin q₁ − 0.8 sin(q₁+q₂)−0.8 sin(q₁+q₂)
cos q₁ + 0.8 cos(q₁+q₂)0.8 cos(q₁+q₂)
=
−1.3−0.8
0.8660

J changes with q. Compare the extended and folded arms below: the same shoulder turn moves the hand different distances.

Extended and folded arms after the same shoulder turn, with different gripper displacements
The same shoulder turn, extended and folded: the gripper moves different distances.

At (30°, 60°), well inside the valid region, the two columns point in different directions, so mixing shoulder and elbow turns can move the hand in any direction in the plane. That is what rank 2 means here, and the set of hand velocities you can produce is J's image. No nonzero mix leaves the hand still, so J's kernel, the joint velocities that hold the hand still to first order, contains only zero. The Panda needs rank 3 for hand position, and with seven joints it has kernel to spare: the elbow can swing while the hand stays put.

Going backwards: inverse kinematics

Flip the question. Given the target p* = (0.866, 1.3), which q gets there? Our arm has two answers: (30°, 60°), and the mirror image with the elbow on the other side, about (82.6°, −60°). In general, inverse kinematics returns a set:

{ q ∈ Qvalid : g(q) = p* }

Qvalid applies joint limits and whichever collision checks you chose, so the set can be empty, a few points, or a whole family. Now suppose the solver picks one elbow arrangement for this target and the other one for the next, slightly shifted target. The hand barely needs to move, but the elbow jumps across! Starting each solve from the arm's current angles usually helps it find the nearby answer. And a valid endpoint still says nothing about whether a safe path reaches it.

Two simulated Panda configurations with the same gripper pose at a cube and elbows in different places
One gripper position and orientation at the cube, two Panda configurations, elbows about 38 cm apart.
Alternating between two valid IK solutions, against choosing the solution nearest the previous one. (MP4)

Where the hand can go

Which targets have any answer at all? The reachable positions are g(Qvalid). For our ideal arm with no joint limits, that is the ring on the board, from 0.2 to 1.8 around the shoulder. Joint limits, self-collision, link thickness, obstacles and the table all carve away more.

For the Panda, I drew 300,000 configurations uniformly inside the seven arm-joint limits, fingers open, and 263,270 passed the recorded self- and environment-collision checks (table, ground and a task cube). Forward kinematics turns each one into a hand position. In the face-on grid below, a green cell holds at least one accepted sample, so the hand can reach it. A blank cell has no accepted sample, so its reachability stays open. Uniform sampling in joint space also spreads hand positions unevenly.

Left: a 6 cm slab moves sideways through the sampled hand positions, with the fixed arm for reference. Right: the face-on cut in 4 cm cells, forward or back from the base against height, above the table. Green means at least one accepted sample. (MP4)
A first guess at the envelope

Before sampling, you can guess an outer envelope. With a hypothetical 180° pan and the hand kept above the table, the outer shape is a quarter ball. Finite link thickness, self-collision, the environment and joint limits remove more positions, and an ideal two-link arm cannot bring its hand closer to the shoulder than |L₁ − L₂|. The model, joint limits, collision rules and sampled data are in workspace.

Hypothetical quarter-ball workspace envelope from a 180 degree pan above a table
A hypothetical envelope, not a measured workspace.

Position is half of a grasp

Reaching the stem of a wine glass still falls short of grasping it: the gripper also needs a useful orientation and room for its fingers. To write orientation down, take the gripper's three axes in world coordinates and stack them as the columns of a matrix R. The axes stay perpendicular and have length 1, which is RᵀR = I, and they describe a rotation with no mirror flip, which is det R = 1. These rotation matrices make up SO(3), and position plus orientation, (p, R), make a pose in SE(3).

Simulated Panda: the target point stays fixed while the hand orientation changes. (MP4)
One grasp target on a glass with several hand orientations
One grasp target, several hand orientations.

Our toy hand points along its last link at α₂ = 90°, so its orientation is a rotation of 90° about z:

Rz(θ) =
cos θ−sin θ0
sin θcos θ0
001

The first column, (cos θ, sin θ, 0), is the gripper's first axis. The second is a quarter turn ahead, so at 90° it points left. Now take a tilted Panda hand and twist it another 30°. Around the world's z-axis, or around the hand's own tilted z-axis? Those are different moves. For the hand's own axis, the extra rotation goes on the right: Rnew = Rold Rz(30°).

Rotated basis vectors drawn next to the columns of the rotation matrix
Rotate the basis vectors, and they become the columns of R.

Who writes the target?

  • A classical pipeline picks a grasp pose, solves IK for the joint endpoint, plans a collision-free path and its timing, and sends the intermediate joint targets to position-controlled servos.
  • ACT, in its original ALOHA setup, reads images and measured joint positions and predicts a chunk of future joint targets. Consecutive chunks can disagree about the same future instant, so we can average the overlapping predictions to smooth the commands; this optional step is called temporal ensembling.
  • A learned model predicts hand poses or displacements in task space, and IK or a Cartesian controller converts them into commands the robot accepts.
  • A VLM (vision-language model) can pick a high-level goal while a VLA (vision-language-action model) produces the motion. Some VLAs read images and instructions directly, with outputs in joint or task space.
Planned and learned command sources converging on servo feedback
Planned and learned command sources, all converging on servo feedback.

Whichever you pick, the command has to match what the controller accepts: position, velocity or torque, in the right units, coordinate frame and timing.

When an arm misbehaves, you now know where to look: an unreachable pose, an IK branch flip, gains tuned for another load, or a command in the wrong frame.

Robot renderings come from simulation; the planar and control animations are teaching schematics. Inspiration: this article. Asset credits and licenses: ASSET-NOTICES.

← All writing