⚙️ Learnsy lesson 1 · standalone TypeScript app

PID Controllers

Build intuition for proportional, integral, and derivative feedback by tuning a motor that holds a robot arm at a target angle.

📘 Foundation

A PID controller compares a desired setpoint with the measured process variable. Their difference is the error. Feedback repeatedly measures that error and adjusts the actuator.

  • Proportional (P) reacts to present error. More P usually means faster response, but too much can oscillate.
  • Integral (I) accumulates past error. It removes persistent offset, but can overshoot when it winds up.
  • Derivative (D) reacts to the error slope. It adds damping, but it is sensitive to noisy measurements.

🎛️ Signal vs. control effort

In this lesson the output signal is joint angle. The control effort is signed motor torque: positive torque accelerates the arm one way, negative torque the other.

Holding a non-vertical arm still needs steady torque to fight the hanging weight — not “more power,” but the right signed push. The arm’s inertia lets angle overshoot, which is why the D term helps here.

❓ FAQ

Why does P-only control have offset?

With Ki = 0, motor torque only comes from present error: u = Kp(setpoint − angle). Near horizontal, the hanging weight creates gravity torque, so a P-only controller must keep some angle error to produce the balancing motor torque.

How does the hanging weight create load torque?

The arm angle runs from −π/2 straight down to π/2 straight up; 0 is horizontal. Gravity torque is modeled as weight·cos(θ), so it is strongest near horizontal and zero when the arm points straight down or straight up.

What happens at 6 seconds?

The hanging weight increases. That raises the gravity torque for the same arm angle, so the controller must produce more motor torque. P-only does that by accepting more position error; integral action can build the extra torque without permanent offset.

What does Kp change?

Higher Kp commands more torque per radian of error, so it reduces offset and reacts faster. Too little Kp droops under the weight; too much Kp can overshoot, ring, or hit the torque clamp.

What do Ki and Kd change?

Ki accumulates error and can remove persistent offset by building steady torque over time. Too much Ki can overshoot. Kd reacts to motion and adds damping, which helps tame ringing from high Kp or inertia.

What does inertia change?

Inertia controls how hard the arm is to accelerate. Higher inertia makes the response slower and more prone to overshoot after torque changes; lower inertia makes the arm respond quickly.

Where is PID used?

PID is common when a machine must regulate a measurable quantity despite changing loads or disturbances: robot velocity, oven temperature, drone attitude, motor position, fluid level, and cruise control.

🎚️ Interactive simulator

The arm starts straight down at −π/2 while the target is horizontal at 0. As it rises, the hanging weight creates more gravity torque. At 6 seconds, the weight increases. Tune the PID gains to control the response.

How to read it: Motor chart is radians: −π/2 down, 0 horizontal, π/2 up. Control chart shows error, motor torque, and gravity torque from the hanging weight.