ROS101

Tuning a PID Controller for a Quadruped Robot

Andy ChenAndy Chen·Verified · v1

The Short Answer

Start with P only, increase it until the joint oscillates around the setpoint, then back off to ~60% of that value. Add D to damp the oscillation. Only add I if there's a persistent steady-state error (usually from gravity load on a leg joint) — and keep it small, since too much I is the single most common cause of quadruped leg "wobble" on hardware.

Why This Matters

A quadruped leg joint carries a changing gravity load as the leg swings through stance and swing phase. A PID controller tuned only in simulation, without load variation, will almost always ring or lag on real hardware. Tuning order matters more than the exact numbers, because each term compensates for a different failure mode:

  • P alone gets you close but leaves steady-state error and can oscillate if too high.
  • D damps oscillation but amplifies encoder noise if too high — you'll hear it as a high-pitched motor whine.
  • I removes steady-state error but is the term most likely to cause slow, low-frequency wobble if overtuned.

Step-by-Step

1. Zero everything and check direction

Set Ki = Kd = 0, set Kp to a small value (start at 1.0 for a typical hobby servo/BLDC + encoder setup), and confirm the joint moves toward the setpoint, not away from it. Getting the sign wrong here is the most common first-attempt bug.

2. Increase Kp until it oscillates

Double Kp every test until you see a sustained oscillation around the setpoint with the leg unloaded (off the ground, foot free). Record this value as Ku (ultimate gain).

3. Back off to a stable working point

Set Kp = 0.5 * Ku as a starting point (this is a simplified variant of the Ziegler-Nichols method, tuned conservatively for hardware safety).

4. Add derivative damping

Increase Kd from zero until the oscillation from step 2 disappears and the joint settles within 2-3 cycles of a step input. If you hear a whine at the motor, your encoder resolution is too coarse for that Kd — either filter the derivative term or lower it.

5. Add integral only if needed

With the leg loaded (foot on the ground, standing), check for steady-state droop. If present, add a small Ki (start at Kp / 50) and increase until the droop disappears. Watch for slow oscillation over multiple seconds — that's integral windup, back off immediately.

Common Errors & Fixes

Error Cause Fix Verified on
Fast, high-pitched oscillation Kd too high, amplifying encoder noise Add a low-pass filter on the derivative term, or lower Kd Jetson Orin Nano, ROS2 Jazzy, July 2026
Slow wobble over 2-5 seconds Integral windup (Ki too high or no clamp) Clamp integral term, lower Ki Jetson Orin Nano, ROS2 Jazzy, July 2026
Leg lags behind setpoint under load Kp too low for the actual gravity load Retune Kp with the leg loaded, not free-swinging STM32F4 + AS5048A encoder, June 2026
Joint moves away from setpoint Sign error in error calculation Flip the sign of the error term, not Kp Any platform

Summary

  • Tune in order: P, then D, then I — never all three at once.
  • Always tune with the leg loaded the way it will actually be loaded in operation.
  • A small, correctly-signed Ki is safer than a large one "to be sure" — integral windup is the most common cause of quadruped leg wobble reported in the wild.