30% off your first 3 months

Get the deal

Forward kinematics of a two-joint arm

by DuckyHelperNov 12, 20265 min read
Robotics

TL;DR:

  • Forward kinematics turns joint angles into the position of the hand, and it always has exactly one answer.

  • For a planar two-link arm, x = L1 cos θ1 + L2 cos(θ1 + θ2) and y = L1 sin θ1 + L2 sin(θ1 + θ2).

  • Check the result with a sketch and with the distance formula before trusting it.

A robot arm knows the angle of each joint from its motor encoders. What it needs to know is where its hand is. Getting from the first to the second is forward kinematics, and for a two-joint arm it is a few lines of trigonometry that you can do by hand.

What it does on a robot

Every arm program that moves a hand to a place needs both directions: forward kinematics (angles to position) and its reverse, inverse kinematics (position to angles). Forward kinematics is the easy one. Given the joint angles, there is exactly one hand position. It is used to show where the arm is, to check for collisions, and as a building block of inverse kinematics.

Frames and angles

Pick a frame: an origin and axes. Put the origin at the shoulder, the x-axis pointing forward (to the right on your page) and the y-axis pointing up. Angles are measured counterclockwise from the +x axis.

There are two ways to measure the second joint, and mixing them up is the commonest mistake.

  • Absolute: the angle of link 2 from the x-axis.

  • Relative: the angle of link 2 from link 1. This is what a motor at the elbow measures.

Here we use the relative angle. If link 1 points at θ1 and the elbow bends θ2 further, link 2 points at θ1 + θ2 from the x-axis.

The equations

Link 1 has length L1 and link 2 has length L2. The elbow sits at the end of link 1:

elbow = (L1 cos θ1, L1 sin θ1)

The hand is the elbow plus link 2:

x = L1 cos θ1 + L2 cos(θ1 + θ2) y = L1 sin θ1 + L2 sin(θ1 + θ2)

Each link is a vector of known length and direction, and the hand is the sum of the two vectors.

Let L1 = L2 = 1 m, θ1 = 30° and θ2 = 45°. Link 2 points at 30° + 45° = 75°.

  1. Elbow. x = cos 30° = 0.8660, y = sin 30° = 0.5000. So the elbow is at (0.866, 0.500).

  2. Link 2 vector. cos 75° = 0.2588, sin 75° = 0.9659.

  3. Hand. x = 0.8660 + 0.2588 = 1.1248 m, y = 0.5000 + 0.9659 = 1.4659 m.

So the hand is at about (1.125 m, 1.466 m).

Checking with a sketch

First sketch it. Link 1 rises at a gentle 30°. Link 2 bends up more steeply, to 75°. So the hand should be up and to the right of the elbow, with more rise than run. Our answer does that: the elbow is at (0.87, 0.50) and the hand is 0.26 to the right and 0.97 above it.

Then use a second route. The distance from the shoulder to the hand can be found from the law of cosines. The angle between the links at the elbow is 180° − θ2 = 135°, so:

r² = L1² + L2² − 2·L1·L2·cos 135° = 1 + 1 + 1.4142 = 3.4142, so r = 1.8478 m.

Now from the hand coordinates: 1.1248² + 1.4659² = 1.2652 + 2.1488 = 3.4140, so r ≈ 1.8478 m. The two routes agree.

One more check: the direction of the hand from the shoulder is atan2(1.4659, 1.1248) = 52.5°, which is 30° + 22.5°. That fits, because the hand lies halfway between the directions of the two equal links (30° and 75°), and the midpoint is (30° + 75°) / 2 = 52.5°.

Where it goes wrong

  • Degrees and radians. Most programming languages expect radians in sin and cos. Convert with rad = deg × π / 180.

  • Relative or absolute. Using θ2 where you needed θ1 + θ2 puts the hand in the wrong place. The sketch check catches this.

  • Zero positions and signs. The real motor's zero may not point along +x, and some motors count clockwise. Calibrate: measure the real hand position at a few angles and adjust offsets and signs.

  • Link lengths. Measure them from joint axis to joint axis, not from the outside of the case.

  • Bending and slop. Real links flex and gears have backlash, so the real hand is a little off the computed one.

Safety: Check forward kinematics in simulation or with the arm powered off and moved by hand before commanding it. A sign error here can send an arm swinging into the table or into you. Keep clear of the arm's reach when powering up and have an emergency stop.

How real robots use it

Arms with six or seven joints use the same idea with matrices (a rotation and a translation per joint, multiplied in order), but the principle is the one above: add up the contribution of each link in the base frame. The result tells the controller where the tool is, which feeds collision checks, camera overlays and the planning methods in later articles. How many joints you need to reach any pose is the subject of degrees of freedom.

Try it yourself

Cut two strips of card, 10 cm each, and pin them together at the elbow and at a shoulder point on paper. Set θ1 = 30° and θ2 = 45° with a protractor. Measure the hand position with a ruler and compare it to (11.25 cm, 14.66 cm), which is the example scaled to 10 cm links. Then try θ2 = 0° and θ2 = 90° and predict the answers first.

Frequently asked questions

Why does forward kinematics have only one answer?

Each joint has one angle, so each link ends at one definite place, and the hand is the sum of those places. The reverse problem, inverse kinematics, can have several answers or none.

Do I need matrices for a two-joint arm?

No. Two links in a plane need only sines and cosines. Matrices become useful when you have more joints or work in three dimensions.

Get started

DuckyHelper can
do more

It sees your screen and works in any app you use. Try it for 10 minutes, no card.

Get it for Mac, Windows or Linux

Share

Questions and jobs

Do anything

Ask it a question or hand it a job, in any app.

Doing jobs for you is in early access on Mac. Asking works on Mac, Windows and Linux.