Part 1 · How robots move

7Getting the hand there: inverse kinematics

Point at a spot and the robot has to find the joint angles that put its hand there. Sometimes there are two ways to do it, sometimes none. Drag a star and watch it work.

This assumes: Where is the hand? Forward kinematics. About 9 minutes of reading.

Reach out and put your finger on the edge of the desk. You did not choose a shoulder angle and an elbow angle and then see where your finger landed. You chose where the finger should go, and the angles took care of themselves. A robot is not so lucky. Its motors understand only angles, one number per joint, so when it is told "put the hand here", something inside it has to turn that place into angles first.

Inverse kinematics is the name for working out the joint angles that put the hand at a chosen place. It is forward kinematics run backward: last module you were given the angles and found the place; this time you are given the place and must find the angles. Forward has a step-by-step working and always one answer. Backward has neither.

Why there are two elbows

Take the arm from last module and lock its wrist straight, so the forearm and the last link act as one 40 cm piece. Now there are two joints to find, a shoulder and an elbow.

The shoulder is bolted down. The upper arm is 30 cm long and rigid, so wherever the elbow ends up, it is exactly 30 cm from the shoulder: somewhere on a circle of that radius, drawn around the shoulder. Call it the small circle. The lower piece is 40 cm long and rigid, so if the hand is on the star, the elbow is exactly 40 cm from the star: somewhere on a second, bigger circle, drawn around the star. The elbow must be on both circles at once.

Two circles that overlap cross in two places. That is the whole story. There are two spots the elbow can be, one above the line from shoulder to star and one below it. Pick one and the angles follow: the shoulder's angle is whichever way the upper arm must point to put the elbow there, and the elbow's angle is the bend from that direction round to the lower piece, which is last module's working read backward. Robot people call the two answers elbow up and elbow down. Both put the hand on the star. Neither is wrong.

Now slide the star further away. The circles pull apart until they touch at one point, with the arm stretched dead straight, and then they do not touch at all. Nothing is broken: there is no elbow position that is 30 cm from the shoulder and 40 cm from a star that is 80 cm away. The place is out of reach, and inverse kinematics has no answer to give. It fails the other way too: a star closer to the shoulder than 10 cm, the difference between the two lengths, sits inside the small circle with the big one wrapped round it, and they never cross.

How a robot actually finds the angles

For two joints in a flat plane you could draw the two circles. A real arm has six joints reaching into three dimensions, and there is no picture to draw. So most robots do something plainer: they guess, check, and correct.

The check is last module's forward working. The first guess is wherever the arm is now. Run the working on those angles and you know where the hand is. If it is not on the star, there is a gap, and the job is to shrink it.

To shrink it, the computer scores each joint. It takes one joint, nudges it by a hair on paper, runs the working again, and sees how much closer to the star the hand would get. That is the joint's score. It does the same for the next joint, and the next.

Then it turns every joint a little, all at once, the ones with bigger scores by more. Only a little, because a score is true for a hair's worth of turn and no further. Then it runs the working again, measures the new gap, scores the joints again, and takes another small step. A few dozen rounds of this and the hand is on the star to a fraction of a millimeter. It happens in less time than one frame of video.

Every step shrinks the gap. So the search slides downhill to whichever answer is nearest to where the arm started, and it stays there. To get from one elbow to the other, the hand would have to leave the star and come back, which means the gap growing before it shrinks again, and a search that only walks downhill will not do that.

So to get the other answer, the robot has to be told which one you want. Look at the two crossings again: in one the arm bends forward at the elbow, a positive angle, and in the other it bends back, a negative one. Tell the robot which sign to keep, and it starts with the elbow bent that way and never lets the sign change while it searches. That is what the Elbow buttons in the box do.

And when there is no answer at all, the steps stop helping. Straightening the arm toward the star is the only thing that still shrinks the gap, so the arm stretches, the gap stops shrinking, and the robot reports the place as unreachable.

Try it

In the box, the arm from last module holds its wrist locked straight. A gold star floats in front of it, and this time you do not touch the joints: you drag the star, and the arm finds the angles itself. Drag it with the mouse or a finger, or nudge it a centimeter at a time with the back, forward, up and down buttons under the box, or with the arrow keys once you have clicked those buttons. The star stays in the arm's flat plane and never goes below the floor. Reset puts the star back where it started and the arm back on it.

