15Knowing where your own joints are: encoders
Every joint on the arm reports its angle as a whole number, and those numbers are all the robot has. See where the six encoders sit, read what they report, and find out what they cannot tell you.
This assumes: Joints: the ones that turn and the ones that slide. About 9 minutes of reading.
Close your eyes and touch your nose. You will land on it, or near it, because your joints report their angles to you even in the dark. The arm in the box below has that sense and nothing else: six small sensors, one at each joint, and the numbers they send.
The sensor in the box
The second module said a small device inside every servo measures how far its shaft has turned. An encoder is the sensor inside a servo that reports how far its shaft has turned, as a whole number of steps around the circle. There is one in every motor on this arm, six in all, and it is the only way the arm knows where any of its joints are.
Here is how the ones in this arm work. A small magnet is fixed to the end of the shaft, and a chip sits right beneath it, not touching. A magnet's pull reaches out around it in a definite direction: hold a compass near one and the needle swings to point along it. That reach is the magnet's field, and it turns when the magnet turns. The chip senses which way the field runs across its face by a trick. A magnet pushes sideways on an electric current. That push is what spins every electric motor: inside one are magnets and coils of wire, and the magnets shove on the current in the coils. Here the chip drives a current along a thin strip of metal, the same shove crowds it toward one edge, and the crowding shows up as a tiny voltage, a push of electricity, between the strip's edges. The shove is strongest when the field crosses the strip square on and fades to nothing when the field runs along it, so the chip has a few such strips facing different ways, and from how much each one is crowded compared with the others it works out which way the field runs, to a small fraction of a degree. Turn the shaft and the field turns with it, so the chip is reading the angle of the shaft with no moving part of its own.
The chip has one more job. It could pass that tiny voltage straight on, but a voltage that varies arrives changed: along a wire it picks up stray pushes from everything electrical nearby, and the computer at the far end has no way to tell what was the angle and what was the journey. So chips talk to each other in pulses that are either fully on or fully off, which survive the trip because a small stray push on a pulse that is fully on still reads as on. One pulse is one yes-or-no answer, on for yes and off for no, and this chip turns its angle into twelve of them: is the shaft in the first half of the circle or the second? Which half of that half? And so on, twelve times. Twelve answers pick out one of 4,096 equal steps around the circle, because two multiplied by itself twelve times is 4,096, and what leaves the chip is the number of the step the shaft is on. Why twelve? Because the chip's reading is only so sure of itself; finer than that would be guessing. Each step is a tick: one step of the encoder's count, and so the smallest turn it can report. A full turn is 360°, so one tick is 360 divided by 4,096, which is 0.088°.
The figure below is one of these encoders on its own, made big. On each of the chip's three strips the dots are the current, pushed toward one edge; the bars under the chip are the voltage that push makes, one per strip. One strip alone could not tell the direction, because it reads the same for the field crossing it from either side; with three facing different ways, only one direction fits all three. The twelve lamps are the twelve answers in order, orange for yes.
The three strips together say the field runs at 45.00°. That falls in step 512, which the arm’s computer reads as 45.00°. The shaft is really at 45.00°.
A few hundred times a second, each encoder hands the arm's computer one whole number. The computer multiplies it by 0.088 to get degrees. That list of numbers is the arm's entire knowledge of its own body.
Six dots and three numbers
In the box the SO-101 stands in its resting pose, with an orange dot on each of its six encoders: one at every joint, on the shaft of the servo that turns it, where the magnet and the chip sit. Three sliders ask three of the arm's joints for angles, the shoulder turn, the shoulder lift and the elbow, and the table under them is what those joints' encoders report: the tick count, and the angle that count means. The dots are placed from the counts, not from the arm. The computer takes the six counts, three you can move and three you cannot, turns each into an angle, and works out where each joint is at those angles. While the counts are right, that is on the joints, and the dots sit still on them. A button hides the dots and shows them again.
The counts are measured from the pose in which the arm stands straight, where every joint reads zero. The chip's own count in that pose is whatever it happens to be, because the magnet was glued on wherever it happened to be, so the arm's software subtracts it from every reading; a count is negative when the joint has turned the other way from there.
Two more controls. A slider marked Noise makes the encoders' counts wander from reading to reading; leave it at none until you are asked. Whenever noise is on, a "Really" column appears in the table with the true angles. Reset puts the sliders back. Under the table, a chart draws the shoulder turn's count over the last six seconds.
This is easier on a larger screen, but it works here too.
What you saw
The count is the angle in a different unit. 512 ticks at 45° and 1,024 at 90°: the count grows in step with the angle, and every tick is worth the same 0.088°. That is the whole conversion, and the "Which means" column is the arm's computer doing it.
The gaps between the steps are invisible. In the figure, the first nudge of a twentieth of a degree left the count where it was, and only the second moved it, by one. Turn a shaft by less than a tick and the count does not change at all: as far as the arm knows, nothing happened. The smallest change a sensor can tell apart is its resolution, and the resolution of this encoder is one tick, 0.088°. Whether that is fine enough depends on what hangs off the joint. At the elbow of this arm, about 27 centimeters from the fingertips, one tick moves them by under half a millimeter.
The encoder reports what is, not what was asked. The elbow slider said 90° and the count said 88.8°, and the count was right. The second module said the servo's circuit nudges the motor until the two agree, and here is the rest. The circuit has one thing to go on, the gap between where the joint is and where it was told to be, and it does the simplest thing with it: it multiplies the gap by a fixed number and pushes that hard. It cannot see gravity. So as the gap shrinks the push shrinks with it, and at no gap there is no push at all, whatever is pulling on the forearm. Gravity pulls the forearm down the whole time, so the elbow drops back until the gap is big enough for the push to hold it, about a degree here, and settles there. The shoulder turn landed on exactly 512 and 1,024 because it spins about a vertical line and gravity has no pull along a turn like that; the elbow and the shoulder lift swing up and down and carry weight. A cleverer circuit can notice that the gap never closes and lean in a little more; that is the third part's business. The slider is a wish; the encoder is a witness. That gap is what the servo's circuit works on every moment, and it can only do that because the encoder does not flatter it.
Where does zero come from? A real servo like these reports a number from 0 to 4,095, never a negative one, and nothing in the number says which pose is "straight". So when an arm is built, someone moves each joint to a known pose, usually the middle of its travel, which on this arm is the straight pose, and the software writes down the count it reads there. From then on it subtracts that count from every reading. That is calibration: putting a sensor's numbers against something already known, so they can be read.
And the wobble. With Noise on, the arm stood still and the counts did not: every reading came back a few ticks from the last, and the dots trembled. A real encoder does this too, for a reason the picture above left out. The voltage across each of the chip's strips is a faint signal, and faint signals are never perfectly steady: warmth makes the current in a strip jostle, and the motor humming a centimeter away is itself magnets and coils, with a field of its own that leaks across the chip and adds to the little magnet's. So the angle the chip works out is a hair different every time, and a hair is sometimes enough to move it into the neighboring step. A real one wanders by a tick or two; the slider turned that up so you could see it. But the arm's computer has no "Really" column. Handed a count of 1,015 it cannot know whether the elbow moved or the reading wobbled, because the number is all it has. What a robot can do about that comes later in this part; here, the point is that even the robot's best sense of itself is a little wrong.
Why six numbers are enough
The arm's computer holds six whole numbers, one per servo, refreshed a few hundred times a second, and multiplies each by 0.088 to get an angle. From six angles and the lengths of the links, which never change, it can work out where every part of the arm is, hand included: that is how the dots found their joints, and it is the working you did in your own head when you read 1,024 ticks and pictured a quarter turn. Everything the arm does starts from that list.
It also means the list is the arm's only witness. If a link bent, or a knock shifted a link on the shaft it is bolted to, the encoder would go on reporting the shaft, the computer would go on trusting it, and the arm would carry on with a confident picture of itself that was wrong, and nothing inside it could notice. That is why real robots are checked against the world now and then: touched against something whose position is known, or looked at by a camera. But every moment in between, a robot's sense of its own body is a short list of whole numbers, read a few hundred times a second, and believed.
Watch
The LeRobot SO101 Arm: Leader Follower Teleoperation Setup Episode 02 — e-Yantra (2:20 of it, starting at 0:00)
- Why this video
- Two real SO-101 arms, the same robot as the box. He holds the white leader arm and moves it by hand: nothing is driving its motors, so all its six encoders can do is report their counts to the computer, and the black follower arm beside it takes those six numbers and goes to the same pose, gripper and all. The whole pose of an arm fits in six whole numbers, and here you watch the numbers carry it across a desk.
- What to watch for
- In the first half minute, before he starts explaining, watch the black follower arm copy every move of the white leader in his hand. At 1:05, "I was actually calculating each and every motor's joint angle values"; at 1:09, the six servo motors in the leader arm, each given a number so its angle can be sent to the computer and on to the follower. At 1:43 the calibration step: each joint moved to its end values, which is the known pose the counts are measured from.
Words introduced
- encoder
- The sensor inside a servo that reports how far its shaft has turned, as a whole number of steps around the circle. There is one per joint, and it is the only way the robot knows where that joint is.
- tick
- One step of an encoder's count, and so the smallest turn it can report. The SO-101's servos cut a full turn into 4,096 ticks, so one tick is 0.088°.
- resolution
- The smallest change a sensor can tell apart. For an encoder it is one tick; a smaller turn leaves the count where it was.
- calibration
- Putting a sensor's numbers against something already known, so they can be read. For an encoder, moving the joint to a known pose and writing down the count there; every later reading is measured from it.
Where next
Suggested next: 16. Touch and force: feeling the world
