Hey friend
I still remember the time I tried to make a small servo-powered robot arm move smoothly. I set the target angle sent the command and the arm jerked violently overshot then started shaking like crazy. It looked terrible.
That frustrating moment taught me one of the important lessons in robotics: good motion comes from good control.. For most humanoid robots from hobby projects to Tesla Optimus and Figure 01 the workhorse controller is still the humble PID controller.
Today I will explain what PID is, why it is so important for joints and how you can actually tune it in practice. No scary theory, real usable knowledge with code you can try.
What Is PID Control?
PID stands for Proportional plus Integral plus Derivative. It is a incredibly powerful feedback controller that constantly corrects the error between where the joint is and where you want it to be.
Think of it like driving a car:
- Proportional is how far you are from the target. The the error, the harder you steer.
- Integral remembers past errors. If you have been drifting left for a while it gently corrects the accumulated mistake.
- Derivative looks at how the error is changing. It. Dampens fast movements to prevent overshooting and shaking.
Together they make the move smoothly accurately and without wild oscillations.
Why PID Is Essential for Humanoid Joints
Every joint in a hips knees, ankles, shoulders, elbows needs precise control.
- Position Control: Make the knee bend to exactly 45 degrees.
- Velocity Control: Move the leg at a smooth constant speed during walking.
- Torque Control: Apply just the right amount of force which is important for compliant safe interaction with humans.
Without a tuned PID controller the robot will either:
- Move too slowly and sluggishly or
- Oscillate wildly and waste energy or
- Feel stiff and unsafe around people.
Tesla Optimus and Figure 01 use more advanced controllers now but at their core they still rely on carefully tuned PID loops or PID-like structures running at high speed on each joint.
A Simple PID Implementation in Python
Here is a realistic PID class:
class PID:
def __init__(self, kp=1.0, ki=0.0, kd=0.0):
self.kp = kp
self.ki = ki
self.kd = kd
self.prev_error = 0.0
self.integral = 0.0
self.dt = 0.01
def compute(self, setpoint, current_value):
error = setpoint - current_value
self.integral += error * self.dt
derivative = (error - self.prev_error) / self.dt
output = (self.kp * error) + \
(self.ki * self.integral) + \
(self.kd * derivative)
self.prev_error = error
return output
Tuning PID in Practice
This is where most beginners get stuck. Here is my practical tuning method:
1. Start with P only set I and D to 0
- Increase Kp until the joint responds quickly.
- If it starts oscillating or shaking reduce Kp a bit.
2. Add D, the Derivative
- This is your damping. Increase Kd to reduce overshoot and shaking.
- Much D makes the joint feel sluggish.
3. Add I, the Integral last
- Use a Ki to remove steady-state error, when the joint stops slightly before the target.
- Much I causes windup and instability.
Real example for a knee joint:
- Target angle: 45°
- starting values: Kp = 8.0, Ki = 0.5, Kd = 1.2
- If the knee overshoots and shakes increase Kd or decrease Kp
- If it stops 2° increase Ki slightly
Position, Velocity and Torque Control
- Position Control is the most common. You give an angle PID tries to reach it.
- Velocity Control is useful during walking phases. You give a desired speed.
- Torque Control or Current Control is what gives humanoids that compliant safe feeling when interacting with people. Many advanced robots run a torque loop with PID and an outer position or velocity loop.
My Personal Take
PID control looks simple on paper. Tuning it well is half science, half art. I have spent hours tweaking values while watching a small robot leg shake itself apart and then suddenly smooth out when the numbers finally click.
Modern humanoids like Optimus combine PID with advanced techniques Model Predictive Control, reinforcement learning, etc. but a solid PID foundation is still, underneath everything.
Once you learn to tune PID you will start to appreciate why compliant joints, good mechanical design and sensor feedback matter so much. They all make the PID controllers job easier and the movement more natural.