30% off your first 3 months

Get the deal

How a quadruped robot keeps its balance

by DuckyHelperNov 12, 20265 min read
Robotics

TL;DR:

  • A legged robot is statically stable when the ground point under its center of mass lies inside the support polygon formed by the feet on the ground.

  • Lifting a foot shrinks the polygon, so the robot must shift its body first, or keep moving to stay up dynamically.

  • An IMU measures tilt and rotation, and the controller uses it to adjust the body and to place the next foot.

A four-legged robot stands very still when all four feet are on the ground. Lift one and the robot has to do something clever, because the ground under the remaining three feet makes a smaller shape. Staying upright while walking is mostly a matter of keeping weight inside that shape or moving fast enough that you do not need to.

The support polygon

Draw a line connecting the feet that are touching the ground. The shape you get is the support polygon: for four feet it is a quadrilateral, for three feet a triangle, for two feet just a line. Now find the robot's center of mass (COM), the point where all its mass can be thought to act, and project it straight down to the ground.

If that point lies inside the polygon, gravity cannot tip the robot over. It is statically stable. If it falls outside, gravity creates a torque that rotates the robot over the edge of the polygon, and it falls unless something changes quickly. The shortest distance from the projected COM to an edge of the polygon is the stability margin: a bigger margin means a more forgiving robot.

Worked example: lifting one foot

Put the origin at the center of the body, with x forward and y to the left, in meters. The feet are at: front-left (0.20, 0.10), front-right (0.20, −0.10), rear-left (−0.20, 0.10), rear-right (−0.20, −0.10). The COM projects to (0, 0).

Standing on four feet. The polygon is a 0.40 m by 0.20 m rectangle, and the COM is in its center. The nearest edges are the left and right sides at 0.10 m, so the margin is 0.10 m.

Lifting the front-left foot. The support triangle has vertices A = FR (0.20, −0.10), B = RL (−0.20, 0.10) and C = RR (−0.20, −0.10). The edge from A to B runs through the origin, because the line from A to B is y = −0.5x, which gives y = 0 at x = 0. So with the COM at (0, 0), it sits exactly on the edge: zero margin. The slightest push tips the robot toward the lifted leg.

To fix that, lean the body away from the raised foot. That means moving toward −y, to the right, so set the COM to (0, −0.05).

  1. The inside of the triangle is below the line y = −0.5x (check with C: at x = −0.20 the line is at y = 0.10, and C has y = −0.10, which is below).

  2. For the COM at (0, −0.05): the line is at y = 0 and −0.05 is below it, so the COM is inside.

  3. Margin: the distance from a point to the line 0.5x + y = 0 is |0.5x + y| / √(0.5² + 1²). That gives |0 − 0.05| / 1.118 = 0.0447 m, about 4.5 cm.

So the robot has to shift its weight 5 cm to the right, away from the lifted leg, before it lifts the foot. That is why a slow, statically stable walk looks like swaying.

What the IMU does

An IMU (inertial measurement unit) combines gyroscopes, which measure how fast the body is rotating, and accelerometers, which measure acceleration including the pull of gravity. From them, the controller estimates the roll and pitch of the body. A feedback loop then adjusts the legs: if the body tilts forward, push the front legs down or move the feet to catch the fall. Gyroscope readings are smooth but drift, accelerometer readings are noisy but do not drift, so the controller blends them (see sensor noise and how to smooth it for the filtering idea).

Foot placement

When a robot moves fast it cannot keep the COM over the polygon at every instant, so it keeps balance dynamically by putting each foot in the right place as it falls forward. A well-known rule of thumb, from early hopping robots, places the foot near the neutral point: the position where the body's forward motion would balance. A simple version puts the foot ahead of the hip by about v × T_stance / 2, where v is the forward speed and T_stance is the time the foot will stay on the ground. For v = 0.8 m/s and T_stance = 0.25 s, that gives 0.8 × 0.25 / 2 = 0.10 m, so the foot lands 10 cm ahead of the hip. A correction is then added if the robot is going faster or slower than wanted.

A trotting robot, with two diagonal feet down at a time, has a polygon that shrinks to a line. The COM projection cannot stay on a line, so a trot is only stable dynamically, by moving, with the feet changing every fraction of a second. This is covered in walking gaits.

Where it goes wrong

  • Wrong COM estimate. A battery moved a few centimeters shifts the COM and shrinks the margin. Measure the COM by balancing the robot on a pivot, or from the sums of the parts' masses times positions.

  • Slipping feet. A foot that slips changes the polygon without warning. Use rubber feet and avoid slippery floors.

  • Slopes. On a slope the projected COM moves toward the downhill edge. Lean uphill.

  • Delay. A slow control loop cannot catch a fall that develops in a few hundredths of a second.

  • Pushing and payloads. An outside push moves the COM or adds torque. A load carried high is especially dangerous.

Safety: A legged robot that falls can crush fingers and hit people with its legs, and servos can pinch. Test on a stand or with a safety line at first, keep hands clear of the legs during start-up, use a soft surface under early tests, and have a power switch to cut all motors. Charge and handle the battery with care.

Try it yourself

Take a table with four equal legs, or a four-legged toy. Mark the feet on paper and draw the polygon with three feet down. Find the balancing point of the toy on a pencil, mark the COM under it, and slide a weight to move it. See how far it can shift before the toy tips. Measure the distance and compare with your drawn margin.

Frequently asked questions

What is the difference between static and dynamic stability?

A statically stable robot stays up if it freezes, because its COM is over the support polygon. A dynamically stable robot would fall if it stopped, and stays up only by moving and placing its feet at the right time.

Why does a robot sway before lifting a leg?

It must move its COM inside the smaller polygon that will remain after the foot leaves the ground, so it shifts its weight first.

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.