Part 3 · How robots are controlled

25Trajectories: getting from A to B smoothly

Every star you dragged so far was you planning for the robot. Left to plan for itself, a robot's plainest plan, straight lines at one speed, asks its motors for the impossible at every corner. Two arms run the same three points, one jerky and one smooth.

This assumes: Proportional control: push harder the further you are, Getting the hand there: inverse kinematics. About 9 minutes of reading.

Reach across the table for a cup of coffee. Your hand does not leap to full speed and stop dead on the cup. It starts gently, is fastest somewhere in the middle, and slows into the last few centimeters so that it arrives still. Now try it the other way: full speed from the first instant, and a dead stop at the cup. You cannot, and if you could, the jolt at each end would slop the coffee over the table. Your arm planned that, and you never noticed. A robot has to be told. This module is about the plan.

Who moves the star?

In the module on inverse kinematics you dragged a star and the robot worked out the angles that put its hand on it, many times a second. In the modules since, a servo has chased a target you moved by pressing a button: the target jumped, the servo pushed toward it, and the arm arrived. Nobody has yet said where the target should be between here and there; dragging the star, you decided that with your hand. When a robot works on its own, something inside it has to move the star; the rest is machinery you have met, the star's new place turned into joint angles every instant and each handed to its servo as the target.

That something is a trajectory: a plan for where the hand should be at every moment on its way. It has two halves: the path through space, and the timing along it, where on that line the hand should be a tenth of a second from now, and two tenths, and so on. Two plans can follow the same path with different timings, and that difference is this module.

A plan is usually written down as a few places the hand must pass through, and a rule for filling in the rest. Each of those places is a waypoint. The box in this module has three: a spot on the table to the left of the arm, a spot on the table to its right, and a spot 20 centimeters above that one. The path runs 24 centimeters sideways and then straight up, with a right-angle corner, and both arms are given two seconds for it.

The plainest plan

The simplest rule for filling in: go from the first waypoint toward the second in a straight line at one steady speed, turn at the second and go toward the third at the same speed, stop at the third. That is 22 centimeters a second the whole way.

Look at three moments. At the start, the target is still, and then in the next instant it is moving at 22 centimeters a second. At the corner, it is moving to the right, and in the next instant it is moving straight up. At the end, it is moving at full speed, and in the next instant it is still. Every one of those is a change of motion, and any change of motion takes a push. The module on gravity showed the speeding-up and slowing-down half of that: a moving thing carries momentum, and changing it takes a force applied for a time. The turning half you feel in a car going round a corner at a steady speed: nobody slowed you down, but something had to shove you sideways to bend your path, and it was the door. The bigger the change and the shorter the time it happens in, the bigger the push. How quickly motion is changing is the acceleration, and a change in no time at all is an infinite acceleration, which no motor can give. The module on motors put a number on this arm's: 2.94 newton meters at each joint.

So the plainest plan asks the motors for the impossible three times. What happens instead is the saturation you met in the proportional control module. The star leaps away, a gap opens, the rule asks for a push far bigger than the motor has, and the motor gives everything. The hand is left behind for a few hundredths of a second, then catches up, moving faster than the plan for a moment. That catch-up is a jolt: an acceleration as big as the motors can manage. Accelerations are measured against falling: a dropped thing gains speed at one fixed rate, called 1 g. A hard stop in a car is about 1 g, an elevator setting off about a tenth. This light arm's catch-up is nearly 2 g. Then, at the corner, all of it again.

The other plan

The smooth plan uses the same three waypoints and the same two seconds and changes only the rule for filling in. Its timing starts from nothing and builds, is fastest in the middle of a leg, and dies away to nothing at the end, the way your hand does reaching for the cup. Its path does not turn the corner in an instant: it runs one curve through all three dots, bending early so it passes the middle one already heading upward. Nowhere in it does the motion change suddenly, so nowhere does it ask for more than the motors have.

It pays in two ways. Starting and stopping gently costs time, so it goes faster in the middle to arrive in the same two seconds, nearly 40 centimeters a second against the jerky plan's steady 22. And it rounds the corner, so between the waypoints the hand is not quite where straight lines would put it, which matters when something is in the way.

The box

Two copies of the arm run the same route, the jerky plan on the left and the smooth one on the right, both on one clock. The three waypoints are gold dots. The star is the target, riding the plan, and the blue dot on the arm is the fingertips trying to stay on it; a line is left where they have been. Four joints do the work: the base turn, the shoulder lift, the elbow and the wrist bend; the wrist twist and the jaws hold still. The route starts by itself a second after the page loads, and Reset runs both sides again together. Under each box the first line says where the plan is. The Hand line says how fast the fingertips are moving and how far behind the star they are, and, once a run has started, the furthest they fell behind and the biggest jolt they felt: their biggest acceleration, in g, over any fiftieth of a second. A catch-up is one; so, on a smaller scale, is a gentle start.