The star is gold while the robot's search, on the side you chose, gets the hand onto it, and gray when the search cannot: gray is the robot's verdict, not a fact about the circles. Under the box, a line says where the star is, x forward of the base and z above the floor, and either that the hand is on it or how far short the hand is. Below that is "The arm's answer": the shoulder and elbow angles the robot went to, counted the same way as last module, positive bending forward. The Elbow buttons tell the robot which side to search on; Down is chosen when the box opens, and Reset chooses it again. Slow, in the toolbar, runs everything at a quarter speed. One more fact about this arm: its shoulder can turn about 150 degrees each way from upright and no further, and nothing on it can pass through the floor. The star starts where you left it last module, at x 30, z 48, and the answer the arm has found is the one you found: shoulder 90, elbow −90.

Loading the simulation. The robot runs in your browser, so the first one takes a few seconds to arrive.

This is easier on a larger screen, but it works here too.

What you saw

Wherever you take the star, the hand follows, and every place you put it the robot turns into a pair of angles, many times a second. At x 30, z 48 the answer is 90 and −90, the pair you built by hand last module: the same place, from the same side, has the same angles. Drag the star anywhere and back and the same pair comes back with it.

Then you pressed Elbow Up, and the arm swung through to a new shape with the elbow high and the shoulder leaning slightly back, shoulder −16, elbow 90, and the hand landed back on the same star. Two answers, one place. The hand left the star on the way, because an arm cannot jump between shapes; the robot can use either elbow, but switching costs a swing.

Dragging forward, the arm straightened as the two circles pulled apart, and past about x 58 the star turned gray with the elbow reading 0: the arm pointing straight at the star and able to get no closer. Nudging back, the star turned gold again at the place where the stretched arm could just touch it.

The last try was the unfair one. With the star down by the floor and Elbow Down still chosen, the star stayed gray and the arm settled folded up and away from it, the line reporting the hand some 40 cm short. Draw the two circles for that star and they do cross twice, but the lower crossing is 22 cm below the floor, and to put the elbow there the shoulder would have to turn past 180 degrees. The wall is the shoulder's limit of about 150: the search knows nothing about the floor, and never needed to. With that crossing ruled out, no shape on the down side puts the hand on the star, and there was no stretch to make either, since the star sits only 30 cm from the shoulder and straightening would carry the hand past it. So the search walked downhill from where the arm was into a fold where every small turn made the gap larger, and a search that only walks downhill stops there. Elbow Up reached the star at once, shoulder 16, elbow 131. The place had one usable answer, not two, and the robot found it only when it was allowed to look on the right side.

Why a robot cares

Almost everything a robot arm is asked to do is given as a place, not as angles: pick from here, weld along there, put the cup down on that. Inverse kinematics turns every one of those instructions into something the motors can act on, and it runs every time the hand moves, for every point along the path. A place with no answer cannot be reached at all; a robot asked for it stops with an error, and someone has to move the part or the robot. A place with two answers needs a choice, and the choice has consequences: one elbow may swing the arm into the table on its way, or run a joint into the end of its range. The next module asks the question that comes before either: of all the places around a robot, which can the hand reach at all?

Watch

Fanuc Jogging in World Mode — Andrew Dahlen (5:08 of it, starting at 6:09)

Why this video
It is inverse kinematics running on a real robot. Last module this instructor showed the pendant turning joint angles into millimeters; now he switches the pendant to World mode and presses one key, X plus. The robot's hand moves in a dead straight line, and to do that the controller has to find fresh joint angles for every point along the way, several joints turning at once at different speeds. He is asking for a place, not for angles, and something inside the robot is doing the working backward, many times a second.
What to watch for
At 9:09 he presses X plus and says the robot is "articulating multiple axes at the same time" to move in a straight line: that is the computer solving for angles as it goes. Watch the elbow and shoulder turn opposite ways to keep the hand level. From 9:40 the same for Y and then Z; at 10:41 Z negative heads straight for the table and he says so, which is why this module's star is not allowed below the floor.

Words introduced

inverse kinematics
Working out the joint angles that put the hand at a chosen place. The opposite direction from forward kinematics, and unlike it, there may be two answers, a whole family, or none.

Where next

Suggested next: 8. Reach: where the hand can and cannot go — Every robot arm is surrounded by an invisible shape, the set of all places its hand can be. Sweep a star through the air around a real arm and paint that shape.