The bars are those four motors, showing the twist the motor is giving right now against all it has, that 2.94 newton meters. A bar turns red while its motor is at the limit, and because a jolt is over in a few hundredths of a second, each bar also keeps a mark at the most its motor gave during the run, red if the most was everything. Run puts one arm back at the first waypoint and runs its route again; Twice as fast runs it in one second. Slow in the toolbar runs both sides at a quarter speed, which is the way to watch a corner.

Jerky plan

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

Smooth plan

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.

Press Run on the smooth side with Slow still on and the picture is the other way: the hand within a couple of millimeters the whole way, and no bar red. Press Slow again for full speed.

What the bars are saying

Between the corners, the jerky arm's bars barely move, because a hand moving in a straight line at a steady speed needs almost no push: a little to hold the arm up against gravity. Everything the motors have is spent in three instants, the start, the corner and the stop, and in each of them it is not enough. That is what the red marks record. The arm still stays within 7 millimeters, because it is light and its motors are quick, so at full speed the trace looks fine; the bars and the jolt are where the cost shows.

The smooth arm spends the same motors evenly. Its biggest pushes come while it gathers speed and while it sheds it, where its motion changes most, and even those are under half of what the motors have. Nothing is ever left behind, so there is never a catch-up. The biggest acceleration its fingertips go through is the plan's own gentle build-up, about a fifth of a g, an elevator's worth.

The traces show the price: the jerky arm's two straight lines with a sharp corner, and the smooth arm's one curve through the same three dots, dipping about two and a half centimeters below the first line on its way to the middle dot and swinging a little wide of the corner.

There is a third plan the box does not run, and real robots use it constantly: keep the straight lines, but start and stop gently on every leg, so the hand comes to rest at each waypoint before setting off again. No jolts and no bends; the price is a stop at every corner. A robot moving a part around an obstacle takes the stops; one polishing a curved surface takes the bends.

Halving the time doubles every speed along the way, and doubling the speeds means every change of motion is twice as big in half the time, which is four times the push. The smooth plan's biggest push, under half the limit before, is now about all of it. The jerky plan was already asking for the impossible, so for it nothing has changed except that the star gets further ahead before the motors can catch it up: 23 millimeters instead of 7. Not far above this speed even the smooth plan would ask for more than this arm has. The jerky plan passed that point before it started.

Why a robot cares

A jolt is not only a number. Anything held by the gripper's friction alone slides when the jolt is big enough; anything liquid slops; a heavy part swings the arm past where the plan wanted it. And a real arm is not the rigid thing in this box: every link flexes a little, and a jolt sets the whole arm ringing like a struck ruler, so the hand arrives and then wobbles before it is truly still. Sudden pushes also wear the gears. That is why the people who write industrial arms' software spend real effort on the rule for filling in.

A heavy arm carrying ten kilograms would not have kept within 7 millimeters as this light one did, and a robot welding along a seam cannot afford to be left behind at a corner. So a plan is written never to ask more than the motors have, with a margin: a plan that respects the motors is one the hand can follow.

What the simulation leaves out

The links in this box are perfectly stiff, so a jolt here costs a few millimeters of lag and no ringing; a real arm would shake. The servos here chase their angles exactly as the proportional control module described; many real servos quietly smooth a sudden command themselves, which softens the worst of a jerky plan without anyone asking.

Watch

9. Robotic Arms - Trajectories (IROS 2020 Tutorial Series) — HEBI Robotics (5:50 of it, starting at 2:01)

Why this video
This is the box's contrast on a real six-joint arm, with the presenter's hands on it. He first sends one wrist joint bare position commands, the jerky plan, and a live graph shows the arm's feedback struggling to keep up with each step; then he teaches the same arm two waypoints, runs them through a trajectory generator, and the motion is calm and the graph stays on track. Finally the whole arm runs through three positions on smooth trajectories, sliding into and out of every waypoint. Nothing about the motors or their tuning changes between the two, only the plan.
What to watch for
At 3:23 he sets abrupt position commands on the wrist and the graph's dotted command line jumps while the solid feedback line chases it: the star leaping away from the hand. At 4:35 he sets two waypoints by hand and at 4:45 runs them; watch how the motion is "a lot more in control" and, on the graph, how the feedback now sits on the command. At 5:30 he says the jerky version can damage the hardware or its surroundings. At 6:25 he sets three positions for the whole arm and, at 7:12, explains that it is "sliding into each position, sliding out of each waypoint": the smooth plan's easing in and out, on all six joints at once.

Words introduced

trajectory
A plan for where something should be at every moment on its way from one place to another. The path through space and the timing along it, together; two trajectories can follow the same path at different timings.
waypoint
A place a trajectory must pass through on its way. The plan decides how the hand gets from each one to the next.
acceleration
How quickly a thing's motion is changing, in speed or in direction. Any change of motion takes a push, and the bigger the change and the shorter the time it happens in, the bigger the push. An instant change would need an infinite one.

Where next

Suggested next: 26. Balancing something that wants to fall — The cart-pole is back, and the four pushes that keep its pole up are yours to switch off. Each one missing brings the pole down its own way: straight over, whipped over, walked off the rail, or swayed into a bumper.